Following part 1 and 2 which covered the JUnit test class creation and the coverage evaluation by Cobertura, we will add in part 3 another dimension: Automation. So far we run the tests manually, but we want to achieve a continuous integration and test environment.
Part 3 (Cobertura and Hudson)
Preparation:
Tutorial:
- Download and install Hudson
Hudson can run standalone (easier for testing, trialing and experimenting) or as a deployed application on an application server.
Once you downloaded it, just navigate with a terminal session (aka Dos-Box) and start it with “java -jar hudson.war“
You will get something like this:I will not go into any details of how to configure Hudson, but jump straight to our project. Maybe in another tutorial I will explain the basic setup of Hudson, but it so simple and the documentation is so good, it is easy for your to do the necessary settings.
- Tweak our Netbeans Project
As per standard setting when creating a new Netbeans project, the libraries are not kept in the project folder, but copied for deployment only. But Hudson need to access these libraries, one approach to solve this, is to keep the library files in the project folder.Open the project in Netbeans and open the project properties (right click project name). In the libraries section you just click Browse and Next.
Once this is done the libraries are kept locally in your project folder.
Now comes the interesting part, you remember the recommendation from the previous part of the tutorial saying you should modify only the build.xml file ?Netbeans needs to recreate its build file after our changes. So either we change it for Netbeans and select cancel (not knowing what changes need to be done) or we redo our changes or keep them finally in our own build.xml file.
- Create new Job in Hudson
Your Hudson is running and you can access it via http://localhost:8080 (assuming you run it as standalone on your local machine)
You see a mainpage like thisCreate new Hudson Job (Build a free-style software project)
Configuration of new Job in Hudson
The following parts of the configuration page are interesting for us
SVN repositoryInvoke Ant (please note it needs to be downloaded and configured first in the main Hudson configuration)
Trigger JUnit Report Creation (default path is usually **/build/test/results/*.xml)
Trigger Corbertura Report (default path is **/build/report/cobertura/coverage.xml)
All other configuration we dont need right now (I added the email function to drop me an email if the build is broken).
- Trigger the first Build
If everything is running fine we should have result like this (inclusive all Ant and JUnit log output)
... BUILD SUCCESSFUL Total time: 10 seconds Recording test results Publishing Cobertura coverage report... Publishing Cobertura coverage results... Finished: SUCCESS
Starting with the second build we will see a graph giving us tendencies over the last builds.
In our sample project we have covered 100% of the classes but only 50% of the lines.Test Code 50%
@Test
public void testApp() {
TestMe tst = new TestMe();
int res = tst.doSomething(3);
assertEquals(“Correct value”, 0, res);//res = tst.doSomething(6);
//assertEquals(“Correct value”, 2, res);//res = tst.doSomething(11);
//assertEquals(“Correct value”, -1, res);
}Lets re-insert the full test code and we get this after our next build:
Where to go from here:
- Explore all the features of Hudson, eg. Javadoc feature, trigger other builds and use fingerprints.
- Make Hudson production ready by deploying it on an application server such as Glassfish and securing it with logins,..
What else could I plug-in or do:
- There is a huge number of plugins available that help you to integrate with all kind of tools and frameworks.
- You can try the Netbeans Hudson feature (version 6.7 and higher)
- You could try using the Firefox plugin to constantly see the build status.















Pingback: Tutorial: Most simple Test Application for Embedded Glassfish + Netbeans + Hudson « The JavaDude Weblog
Hi , i am getting below error after hudson execution.
Total time: 5 seconds
Recording test results
Archiving artifacts
Publishing Cobertura coverage report…
No coverage results were found using the pattern ‘**/build/report/cobertura/coverage.xml’ relative to ‘C:\Program Files\Hudson\jobs\junitTesting\workspace’. Did you enter a pattern relative to the correct directory? Did you generate the XML report(s) for Cobertura?
Finished: FAILURE
Hi ashish,
Did you get the get this resolved ?
Now after resolving above issue , now i am getting below message :
BUILD SUCCESSFUL
Total time: 4 seconds
Recording test results
No test report files were found. Configuration error?
Archiving artifacts
Skipping Cobertura coverage report as build was not UNSTABLE or better …
Finished: FAILURE