ANT, Functional Test, NetBeans IDE, NetBeans RCP, Testing

Selectively running functional tests in NetBeans

Sometimes you may require to run only certain selected functional tests instead of running all tests in your NetBeans project. This is straightforward if you are doing it directly using the IDEs menu options in NetBeans since you can select the specific test file and run it.

But sometimes (e.g. Jenkins/Hudson CI) you may need to run selected functional tests from the command line. In such cases the first thing to note is that you must use the ‘test-single’ ANT target instead of the usual ‘test’ target to run your tests. You also have to provide two important parameters for it to work. They are ‘test.type’ and ‘test.includes’. The ‘test-type’ parameter should tell ANT to run ‘qa-functional’ tests and the ‘test-includes’ parameter should provide the actual functional test file name to be run. The ‘test-includes’ parameter can take wild cards therefore you can actually run multiple tests using the ‘test-single’ ANT target 🙂

Here’s an example, where I wanted to run all tests in org/acme/ide/projectbuild package which ends with ‘

D:\work\MyNBPlatformApp>ant -Dtest.type=qa-functional -Dtest.includes=org
/acme/ide/projectbuild/* test-single
ANT, Functional Test, Jenkins, JUnit, NetBeans RCP

NetBeans GUI tests on Jenkins + Windows

Running NetBeans application tests on Jenkins CI is quite easy. You just need to call the ‘test’ target in your NetBeans application’s build script (e.g. ANT build.xml) and Jenkins will do the rest. I initially setup Jenkins as a windows service to run my tests. This works fine for unit tests since they do not require a display to execute.

But recently I faced some issues when I wanted to run some functional (GUI) tests of a NetBeans platform app using a Jenkins job running on Windows. Since the Jenkins process could not access the windows display all the GUI tests were failing. On a linux box this issue is addressed by using X display such Xvnc (available as a Jenkins plugin), but of course I cannot use X display on windows!

After googling around I came across a possible solution which was to enable the option “Allow service to interact with desktop” for my Jenkins service. But as promising as it seemed it did not work, my GUI tests continued to fail 😦

Then I decided to stop and disable the Jenkins windows service and just ran it from the windows command prompt using the refreshingly simple command “java -jar jenkins.war”. Voila!!! It worked all my GUI tests were running without any problem and I can even see the GUIs opening and closing automagically on my windows desktop.

This solution was confirmed when I later stumbled upon the wiki here, which shows how to run GUI tests on ‘Hudson’ (Jenkins’ original name before Oracle knocked its head on a rock!) using a Tomcat container running on Windows. Although I didn’t use a servlet container such as Tomcat the solution applies to my situation as well.

So there you are, if you want to run GUI tests on Jenkins CI running on Windows do not configure it as a windows service instead run it from the command prompt or set it up as a scheduled task to run on windows logon using the command “java -jar jenkins.war”.