gpt4 book ai didi

java - 使用 Cucumber 中的 AssertJ Swing 测试

转载 作者:行者123 更新时间:2023-11-30 05:36:52 25 4
gpt4 key购买 nike

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

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 的 @Before 注释 (@org.junit.Before) 不适用于 Cucumber。
cucumber 有其own @Before annotation (@cucumber.api.java.Before):

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

作为一种解决方法,尝试在测试抽象类的设置方法上添加 2 个不同的 @Before 注释(junit 和 cucumber),或者创建两个不同的方法:一个使用 @cucumber .api.java.Before 和另一个 @org.junit.Before 都委托(delegate)给执行设置处理的通用方法。

关于java - 使用 Cucumber 中的 AssertJ Swing 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56415393/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com