~~NOTRANS~~
~~Title: 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();
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:
@BeforeClass
public static void beforeClassBaseApplicationTest() throws Exception
{
System.setProperty(IPackageSetup.CONFIG_BASEDIR, new File("").getAbsolutePath());
}