This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information

--Use SwingApplication with JUnit tests

Documents for the development of and with JVx.

--Use SwingApplication with JUnit tests

Postby Development@SIB » Tue Apr 08, 2014 6:06 pm



This article is outdated - please use our new system at

https://doc.sibvisions.com




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:
Syntax: [ Download ] [ Hide ]
public SwingApplication startApplication()
{
    SwingApplication app = new SwingApplication();
    app.setSystemExitOnDispose(false);
    app.startup(FirstApplication.class.getName(),
                "/apps/firstapp/application.xml", null);
   
    long lTime = System.currentTimeMillis();

    while ((app.getApplication() == null
            || !app.getApplication().getLauncher().isVisible())
           && lTime + 60000 > System.currentTimeMillis())
    {
        try
        {
            Thread.sleep(100);
        }
        catch (InterruptedException ie)
        {
            throw new RuntimeException(ie);
        }
    }
   
    IApplication jvxapp = (IApplication)app.getApplication();

    if (jvxapp == null)
    {
        Assert.fail("Application was not started!");
    }
   
    return app;
}

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

Syntax: [ Download ] [ Hide ]
@BeforeClass
public static void beforeClassBaseApplicationTest() throws Exception
{
    System.setProperty(IPackageSetup.CONFIG_BASEDIR, new File("").getAbsolutePath());
}
User avatar
Development@SIB
 
Posts: 325
Joined: Mon Sep 28, 2009 1:54 pm

Return to Documentation