简体   繁体   中英

How to run single integration test in maven?

I am trying run single integration test. I have aa lot of *IT class and I want to run only one test. I try this :

mvn -Dit.test=XControllerIT verify

Am I doing wrong? Is there another alternative to this? Maven is being used.

There are two main options depending on your project setup:

  • Integration Tests are run with a dedicated Failsafe plugin
  • Integration Tests are run with a regular surefire plugin

If you have a failsafe plugin (and you actually should, its a recommended approach), then use the following snippet:

mvn -Dit.test=MySampleIntegrationTest failsafe:integration-test

If you're on surefire, then run:

mvn -Dtest=MySampleUnitTest surefire:test

In both cases there is a direct plugin goal execution, bypassing the lifecycle like in your initial example (with mvn verify )

In maven it is possible to run the lifecycle, see Default Lifecycle Documentation for more information

Basically, the lifecycle is comprised of phases with plugins bound to each phase So when you run the mvn verify all the phases before verify will also run.

As a consequence, the code will be compiled (compile phase with a maven compile plugin automatically attached to it will do the job), tests will run (surefire plugin), and so on.

If you don't have a compiled source code and code of tests, you can't use the presented approach because you have to compile the code first.

However, if you already have everything compiled, it makes sense to run only the one test without recompilation of the code, and in this case, depending on the plugin you can use the suggested solution.

Especially it can make sense for local debugging or for CI in some cases multi-step build setup (can be seen in fairly complicated projects)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM