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 ‘BuildTest.java

D:\work\MyNBPlatformApp>ant -Dtest.type=qa-functional -Dtest.includes=org
/acme/ide/projectbuild/*BuildTest.java test-single
Advertisements
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”.

JUnit, NetBeans RCP, Testing

Delicious JellyTools for NetBeans functional testing


Yesterday I had the pleasure of writing some functional tests (for an in house IDE) using JellyTools, NetBeans’ extension to the Jemmy testing framework. The testing APIs offered by Jelly and Jemmy are very intuitive and you can get your GUI test up and running in minutes.

Jemmy provides various types of Swing/AWT  ‘operators‘ that can be used to manipulate GUI components. Examples for Jemmy operators include JTreeOperator, JPopupMenuOperator, JCheckBoxOperator etc.

Jelly extends these and provide NetBeans platform specific convenience operators such as TopComponentOperator, OutputTabOperator, ProjectsTabOperator etc.

In my case, my functional test needed to test my (custom) IDEs build project functionality.

public void testIDEBuild() {
   //utility method to open a project, code not shown here
   openProject(PROJ_NAME); 
   //open the IDEs output window
   new OutputWindowViewAction().perform(); 
   //get a handle to the Projects tab in NetBeans
   ProjectsTabOperator projects = new ProjectsTabOperator();
   //get a handle to the project tab's explorer tree
   JTreeOperator tree = new JTreeOperator(projects);
   //find the node that contains the RMB action 'Build'
   TreePath path = tree.findPath(PROJ_NAME+"| My Applications"); 
   //get a popmenu operator
   JPopupMenuOperator menu = new JPopupMenuOperator(tree.callPopupOnPath(path));   
   //call the 'Build' action
   menu.pushMenuNoBlock("Build");    
   //get the output tab containing 'proj-build' ANT output
   OutputTabOperator outputTabOp = new OutputTabOperator("proj-build"); 
   //give 2 mins for building
   outputTabOp.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 120000);
   //check for "BUILD SUCCESSFUL" if not the test fails
    outputTabOp.waitText("BUILD SUCCESSFUL"); 
}

For information on how to get started with NetBeans testing and how to write JellyTools tests refer the following links.