In real projects, you run tests from the command line — not from IntelliJ. Jenkins doesn't have an IDE. GitHub Actions doesn't have a right-click menu. The terminal command is how tests run in CI/CD, and you need to know every variation.
# ===== DAILY COMMANDS =====
# Run all tests (default testng.xml)
mvn clean test
# Run a specific suite
mvn clean test -DsuiteXmlFile=testng-smoke.xml
# Run a single test class
mvn clean test -Dtest=LoginTest
# Run a single test method
mvn clean test -Dtest=LoginTest#testValidLogin
# Run multiple classes
mvn clean test -Dtest=LoginTest,TransferTest,DashboardTest
# Run tests matching a pattern
mvn clean test -Dtest="*Login*"
# ===== CI/CD COMMANDS =====
# Headless Chrome on staging
mvn clean test -Pchrome,staging -Dheadless=true
# Cross-browser smoke test
mvn clean test -DsuiteXmlFile=testng-smoke.xml -Dbrowser=firefox
# Run specific TestNG groups
mvn clean test -Dgroups=smoke
mvn clean test -Dgroups="smoke,login"
# Exclude broken tests
mvn clean test -DexcludedGroups=broken
# ===== DEBUGGING COMMANDS =====
# Just compile — check for compilation errors
mvn clean compile test-compile
# Show all dependencies
mvn dependency:tree
# Download all dependencies (useful after fresh clone)
mvn dependency:resolve
# Check for dependency updates
mvn versions:display-dependency-updates
# Show active profiles
mvn help:active-profiles
# Run with debug output
mvn clean test -X
# ===== OTHER USEFUL COMMANDS =====
# Skip tests (just build)
mvn clean package -DskipTests
# Install to local repo
mvn clean install -DskipTests
# Force re-download all dependencies
mvn clean test -UThe -D flag sets a system property. When you run mvn test -Dbrowser=firefox, Maven makes "browser" = "firefox" available to your code via System.getProperty("browser"). You can pass any property — browser, headless, base URL, test data file, anything.
# Pass multiple properties at once
mvn clean test \
-Dbrowser=chrome \
-Dheadless=true \
-Dbase.url=https://testerrank.com/banking \
-DsuiteXmlFile=testng-regression.xml \
-Dthread.count=4// In your test code, read these properties:
String browser = System.getProperty("browser", "chrome"); // default: chrome
String headless = System.getProperty("headless", "false"); // default: false
String baseUrl = System.getProperty("base.url", "https://www.testerrank.com/banking");
int threadCount = Integer.parseInt(System.getProperty("thread.count", "1"));Q: How do you run tests from the command line using Maven?
A: The most common command is mvn clean test — this cleans old builds and runs all tests using the configured testng.xml. For specific scenarios: mvn test -DsuiteXmlFile=testng-smoke.xml for a specific suite, mvn test -Dtest=LoginTest for a single class, mvn test -Dgroups=smoke for TestNG groups. We pass environment-specific settings via -D flags like -Dbrowser=chrome and -Dheadless=true. For CI pipelines, we use profiles: mvn clean test -Pchrome,staging,regression.
The two commands you'll type 100 times: mvn clean test for local runs, and mvn clean test -DsuiteXmlFile=testng-smoke.xml -Dbrowser=chrome -Dheadless=true for CI. Memorize these — you'll use them daily.
Key Point: mvn clean test is your daily workhorse. -D passes properties, -P activates profiles. Learn these commands by heart.