我有一個簡單的單元測試來確保應用程序的主窗口是未修飾的: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
提交
取消