Vivek
Vivek

Reputation: 13298

What is the difference between 'mvn verify' vs 'mvn test'?

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.

Upvotes: 75

Views: 68272

Answers (2)

Ziad Bougrine
Ziad Bougrine

Reputation: 47

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

Upvotes: 3

UrbanoJVR
UrbanoJVR

Reputation: 1307

First of all, when you run a Maven goal, it will run any previous goal. The order of basic phases is:

  • Validate
  • Compile
  • Test
  • Package
  • Verify
  • Install
  • Deploy

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.

Upvotes: 103

Related Questions