首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FEST:无法使用matcher org.fest.swing.core.NameMatcher找到组件

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

Stack Overflow用户
提问于 2014-12-27 11:19:31
回答 1查看 1.3K关注 0票数 4

我试图用喜庆运行一个简单的测试,结果失败了。这是我的Swing应用程序:

代码语言:javascript
复制
public final class App extends JFrame {
  public App() {
    super();
    JButton button = new JButton("start!");
    button.setName("start");
    this.getContentPane().add(button);
  }
}

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

代码语言:javascript
复制
public final class AppTest {
  @Test
  public void test() {
    FrameFixture frame = new FrameFixture(new App());
    frame.button("start").click();
    frame.cleanUp();
  }
}

这就是它失败的原因:

代码语言:javascript
复制
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)
    ...

这是我使用的依赖项:

代码语言:javascript
复制
<dependency>
    <groupId>org.easytesting</groupId>
    <artifactId>fest-swing</artifactId>
    <version>1.2.1</version>
    <scope>test</scope>
</dependency>

怎么了?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-27 11:31:53

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

代码语言:javascript
复制
this.setVisible(true);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27666732

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档