使用 Cucumber 的 AssertJ Swing 测试

Use AssertJ Swing test from Cucumber

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

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,但 window 变量仍然为空。

JUnit (@org.junit.Before) 的 @Before 注释不适用于 Cucumber。
黄瓜有它的 own @Before annotation (@cucumber.api.java.Before) :

事实上,JUnit 和 Cucumber 实际上是两个不同的测试运行器平台,因此拥有自己的测试运行器和相关设施(而有些在逻辑方面是通用的)。

作为变通方法,尝试在测试摘要 class 的设置方法上添加 2 个不同的 @Before 注释(junit 的和 cucumber 的)或创建两个不同的方法:一个带有 @cucumber.api.java.Before 和另一个 @org.junit.Before 都委托给执行设置处理的通用方法。