JUnit tests with GUI
3 posts
• Page 1 of 1
JUnit tests with GUI
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?
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
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:
If you won't start the whole application, it's important to set at least a factory:
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:
The path should be the directory which contains the rad directory.
Another option for headless tests is the JVx headless UI.
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:
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!");
}
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:
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:
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.
-
Support@SIB - Posts: 353
- Joined: Mon Sep 28, 2009 1:56 pm
Re: JUnit tests with GUI
A complete launcher implementation is available here. The SimpleTestLauncher class.
-
Development@SIB - Posts: 325
- Joined: Mon Sep 28, 2009 1:54 pm
3 posts
• Page 1 of 1