Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I atomically run mvn tests (without rebuilding source code)?

I want to run a maven project lifecycle starting, and ending, with the unit tests.

How can I skip recompilation and re-resolution of dependencies and only run the test phase?

like image 258
jayunit100 Avatar asked Feb 14 '13 02:02

jayunit100


People also ask

How do I run a test in mvn test?

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”.

How do I run the Maven test clean?

To run all the unit tests with Maven run command $ mvn test or $ mvn clean test . If you use clean , all the resources and compiled java code generated by maven in target directory will be cleaned and run tests freshly.

What do we used to run unit test with Maven?

We can run our unit tests with Maven by using the command: mvn clean test. When we run this command at command prompt, we should see that the Maven Surefire Plugin runs our unit tests. We can now create a Maven project that compiles and runs unit tests which use JUnit 5.

What does mvn test command do?

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.


1 Answers

If you start maven by calling a phase it will execute all lifecycle phases up to the one you are calling. For example, when calling

mvn test 

all the phases before the test lifecycle phase will be execute too: the project will be validated, sources and resources will be generated and processed, sources will be compiled, the same will happen to test sources and resources and finally unit tests will be run.

But you can also call the plugin goal that is bound to a lifecycle phase. In the case of the test phase the bound goal is surefire's test mojo. So you could call

mvn surefire:test 

and no other lifecycle phase will be executed. You can find the goals bound to each phase depending on the package type here.

like image 61
Akro Avatar answered Sep 25 '22 21:09

Akro