[英]FEST: Unable to find component using matcher org.fest.swing.core.NameMatcher
I'm trying to run a simple test with FEST and it fails. 我正在尝试用FEST运行一个简单的测试但它失败了。 Here is my Swing app: 这是我的Swing应用程序:
public final class App extends JFrame {
public App() {
super();
JButton button = new JButton("start!");
button.setName("start");
this.getContentPane().add(button);
}
}
This is the test (I'm using JUnit 4): 这是测试(我使用的是JUnit 4):
public final class AppTest {
@Test
public void test() {
FrameFixture frame = new FrameFixture(new App());
frame.button("start").click();
frame.cleanUp();
}
}
This is how it fails: 这是它失败的方式:
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)
...
This is the dependency I'm using: 这是我正在使用的依赖:
<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-swing</artifactId>
<version>1.2.1</version>
<scope>test</scope>
</dependency>
What's wrong? 怎么了?
只需将其添加到您的应用构造函数:
this.setVisible(true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.