In order to build a Maven project you can use one of the following:
This would build/compile and run the tests as well.
However, if you want to run the tests only then what would you do?
Sound similar? Yeah! we all often land up in this situation as an application developer. And, the solution is simple.
The default
- mvn clean install
- mvn clean package etc.
This would build/compile and run the tests as well.
However, if you want to run the tests only then what would you do?
Sound similar? Yeah! we all often land up in this situation as an application developer. And, the solution is simple.
You can use
mvn test
to run unit test in Maven. Few examples :# Run all the unit test classes.
$ mvn test
# Run a single test class.
$ mvn -Dtest=TestApp1 test
# Run multiple test classes.
$ mvn -Dtest=TestApp1,TestApp2 test
# Run a single test method from a test class.
$ mvn -Dtest=TestApp1#methodname test
# Run all test methods that match pattern 'testHello*' from a test class.
$ mvn -Dtest=TestApp1#testHello* test
# Run all test methods match pattern 'testHello*' and 'testMagic*' from a test class.
$ mvn -Dtest=TestApp1#testHello*+testMagic* test
The default
maven-surefire-plugin
is outdated, make sure update to the latest to support new features, like pattern matching or run a single test method, and etc.
pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
</plugins>
</build>
No comments:
Post a Comment