I'm bit confused with mvn verify
phase. I've created a Spring Boot project (a simple project, without any explicit configurations added). I've created a few JUnit unit tests which are run with both the mvn verify
and mvn test
commands.
There isn't any difference observed in the mvn verify
and mvn test
command output.
What does mvn verify
do different than mvn test
?
Also some posts on Stack Overflow mentions that mvn verify
runs the integration tests. If this is the case then I have few questions.
mvn verify
is supposed to run only the integration tests, then why are unit tests executed with it?The verify phase will indeed verify the integration tests results, if one or more results have failed or not.
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.
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.
Verify is just another build lifecycle in maven so you can run it in command line from within the directory of your pom. xml file like any other maven command . If you want to run it from eclipse navigate to Run >> Run Configuration menu, select Maven build from left sidebar and make your own maven build.
mvn verify - as said before - performs any integration tests that maven finds in the project. mvn install implicitly runs mvn verify and then copies the resulting artifact into your local maven repository which you usually can find under C:\Users\username\.m2epository if you are using windows.
mvn verify - run any checks on results of integration tests to ensure quality criteria are met clean is a lifecycle that handles project cleaning. Commands involving clean before it will clear the entire directory, meaning that all the classes have to be recompiled.
If you run Test, Maven will execute validate, compile and test. Based on this, the first point is that verify includes test. TEST - test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed To run unit tests, the Surefire plugin is recommended.
mvn clean install -DskipTests The first invocation of mvn verify is for testing the project builds and also downloading all required dependencies and plugins to the local Maven repository, that way network access should not affect the build times. Then the repository is cleaned and the actual measurements take place.
First of all, when you run a Maven goal, it will run any previous goal. The order of basic phases is:
If you run Test, Maven will execute validate, compile and test. Based on this, the first point is that verify includes test.
Based on official documentation:
TEST - test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
VERIFY - run any checks on results of integration tests to ensure quality criteria are met
To run unit tests, the Surefire plugin is recommended. And Failsafe for integration tests.
The verify command executes each default lifecycle phase in order (validate, compile, package, etc.), before executing verify. In most cases the effect is the same as package. However, in case there are integration tests, these will be executed as well. And during the verify phase some additional checks can be done, e.g. if your code is written according to the predefined checkstyle rules.
Conclusion: if you want to run your integration tests and check it, use verify. If you only want to run unit tests, use test.
My personal advice: if in doubt, use verify.
How does Maven identify a specific test as a unit test or integration test?
Integrations Test always takes a name like IT.java or IT.java or *ITCase.java
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