为了账号安全,请及时绑定邮箱和手机立即绑定

使用 Cucumber 的 AssertJ Swing 测试

使用 Cucumber 的 AssertJ Swing 测试

跃然一笑 2022-12-28 11:02:28
我有一个简单的单元测试来确保应用程序的主窗口是未修饰的: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个赞

@BeforeJUnit ( )的注释@org.junit.Before不适用于 Cucumber。
Cucumber 有自己的 @Before 注解@cucumber.api.java.Before) :

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

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


查看完整回答
反对 回复 2022-12-28
  • 1 回答
  • 0 关注
  • 113 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号