You have three ways to run TestNG tests: right-click in IntelliJ (good for development), Maven from the command line (good for CI/CD), or testng.xml (good for suite management). In real projects, you use all three.
# Run all tests (uses testng.xml from pom.xml config)
mvn test
# Run a specific test class
mvn test -Dtest=BankingLoginTest
# Run a specific test method
mvn test -Dtest=BankingLoginTest#testSuccessfulLogin
# Run multiple test classes
mvn test -Dtest="BankingLoginTest,ShoppingCartTest"
# Run a specific testng.xml file
mvn test -DsuiteXmlFile=testng-smoke.xml
# Run a specific group
mvn test -Dgroups=smoke
# Skip tests (for when you just want to build)
mvn install -DskipTestsAfter every test run, TestNG generates a file called testng-failed.xml in the test-output directory. This file contains only the tests that failed. You can re-run just those:
# First run — some tests fail
mvn test
# Re-run only the failed tests
mvn test -DsuiteXmlFile=test-output/testng-failed.xmlIn CI/CD pipelines (Jenkins, GitHub Actions), teams often run the full suite first, then automatically re-run failed tests once more. If a test fails twice, it is a real bug. If it passes on retry, it is flaky and should be investigated later.
After running tests, TestNG generates reports in the test-output directory:
Open test-output/index.html in a browser after your test run to see the full report. In later chapters, we will add Allure or Extent Reports for much richer HTML reports with screenshots and step details.
Make sure your test classes are in src/test/java, not src/main/java. Maven only scans src/test/java for test classes. If your tests are in the wrong folder, "mvn test" will say "No tests to run" and you will spend an hour wondering why.
Key Point: Run with IntelliJ (development), Maven (CI/CD), or testng.xml (suite management). Use testng-failed.xml to re-run failures.