Use SwingApplication With JUnit Tests

If you want to start a JVx application during a JUnit Test, it's important that you don't call System.exit during the test - otherwise, your unit test will stop.

This example shows how you start an application:

public SwingApplication startApplication()
    SwingApplication app = new SwingApplication();
                "/apps/firstapp/application.xml", null); 
    long lTime = System.currentTimeMillis();
    while ((app.getApplication() == null 
            || !app.getApplication().getLauncher().isVisible())
           && lTime + 60000 > System.currentTimeMillis())
        catch (InterruptedException ie)
            throw new RuntimeException(ie);
    IApplication jvxapp = (IApplication)app.getApplication();
    if (jvxapp == null)
    {"Application was not started!");
    return app;

If you have problems with config.xml, use following to set the configuration base directory:

public static void beforeClassBaseApplicationTest() throws Exception
    System.setProperty(IPackageSetup.CONFIG_BASEDIR, new File("").getAbsolutePath());
This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information