jenkins
How to schedule your maven tests or TestNG tests using Jenkins?
Here are the high-level steps to schedule your Maven or TestNG tests using Jenkins:
- Install and configure Jenkins: Install Jenkins on a server, and configure it with the necessary plugins, such as the Maven and TestNG plugins.
- Create a Jenkins job: Create a new Jenkins job for your project and configure it to use Maven and TestNG for building and testing your project.
- Configure the Source Code Management: Set up the source code repository for your project, such as Git or SVN, and configure Jenkins to checkout the code.
- Set up Maven goals: In the build section of your Jenkins job, configure the Maven goals to run during the build process. This includes compiling the source code, running the TestNG tests, and packaging the final artifact.
- Configure TestNG: In the post-build action section of your Jenkins job, configure TestNG to run your tests and generate a test report.
- Schedule the build: Set the build trigger for your Jenkins job, such as building periodically or building after a code change.
- Start the build: Initiate a build for your project and monitor the build and test results in the Jenkins dashboard.
By following these steps, you can schedule your Maven or TestNG tests to run automatically in Jenkins, ensuring that your tests are executed regularly and the results are captured for future reference.
Le-Man's steps:
Download Jenkins war file
Open the command prompt and navigate to the downloaded folder
use command : java -jar jenkins.war -httpport-8080
Wait for the text "Jenkins is fully Up and Running" to appear on cmd window
Goto URL : localhost:8080 on the browser and open Jenkins consol
Go to Manage Jenkins
Click global tools configurations
Provide JDK path for JDK installation
Click on Maven Installations: provide MAVEN_HOME path
Save
-----------------------------------------------------------------------------
Create a new job:
Create a new Jenkins job
select freestyle project
You need to provide the code for Jenkins to execute:
provide git hub link for code or provide a local link -by selecting use custom workspace
Ex. $(JENKINS_HOME)/project folder name where pom.xml is located
Go to build triggers, click build periodically, and provide schedule using a regular expression :
Ex. Min Hour Day Month DayOfWeek
20 7 * * * : Everyday at 7:20 am
Go to build and click invoke top level maven targets
provide maven version and maven command
test -PRegression
since we are dealing with maven, ignore mvn from the actual command mvn test -PRegression
Save
If you want to run the build now, click on build now
and monitor console or it will get triggered at the provided scheduleReporting in Jenkins:
Jenkins provides several reporting options to view the results of builds and tests:
- Console Output: The console output displays the log of the build and test execution, showing the details of each step of the build process, including the status of each task and any error messages.
- Build History: The build history displays a list of all builds for a job, including the status of each build, the duration, and the date and time of each build.
- Test Result: Jenkins provides a test result report that shows the results of test execution, including the total number of tests, the number of tests that passed, failed, or were skipped, and the details of each test.
- Trends Report: Jenkins provides a trends report that displays historical data on builds and tests, including the number of builds, the duration of builds, and the number of tests that passed or failed over time.
- Artifacts: Jenkins stores the artifacts generated by a build, such as the final distribution, test reports, and log files, which can be downloaded and used for further analysis.
- Third-party Plugins: Jenkins integrates with several third-party reporting tools, such as JUnit, TestNG, and Allure, to provide more advanced reporting options, including test case-level details, test result trend charts, and more.
By using these reporting options, you can effectively monitor and analyze the results of your builds and tests, ensuring that your builds and tests are executing correctly and providing the necessary information for troubleshooting and debugging.
Le-Man's steps:
The Surefire plugin in pom.xml file provides result in simple format
For better reporting, go to
Manage Jenkins -- manage plugins -- search TestNG results plugin
install it
Go to project configuration
go to post build options
there's an option of publish testNG results- provide XML path if not configured by default
Save, and you are done. Now, you will get good formated report on Jenkins console after the build gets completed.