Pages

Monday, May 27, 2019

Jenkins - Integration with Junit

Unit testing is defined as a type of software testing where individuals units/components of the software ( the code that developers write ) are tested. This testing is done during development of an application. The objective of unit testing is to isolate a section of code and verify its correctness. In a normal programming language , a unit can be taught as an individual function or procedure. The unit testing code will be generally written by developer.

Junit is an open Source Unit Testing framework for Java. It is useful for java Developers to write and run repeatable tests for the code they have written. Junit is an instance of xUnit architecture. Developers basically write and execute unit tests first before writing any code. Once the code is done we should execute all tests and they should pass. Every time a new code is added , we need to re execute all test cases and make sure nothing is broken

In this article, we will see how we can run the Junit test cases as a part of the CI/CD pipeline using jenkins

1. Install the Xunit plugin from Manage Jenkins -> Manage plugins. The xunit plugins once installed supports multiple languages like java ,python by including plugins for that language like Junit for java etc.

2. Provide the maven goals and options as “clean test verify” for the maven project which contains the Junit test cases

3. Choose the Post step action and provide the necessary details like below,

The pattern is the most important one. We need to provide the location where our junit test cases results will be saved. These details will be saved with the name starting with TEST. provide the location as above.

That's it ,once we run our maven project containing junit test cases, we we see the results displayed as,

No comments :

Post a Comment