Continuous testing in CI/CD in Testing Fundamentals - Build an Automation Script
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building the application...'
sh 'mvn clean compile'
}
}
stage('Test') {
steps {
echo 'Running automated tests...'
sh 'mvn test'
}
post {
always {
junit 'target/surefire-reports/*.xml'
}
}
}
}
post {
failure {
echo 'Build or tests failed. Please check the logs.'
}
success {
echo 'Build and tests passed successfully.'
}
}
}
This Jenkins pipeline script automates continuous testing in a CI/CD environment.
Agent any means the pipeline runs on any available agent.
There are two main stages: Build and Test.
In the Build stage, the command mvn clean compile compiles the application.
In the Test stage, mvn test runs automated tests.
The junit step publishes test results from the Surefire reports, so Jenkins can show test reports and fail the build if tests fail.
The post section handles messages on success or failure to inform the user.
This setup ensures that on every code commit, Jenkins builds the app, runs tests, and reports results automatically, which is the essence of continuous testing in CI/CD.
Now add data-driven testing with 3 different input configurations in the test stage