Jenkins - Unit Testing
Jenkins provides an out of box functionality for Junit, and provides a host of plugins for unit testing for other technologies, an example being MSTest for .Net Unit tests. If you go to the link https://wiki.jenkins-ci.org/display/JENKINS/xUnit+Plugin it will give the list of Unit Testing plugins available.
Example of a Junit Test in Jenkins
The following example will consider
- A simple HelloWorldTest class based on Junit.
- Ant as the build tool within Jenkins to build the class accordingly.
Step 1 − Go to the Jenkins dashboard and Click on the existing HelloWorld project and choose the Configure option
Step 2 − Browse to the section to Add a Build step and choose the option to Invoke Ant.
Step 3 − Click on the Advanced button.
Step 4 − In the build file section, enter the location of the build.xml file.
Step 5 − Next click the option to Add post-build option and choose the option of “Publish Junit test result report”
Step 6 − In the Test reports XML’s, enter the location as shown below. Ensure that Reports is a folder which is created in the HelloWorld project workspace. The “*.xml” basically tells Jenkins to pick up the result xml files which are produced by the running of the Junit test cases. These xml files which then be converted into reports which can be viewed later.
Once done, click the Save option at the end.
Step 7 − Once saved, you can click on the Build Now option.
Once the build is completed, a status of the build will show if the build was successful or not. In the Build output information, you will now notice an additional section called Test Result. In our case, we entered a negative Test case so that the result would fail just as an example.
One can go to the Console output to see further information. But what’s more interesting is that if you click on Test Result, you will now see a drill down of the Test results.
No comments:
Post a Comment