我有一个简单的单元测试来确保应用程序的主窗口是未修饰的: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,但窗口变量仍然为空。
1 回答

慕桂英546537
TA贡献1848条经验 获得超10个赞
@Before
JUnit ( )的注释@org.junit.Before
不适用于 Cucumber。
Cucumber 有自己的 @Before 注解( @cucumber.api.java.Before
) :
事实上,JUnit 和 Cucumber 实际上是两个不同的测试运行器平台,因此拥有自己的测试运行器和相关设施(而有些在逻辑方面是通用的)。
作为解决方法,尝试@Before
在测试抽象类的设置方法上添加 2 个不同的注释(junit 和 cucumber 的)或创建两个不同的方法:一个与@cucumber.api.java.Before
另一个@org.junit.Before
都委托给执行设置处理的通用方法。
添加回答
举报
0/150
提交
取消