![]() |
VOOZH | about |
To run TestNG tests with Maven, it is not mandatory to configure any testng.xml. Instead of this you just let Maven do the execution with maven-surefire-plugin of the Maven build lifecycle and for that you don't need to define any test suite, classes, or methods in testng.xml. The maven-surefire-plugin allows you to run your TestNG tests directly by providing options in the pom.xml file.
Following are the approaches to execute testNG and Maven without the testng.xml file
pom.xml
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running MyTest
Executing testMethod1
Executing testMethod2
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.123 sec
-------------------------------------------------------
BUILD SUCCESS
Running TestNG tests from Maven with no testng.xml is very straightforward using maven-surefire-plugin. You can configure a usage of that plugin within your pom.xml in such a manner to make the plug-in automatically discover and run your TestNG-based tests. This approach makes your test configuration simpler and keeps your project structure clean, as you do not require keeping an external testng.xml file in particular for running tests.