Thursday 29 September 2022

How to execute tests in a maven project?

In this post, I am going to explain various scenarios to execute tests in a maven project.

 

Demo application has three test classes, where each class has one or more test cases.

 


 

Scenario 1: Execute all the tests.

mvn test

Scenario 2: Execute single test class.

mvn -Dtest=TestClass1 test

Above command execute all the tests in TestClass1.

Scenario 3: Execute tests in multiple test classes.

mvn -Dtest=TestClass1,TestClass3 test

Above command execute all the tests in TestClass1, TestClass3.

 

Scenario 4: Run single test case from a test class.

mvn -Dtest=TestClass1#testCase1 test

Scenario 5: Run all the test cases that match to a pattern in a test class.

mvn -Dtest=TestClass1#*2 test

Above snippet run all the test cases where the test case name ends with 2 in TestClass1.

 

You can download this application from this link.



Previous                                                 Next                                                 Home

No comments:

Post a Comment