简体   繁体   English

Java/Swing FEST 测试荒谬地失败了

[英]Java/Swing FEST test fails absurdly

I have a test that sometimes fails on the requireSelected() call, and I can't figure out why.我有一个测试有时会在requireSelected()调用上失败,我不知道为什么。

public void testSimple() {
  JRadioButtonFixture fixture = getFixture();
  fixture.check();
  fixture.requireSelected().requireVisible();
}

I tried changing the code to run on the EDT instead of in the test's main, but none of the fixture's methods are allowed to be invoked from the EDT it seems.我尝试将代码更改为在 EDT 上而不是在测试的 main 上运行,但似乎不允许从 EDT 调用任何夹具的方法。

Why does this test fail?为什么这个测试会失败?

Update: More details:更新:更多细节:

There isn't anything in the setUp() . setUp()中没有任何内容。

Here's the failure trace:这是故障跟踪:

Java.lang.AssertionError: [javax.swing.JRadioButton[name='button', text='text', selected=false, enabled=true, visible=true, showing=true] - property:'selected'] expected:<true> but was:<false>
at org.fest.assertions.Fail.fail(Fail.java:87)
at org.fest.assertions.Fail.failIfNotEqual(Fail.java:60)
at org.fest.assertions.BooleanAssert.isEqualTo(BooleanAssert.java:129)
at org.fest.swing.driver.AbstractButtonDriver.assertThatButtonIsSelected(AbstractButtonDriver.java:142)
at org.fest.swing.driver.AbstractButtonDriver.requireSelected(AbstractButtonDriver.java:127)
at org.fest.swing.fixture.JRadioButtonFixture.requireSelected(JRadioButtonFixture.java:288)

I was recently testing with Abbot, FEST precursor, and some failures occurred the same way of yours.我最近正在使用 Abbot,FEST 前身进行测试,并且一些失败的发生方式与您的相同。 In my case, adding a Thread.sleep(300) between the simulation radio.check() and the verifier radio.requireSelected() solved the issue.就我而言,在模拟radio.check()和验证程序radio.requireSelected()解决了这个问题。

Give it a try.试试看。

You need to specify how the test fails and maybe show the setUp() method.您需要指定测试如何失败并可能显示 setUp() 方法。 It could be basically anything with the information you've given.基本上可以是您提供的任何信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM