使用 Cucumber 的 AssertJ Swing 测试

我有一个简单的单元测试来确保应用程序的主窗口是未修饰的:


public class MainWindowUT extends AbstractMainWindowTest {


    @Test

    public void whenApplicationIsStarted_thenMainFrameIsUndecorated() {

        @SuppressWarnings("boxing")

        Boolean isUndecorated = GuiActionRunner.execute(() -> window.target().isUndecorated());

        assertThat(isUndecorated).isTrue();

    }

}

AbstractMainWindowTest 是:


public abstract class AbstractMainWindowTest extends AssertJSwingJUnitTestCase {


    protected FrameFixture window;


    @Override

    protected void onSetUp() {

        ScaleRuler frame = GuiActionRunner.execute(() -> new ScaleRuler());

        window = new FrameFixture(robot(), frame);

        window.show();

    }

}

ScaleRuler 是我的框架,目前什么都不做,只是 setUndecorated(true)。测试运行良好。如何从 Cucumber 执行相同的测试?


public final class WindowAspectSteps {


    @Then("the main window should be undecorated")

    public void checkMainWindowIsUndecorated() {

        //????

    }

}

我试图让 WindowAspectSteps 扩展 AbstractMainWindowTest,但窗口变量仍然为空。


跃然一笑
浏览 114回答 1
1回答

慕桂英546537

@BeforeJUnit ( )的注释@org.junit.Before不适用于 Cucumber。Cucumber 有自己的 @Before 注解( @cucumber.api.java.Before) :事实上,JUnit 和 Cucumber 实际上是两个不同的测试运行器平台,因此拥有自己的测试运行器和相关设施(而有些在逻辑方面是通用的)。作为解决方法,尝试@Before在测试抽象类的设置方法上添加 2 个不同的注释(junit 和 cucumber 的)或创建两个不同的方法:一个与@cucumber.api.java.Before另一个@org.junit.Before都委托给执行设置处理的通用方法。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java