In order to run all Maven tests, we can use:
mvn clean test
If we want to run specific test class, we can use:
mvn clean test -Dtest=className
If we want to run specific method from specific test class, we can use:
mvn clean test -Dtest=className#methodName
But I want to run:
src\test\java
)src\test\java
)Are there Maven commands using which I can achieve above two?
The Maven surefire plugin provides a test parameter that we can use to specify test classes or methods we want to execute. If we want to execute a single test class, we can execute the command mvn test -Dtest=”TestClassName”.
1) Run all testcases with command “mvn test” : This command run all testcases present inside test folder irrespective of any other criteria.
mvn test-compile: Compiles the test source code. mvn test: Runs tests for the project. mvn package: Creates JAR or WAR file for the project to convert it into a distributable format. mvn install: Deploys the packaged JAR/ WAR file to the local repository.
If using surefire plugin then you may use the below options.
For multiple classes you can use,
mvn -Dtest=TestSquare,TestCi*le test
For multiple methods in same class you can use,
mvn -Dtest=TestCircle#testOne+testTwo test
Refer docs
You can use wildcards - note that you have to quote the test argument so the shell does not expand the wildcard.
mvn -Dtest="TestSquare,TestCi*le" test
(using maven-surefire-plugin:2.17)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With