🔧Maven- Project & Build Management Tool — Article #5
🔗Integrate TestNG With Maven
Execute Specific Test Cases 📄 With Maven
In this article, we’re going to learn how to trigger the TestNG XML file from the maven project.
💭Revision: In Article #4, We taught about the ‘mvn test’ command to execute all the test cases in the ‘src/test/java folder.
But think if you have 100 test cases 🤪 but you only need to run 40 test cases then how would you do that 🤔.
We can do this by using the TestNG XML file that we learned in TestNG’s Article. Now Let’s do this, basically, we just need to integrate the TestNG XML file with Maven, Simple!🤷♂️
Steps:
[🔃See TestNG’s Article to create Step by step TestNG XML file]
First Right-click on the project → TestNG → Convert to TestNG then testng.xml file will be shown in your maven project’s folder.
Execute Specific Test from Maven Project
In the previous article we taught ‘mvn test’ command but this command triggers all the test in ‘src/test/ java folder but if you want to execute specific tests included in testng.xml file from maven project then how would you do that🤔❔ Follow the steps 👇
Steps:
- Open the official website of apache maven.
- Copy these lines 👇 and paste it in pom.xml file.
3. Scroll down the page and copy these lines 👇 then paste it in pom.xml in the surefire plugin tag.
Now, if you’ll run ‘mvn test’ command then it will not execute all the tests but only those tests included in xml file.
Execute a Single Test from Maven Project
If you client wants you to run only one .java file then you can also do this, follow the steps 👇
- Open the official website of apache maven.
- Copy this line 👇
Syntax:
mvn -Dtest=TestName test /*Write your .java file name instead of
'TestName' and run this command on cmd*/
Follow my all articles to learn Maven step by step. In the next article we’ll learn about ‘Switching the test with maven profiling’.
Best of luck 👍