This guide provides detailed steps for installing and configuring testing frameworks including JUnit 5, Selenium, TestNG, Cypress, and other testing tools on Jenkins.
- Jenkins server with administrative access
- Build tools (Maven/Gradle/npm) installed
- Browser drivers for Selenium tests
- Sufficient resources for test execution
Add JUnit 5 dependencies to your pom.xml:
<dependencies>
<!-- JUnit 5 Jupiter API -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.1</version>
<scope>test</scope>
</dependency>
<!-- JUnit 5 Jupiter Engine -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.10.1</version>
<scope>test</scope>
</dependency>
<!-- JUnit 5 Jupiter Params -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.10.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.2</version>
</plugin>
</plugins>
</build>Add JUnit 5 dependencies to your build.gradle:
test {
useJUnitPlatform()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.1'
}pipeline {
agent any
tools {
maven 'Maven 3.9.5'
jdk 'JDK 17'
}
stages {
stage('Test') {
steps {
sh 'mvn clean test'
}
post {
always {
junit '**/target/surefire-reports/*.xml'
}
}
}
}
}<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.8.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>dependencies {
testImplementation 'org.testng:testng:7.8.0'
}
test {
useTestNG()
}<dependencies>
<!-- Selenium WebDriver -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.16.1</version>
</dependency>
<!-- WebDriver Manager for automatic driver management -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<!-- JUnit 5 for Selenium tests -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.10.1</version>
<scope>test</scope>
</dependency>
</dependencies># For Ubuntu/Debian
sudo apt update
sudo apt install -y chromium-browser firefox
# Install ChromeDriver
wget https://chromedriver.storage.googleapis.com/114.0.5735.90/chromedriver_linux64.zip
sudo unzip chromedriver_linux64.zip -d /usr/local/bin/
sudo chmod +x /usr/local/bin/chromedriver
# Install GeckoDriver (for Firefox)
wget https://github.com/mozilla/geckodriver/releases/download/v0.34.0/geckodriver-v0.34.0-linux64.tar.gz
tar -xzf geckodriver-v0.34.0-linux64.tar.gz
sudo mv geckodriver /usr/local/bin/
sudo chmod +x /usr/local/bin/geckodriverimport io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class SeleniumTest {
@Test
public void testExample() {
WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");
options.addArguments("--disable-gpu");
WebDriver driver = new ChromeDriver(options);
driver.get("https://example.com");
// Your test logic here
driver.quit();
}
}pipeline {
agent any
stages {
stage('Selenium Tests') {
steps {
sh 'mvn clean test -Dtest=SeleniumTest'
}
post {
always {
junit '**/target/surefire-reports/*.xml'
}
}
}
}
}npm install --save-dev cypressCreate cypress.config.js:
const { defineConfig } = require("cypress");
module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
baseUrl: "https://example.com",
video: false,
screenshotOnRunFailure: true,
},
});pipeline {
agent any
tools {
nodejs 'Node 20'
}
stages {
stage('Install Dependencies') {
steps {
sh 'npm install'
}
}
stage('Cypress Tests') {
steps {
sh 'npm run cypress:run'
}
post {
always {
publishHTML(target: [
reportDir: 'cypress/reports',
reportFiles: 'index.html',
reportName: 'Cypress Report'
])
}
}
}
}
}pipeline {
agent any
environment {
CYPRESS_RECORD_KEY = credentials('cypress-record-key')
}
stages {
stage('Cypress Tests') {
steps {
sh '''
npm run cypress:run --record \
--key ${CYPRESS_RECORD_KEY} \
--parallel
'''
}
}
}
}npm install --save-dev @playwright/test
n```
### Install Browsers
```bash
npx playwright installCreate playwright.config.ts:
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
testDir: './tests',
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: 'html',
use: {
baseURL: 'https://example.com',
trace: 'on-first-retry',
},
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},
],
});pipeline {
agent any
tools {
nodejs 'Node 20'
}
stages {
stage('Install Dependencies') {
steps {
sh 'npm install'
}
}
stage('Install Playwright Browsers') {
steps {
sh 'npx playwright install --with-deps'
}
}
stage('Playwright Tests') {
steps {
sh 'npx playwright test'
}
post {
always {
publishHTML(target: [
reportDir: 'playwright-report',
reportFiles: 'index.html',
reportName: 'Playwright Report'
])
}
}
}
}
}npm install --save-dev jest @types/jestCreate jest.config.js:
module.exports = {
testEnvironment: 'node',
coverageDirectory: 'coverage',
collectCoverageFrom: [
'src/**/*.js',
'!src/**/*.test.js',
],
};pipeline {
agent any
tools {
nodejs 'Node 20'
}
stages {
stage('Install Dependencies') {
steps {
sh 'npm install'
}
}
stage('Jest Tests') {
steps {
sh 'npm test -- --coverage'
}
post {
always {
publishHTML(target: [
reportDir: 'coverage/lcov-report',
reportFiles: 'index.html',
reportName: 'Coverage Report'
])
}
}
}
}
}pip install pytest pytest-cov pytest-htmlpipeline {
agent any
stages {
stage('Install Dependencies') {
steps {
sh 'pip install -r requirements.txt'
}
}
stage('pytest Tests') {
steps {
sh '''
pytest --cov=. --cov-report=html \
--html=test-report.html \
--self-contained-html
'''
}
post {
always {
publishHTML(target: [
reportDir: '.',
reportFiles: 'test-report.html',
reportName: 'pytest Report'
])
publishHTML(target: [
reportDir: 'htmlcov',
reportFiles: 'index.html',
reportName: 'Coverage Report'
])
}
}
}
}
}pipeline {
agent any
stages {
stage('Parallel Tests') {
parallel {
stage('Unit Tests') {
steps {
sh 'mvn test -Dtest=UnitTest'
}
}
stage('Integration Tests') {
steps {
sh 'mvn test -Dtest=IntegrationTest'
}
}
stage('E2E Tests') {
steps {
sh 'mvn test -Dtest=E2ETest'
}
}
}
}
}
}- JUnit Plugin - For JUnit test reports
- HTML Publisher Plugin - For HTML test reports
- Cucumber Reports Plugin - For Cucumber test reports
- Allure Plugin - For Allure test reports
pipeline {
agent any
stages {
stage('Test') {
steps {
sh 'mvn clean test'
}
}
}
post {
always {
script {
allure includeProperties: false,
jdk: '',
results: [[path: 'target/allure-results']]
}
}
}
}- Use headless browsers for CI/CD environments
- Implement parallel test execution to reduce build time
- Use test containers for isolated test environments
- Implement proper test data management
- Use test reporting for visibility
- Implement retry logic for flaky tests
- Use test coverage thresholds to enforce quality
- Mock external dependencies for reliable tests
# Check browser driver versions
chromedriver --version
geckodriver --version
# Update browser drivers
sudo apt update
sudo apt upgrade chromium-browser firefox# Install xvfb for virtual display
sudo apt install -y xvfb
# Run tests with xvfb
xvfb-run mvn test# Fix permissions for Jenkins user
sudo chown -R jenkins:jenkins /var/lib/jenkins/.cacheBy following these steps, you should be able to install and configure modern testing frameworks on your Jenkins server. Remember to configure your Jenkins build jobs to execute the appropriate test commands and integrate test reporting for visibility into test results.