简体   繁体   English

有条件地从Maven运行JUnit测试

[英]Conditionally run JUnit tests from Maven

In Maven, is there some way to specify that JUnit tests only run when there are some source code changes? 在Maven中,是否有一些方法可以指定只有在源代码更改时才运行JUnit测试?

For instance, I see this message 例如,我看到了这条消息

[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ my_project ---
[INFO] Nothing to compile - all classes are up to date

Now -since no code was compiled (since there were no changes from the last compile), I'd prefer that no tests run. 现在 - 因为没有编译代码(因为上次编译没有变化),我宁愿不运行任何测试。 Is this possible? 这可能吗?

Your project setup should be broken up into separate modules. 您的项目设置应分解为单独的模块。 However if you can not do that you could set the maven.test.skip property in your profiles in which you want no tests to be run. 但是,如果您不能这样做,您可以在您希望不运行测试的配置文件中设置maven.test.skip属性。 See more about skipping tests on the site . 了解有关在网站上跳过测试的更多信息

You are talking about a war project. 你在谈论一个战争项目。 Typically a war project should NOT have any code in it, but rather just some configuration and stuff like html, jsp, css and java script and bundle jar projects, that contain java code. 通常,war项目中不应包含任何代码,而只需要包含java代码的一些配置和内容,如html,jsp,css和java脚本以及bundle jar项目。 The jar projects will have the code. jar项目将拥有代码。 And if you do integration tests a good practice is to have them in separate modules. 如果你进行集成测试,一个好的做法是将它们放在单独的模块中。

Different war configs can be in profiles or potentially also in separate modules using the war overlay feature of the maven war plugin. 使用maven war插件的war叠加功能,不同的战争配置可以在配置文件中,也可能在单独的模块中。

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

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