AssertJ Swing supports launching an application from its main() method. It is quite easy, and requires only one line of code. You only need to use the ApplicationLauncher.

Let's assume we have the following application

public class JavaApp {

  public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        JFrame frame = new JFrame("Java Application");
        frame.setPreferredSize(new Dimension(200, 200));

We can launch this application programmatically either by the main class or its fully qualified name:

//import static org.assertj.swing.launcher.ApplicationLauncher.*;

// 1. by class object without arguments
// 2. by class object with arguments
application(JavaApp.class).withArgs("arg1", "arg2").start();
// 3. by qualified name without arguments
// 4. by qualified name with arguments
application("com.mycompany.JavaApp").withArgs("arg1", "arg2").start();

Once the application is started, we can get a reference of its JFrame. In this example we're using a WindowFinder. For more information about WindowFinder, please visit Testing Long-Duration Tasks.

// import static org.assertj.swing.finder.WindowFinder.findFrame;

FrameFixture frame = findFrame(new GenericTypeMatcher<Frame>() {
  protected boolean isMatching(Frame frame) {
    return "Java Application".equals(frame.getTitle()) && frame.isShowing();

AssertJ Swing provides its own applet viewer to support GUI testing of Java applets. Testing an applet involves three steps: start the applet, the actual test and resource cleanup.

Start the applet

There are two ways to start an applet:

Using an AppletLauncher to start an AppletViewer

The class AppletLauncher provides a fluent interface for launching an applet:

AppletViewer viewer = AppletLauncher.applet("org.assertj.swing.applet.MyApplet").start();
// or
AppletViewer viewer = AppletLauncher.applet(MyApplet.class).start();
// or
AppletViewer viewer = AppletLauncher.applet(new MyApplet()).start();

In addition, we can pass parameters to the applet. This works as if you'd specify them in the param tag of the embedding HTML:

AppletViewer viewer = AppletLauncher.applet(new MyApplet())

// or

Map<String, String> parameters = new HashMap<String, String>();
parameters.put("bgcolor", "blue");
parameters.put("color", "red");
parameters.put("pause", "200");

AppletViewer viewer = AppletLauncher.applet(new MyApplet()).withParameters(parameters).start();
Starting an AppletViewer directly

The AppletLauncher provides a simple and compact API to start applets in an AppletViewer. The created AppletViewer uses basic implementations of AppletStub and AppletContext though. If you need to test an applet with more advanced implementations of AppletStub or AppletContext, you can use AppletViewer directly, passing your own AppletStub (which will return your own AppletContext).

AppletViewer viewer = AppletViewer.newViewer(new MyApplet(), new MyAppletStub());

Test the applet

Once we have an AppletViewer up and running the applet to test, we simply can wrap the AppletViewer with a FrameFixture and start testing.

private AppletViewer viewer;
private FrameFixture applet;

@BeforeMethod public void setUp() {
  viewer = // get the viewer using AppletLauncher or create a new AppletViewer
  applet = new FrameFixture(viewer);;

@Test public void shouldChangeLabelOnButtonClick() {

@AfterMethod public void tearDown() {

Resource cleanup

As our previous example showed, in addition to call cleanUp() we need to unload the applet by calling unloadApplet in the AppletViewer used in our test.