FEST:无法使用 matcher org.fest.swing.core.NameMatcher 查找组件



我正在尝试使用 FEST 运行一个简单的测试,但它失败了。这是我的 Swing 应用程序:

public final class App extends JFrame {
  public App() {
    super();
    JButton button = new JButton("start!");
    button.setName("start");
    this.getContentPane().add(button);
  }
}

这是测试(我使用的是JUnit 4):

public final class AppTest {
  @Test
  public void test() {
    FrameFixture frame = new FrameFixture(new App());
    frame.button("start").click();
    frame.cleanUp();
  }
}

这就是它失败的方式:

org.fest.swing.exception.ComponentLookupException: Unable to find 
component using matcher org.fest.swing.core.NameMatcher[name='start',
type=javax.swing.JButton, requireShowing=true].
Component hierarchy:
com.sigzig.App[name='frame0', title='', enabled=true, visible=false, showing=false]
  javax.swing.JRootPane[]
    javax.swing.JPanel[name='null.glassPane']
    javax.swing.JLayeredPane[]
      javax.swing.JPanel[name='null.contentPane']
        javax.swing.JButton[name='start', text='start!', enabled=true, visible=true, showing=false]
  at org.fest.swing.core.BasicComponentFinder.componentNotFound(BasicComponentFinder.java:271)
  at org.fest.swing.core.BasicComponentFinder.find(BasicComponentFinder.java:260)
  at org.fest.swing.core.BasicComponentFinder.find(BasicComponentFinder.java:254)
  at org.fest.swing.core.BasicComponentFinder.findByName(BasicComponentFinder.java:191)
  at org.fest.swing.fixture.ContainerFixture.findByName(ContainerFixture.java:527)
  at org.fest.swing.fixture.ContainerFixture.button(ContainerFixture.java:124)
    ...

这是我正在使用的依赖项:

<dependency>
    <groupId>org.easytesting</groupId>
    <artifactId>fest-swing</artifactId>
    <version>1.2.1</version>
    <scope>test</scope>
</dependency>

怎么了?

只需将其添加到您的应用程序构造函数中:

this.setVisible(true);

最新更新