Commands
3 min
Maven Commands for QE
Essential Maven commands for test automation projects
...
mavenjavabuild-toolstesting
Essential Maven Commands for Test Automation
1. Running Tests
# Run all tests
mvn test
# Run specific test class
mvn test -Dtest=LoginTest
# Run multiple test classes
mvn test -Dtest=LoginTest,CheckoutTest
# Run tests matching pattern
mvn test -Dtest="*IntegrationTest"
# Run single test method
mvn test -Dtest=LoginTest#testValidLogin
# Skip tests during build
mvn clean install -DskipTests2. Test Execution with Parameters
# Run with custom properties
mvn test -Dbrowser=chrome -Denv=staging
# Run specific test suite
mvn test -DsuiteXmlFile=testng-smoke.xml
# Parallel test execution
mvn test -DthreadCount=4 -Dparallel=methods
# Run with profile
mvn test -P regression
# Debug mode (remote debugging on port 5005)
mvn test -Dmaven.surefire.debug3. Clean and Build
# Clean target directory
mvn clean
# Compile source code
mvn compile
# Compile test code
mvn test-compile
# Package project (skip tests)
mvn clean package -DskipTests
# Install to local repository
mvn clean install
# Verify build without installing
mvn clean verify4. Dependency Management
# Download dependencies
mvn dependency:resolve
# Show dependency tree
mvn dependency:tree
# Copy dependencies
mvn dependency:copy-dependencies
# Check for updates
mvn versions:display-dependency-updates
# Purge local repository cache
mvn dependency:purge-local-repository5. Reporting and Analysis
# Generate test reports
mvn surefire-report:report
# Generate site with reports
mvn site
# Run tests with coverage (JaCoCo)
mvn clean test jacoco:report
# Check code style (Checkstyle)
mvn checkstyle:check
# Find bugs (SpotBugs)
mvn spotbugs:checkCommon Test Configuration in pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<!-- TestNG suite file -->
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<!-- System properties -->
<systemPropertyVariables>
<browser>${browser}</browser>
<env>${env}</env>
<baseUrl>${baseUrl}</baseUrl>
</systemPropertyVariables>
<!-- Parallel execution -->
<parallel>methods</parallel>
<threadCount>4</threadCount>
<!-- Re-run failures -->
<rerunFailingTestsCount>2</rerunFailingTestsCount>
</configuration>
</plugin>
</plugins>
</build>Maven Profiles for Different Environments
<profiles>
<profile>
<id>smoke</id>
<properties>
<suiteXmlFile>testng-smoke.xml</suiteXmlFile>
</properties>
</profile>
<profile>
<id>regression</id>
<properties>
<suiteXmlFile>testng-regression.xml</suiteXmlFile>
<threadCount>8</threadCount>
</properties>
</profile>
<profile>
<id>staging</id>
<properties>
<env>staging</env>
<baseUrl>https://staging.example.com</baseUrl>
</properties>
</profile>
</profiles>Quick Reference
Useful Shortcuts
# Clean, compile, and test in one command
mvn clean test
# Skip test compilation
mvn clean install -Dmaven.test.skip=true
# Offline mode (use cached dependencies)
mvn -o test
# Update snapshots
mvn clean install -U
# Run with verbose output
mvn test -X
# Run quietly (errors only)
mvn test -qCI/CD Commands
# Jenkins/GitHub Actions typical command
mvn clean verify -B -Denv=ci
# Generate reports for CI
mvn clean test surefire-report:report-only
# Run with retry and fail at end
mvn test -fae -DrerunFailingTestsCount=2
# Package with all reports
mvn clean verify siteKey Takeaways
- Use
-Dtestparameter to run specific tests quickly - Leverage profiles for different test suites and environments
- Configure parallel execution for faster test runs
- Use
dependency:treeto troubleshoot dependency conflicts - Enable rerun for flaky tests in CI/CD
- Always use
cleanbefore running full test suites
Comments (0)
Loading comments...