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.