Sunday, September 18, 2011

Debugging Apache ODE Test Classes with Maven Surefire Plugin

There are some occasions when we need to debug the test classes in our unit tests base in the maven project. Ever wondered how to do that??  Well i did at the beginning when i had to debug the ODE test cases and that was when i found the way with maven surefire plugin. However this method can be used with any maven built project than ODE too.

Environment: Ubuntu 10.04 
                       Apache ODE 1.3.5 
                       Apache Maven 2.2.1 
                       Maven Surefire Plugin 2.5 
                       IntelliJ Idea 10.0.3

Here we go. Apache ODE's root 'pom.xml' file generally includes the maven surefire plugin by default as a test framework. The surefire 'debug' option is used to remotely debug the test classes in any of the modules in ODE project which is built using maven. First of all let's create a remote debug configuration with 'localhost' and default '5005' port, which is used by surefire. I have called mine as 'maven'.

Figure 1: Create a remote debug for Surefire

Now go to the specific module in ODE project directory in which we want to debug the test class. If you need to debug a single test class simply use the following command.

odeTrunk/bpel-compiler$ mvn clean install -Dmaven.surefire.debug -Dtest="CompilationMessageTest" -o

-Dmaven.surefire.debug : This tells maven to enable the surefire debug property and it will listen on default port 5005, for a remote debug connection to get attached.

-Dtest="CompilationMessageTest" : This command is used to declare the exact test class we need to debug. 

-o : Informs maven to build the module offline. If you need to build it online just remove the '-o' command.

When maven starts to build in debug mode we can see that it will hang on the console when waiting for a remote debug configuration as shown here.

Figure 2: Starting debug a single test class

At this time start the 'maven' debug in the IDE and it will pause at the given breakpoint in our 'CompilationMessageTest' class in the 'bpel-compiler'module.

Figure 3: Remote debug the test class

We don't have to declare a specific test class name under -Dtest command to debug that single test. Instead we can enable debugging for all the test classes and keep the breakpoint in the necessary class as our wish. In this case maven will run all the test classes in that module and will break at the specified breakpoint when it come to the relevant test class. The command for this should be;

odeTrunk/axis2-war$ mvn clean install -Dmaven.surefire.debug -o

No comments:

Post a Comment