One minute starting guide

Assuming you have only little time, here's the quickest introduction to AssertJ Swing. Depending on your reading and coding skills, this should be done in about one minute. ☺

AssertJ Swing artifacts are in Maven central repository. There are two main artifacts: assertj-swing-testng and assertj-swing-junit.

It should be obvious that JUnit users should depend on assertj-swing-junit while TestNG users should depend on assertj-swing-testng ;-)

TestNG

<dependency>
  <groupId>org.assertj</groupId>
  <artifactId>assertj-swing-testng</artifactId>
  <version>3.9.2</version>
  <scope>test</scope>
</dependency>

JUnit

<dependency>
  <groupId>org.assertj</groupId>
  <artifactId>assertj-swing-junit</artifactId>
  <version>3.9.2</version>
  <scope>test</scope>
</dependency>

If you use another dependency tool, please check this page to find the relevant AssertJ Swing dependency declaration for your tool.

JIDE support (optional)

For adding the JIDE dependent features you have to add assertj-swing-jide additionally to the libraries for your test framework. Note that this step is only required for users of JIDE, else it is optional!

<dependency>
  <groupId>org.assertj</groupId>
  <artifactId>assertj-swing-jide</artifactId>
  <version>3.9.0</version>
  <scope>test</scope>
</dependency>

Make some static imports

import static org.assertj.swing.launcher.ApplicationLauncher.application;
import static org.assertj.swing.finder.WindowFinder.findFrame;

extend our base test case,

// either for JUnit
AssertJSwingJUnitTestCase
// or for TestNG
AssertJSwingTestngTestCase

and add the following to the onSetUp() method to start your application via its main method.

// without arguments
application(YourMainClass.class).start();
// with arguments
application(YourMainClass.class).withArgs(arguments).start();

Then you just need to tell AssertJ Swing to find the main frame of your application and start testing:

FrameFixture frame = findFrame(new GenericTypeMatcher<Frame>(Frame.class) {
  protected boolean isMatching(Frame frame) {
    return "Your application title".equals(frame.getTitle()) && frame.isShowing();
  }
}).using(robot());

Now frame refers to the test fixture for your main frame and you're ready to test it.

Type frame. and your IDE will show you the available commands. Assuming your frame contains a table that should have 42 rows you could for instance write:

frame.table().requireRowCount(42);

That's all!

See our more detailed getting started guide to get the maximum out of it!

You can learn more by looking at AssertJ Swing javadoc.

Another way is to go see assertj-examples, it covers what is possible with AssertJ and contains projects for AssertJ Swing, too. You can clone it and run its tests!