JUnit tests with GUI

General questions regarding the development with JVx.

JUnit tests with GUI

Postby jvxdev » Mon Mar 07, 2016 4:00 pm

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?
jvxdev
 
Posts: 19
Joined: Fri Mar 04, 2016 12:40 pm

Re: JUnit tests with GUI

Postby Support@SIB » Mon Mar 07, 2016 4:15 pm

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.setSystemExitOnDispose(false);
app.startup(YourApplication.class.getName(), "/yourapp/application.xml", null);
       
while (app.getApplication() == null || !app.getApplication().getLauncher().isVisible())
{
    try
    {
        Thread.sleep(100);
    }
    catch (InterruptedException ie)
    {
        throw new RuntimeException(ie);
    }
}
       
YourApplication yapp = (YourApplication)app.getApplication();

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

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

Syntax: [ Download ] [ Hide ]
UIFactoryManager.getFactoryInstance(SwingFactory.class);

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.
User avatar
Support@SIB
 
Posts: 201
Joined: Mon Sep 28, 2009 1:56 pm

Re: JUnit tests with GUI

Postby Development@SIB » Thu Aug 25, 2016 1:19 pm

A complete launcher implementation is available here. The SimpleTestLauncher class.
User avatar
Development@SIB
 
Posts: 311
Joined: Mon Sep 28, 2009 1:54 pm


Return to Development