4

I'm trying to run a simple test with FEST and it fails. Here is my Swing app:

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):

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?

Ed Limonov
  • 105
  • 1
  • 6

1 Answers1

2

Just add this to your app constructor:

this.setVisible(true);
Bernie Noel
  • 304
  • 2
  • 10