Page 1 of 1

JUnit tests with GUI

PostPosted: Mon Mar 07, 2016 4:00 pm
by jvxdev
How do I start a JVx application for JUnit tests?

I tried to start the application with a custom launcher, but got a NullPointerException. Do you have a special launcher for JUnit tests?

Re: JUnit tests with GUI

PostPosted: Mon Mar 07, 2016 4:15 pm
by Support@SIB
What do you mean with "a custom launcher". Did you extend an existing launcher or create a new one?

It's not necessary to create a new launcher. Simply use an existing one.

If you want to start the whole application, you could do following:

Syntax: [ Download ] [ Hide ]
SwingApplication app = new SwingApplication();
app.startup(YourApplication.class.getName(), "/yourapp/application.xml", null);
while (app.getApplication() == null || !app.getApplication().getLauncher().isVisible())
    catch (InterruptedException ie)
        throw new RuntimeException(ie);
YourApplication yapp = (YourApplication)app.getApplication();

if (yapp == null)
{"Application was not started!");

If you won't start the whole application, it's important to set at least a factory:

Syntax: [ Download ] [ Hide ]

The factory is important if you want to use GUI classes in your test cases. See example JUnit test-case.

If your test cases don't work because of invalid configuration files, it could help to set the configuration basedir:

Syntax: [ Download ] [ Hide ]
System.setProperty(IPackageSetup.CONFIG_BASEDIR, new File("").getAbsolutePath());

The path should be the directory which contains the rad directory.

Another option for headless tests is the JVx headless UI.

Re: JUnit tests with GUI

PostPosted: Thu Aug 25, 2016 1:19 pm
by Development@SIB
A complete launcher implementation is available here. The SimpleTestLauncher class.