简体   繁体   English

使用 Maven 运行已编译的单元测试

[英]Run an already compiled unit test with Maven

I would like to know if it is possible to run a previously compiled test (using mvn test-compile ) without having to recompile a project and its tests.我想知道是否可以运行先前编译的测试(使用mvn test-compile )而无需重新编译项目及其测试。 I'm aware of the mvn -Dtest=TestClass#testMethod test command, but it does not fit my need.我知道mvn -Dtest=TestClass#testMethod test命令,但它不适合我的需要。

More generally I'm trying to find a way to run unit tests is a specific order using a list of test names.更一般地说,我试图找到一种运行单元测试的方法是使用测试名称列表的特定顺序。 Any idea would be appreciated.任何想法将不胜感激。

If you start maven by calling a phase it will execute all lifecycle phases up to the one you are calling.如果您通过调用一个阶段来启动 Maven,它将执行所有生命周期阶段,直到您调用的那个阶段。 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.在测试阶段的情况下,绑定目标是surefire 的测试魔力。 So you could call所以你可以打电话

mvn surefire:test

and no other lifecycle phase will be executed.并且不会执行其他生命周期阶段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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