简体   繁体   English

奇怪的行为 maven 测试

[英]Weird behaviour maven tests

I tought I was quite familiar with maven and it's behaviour but i'm not figuring out this one.我认为我对 maven 及其行为非常熟悉,但我没有弄清楚这一点。 I have a parent project in which i defined the property:我有一个父项目,我在其中定义了属性:

        <maven.test.skip>true</maven.test.skip>

which I know is meant to not build test jars.我知道这意味着不构建测试罐。

I then created three properties still in the parent project like the following然后我在父项目中创建了三个属性,如下所示

<skipChild1Test>true</skipChild1Test>
<skipChild2Test>true</skipChild2Test>
<skipChild3Test>true</skipChild3Test>

Each of the child projects have a maven-surefire-plugin section like the following每个子项目都有一个 maven-surefire-plugin 部分,如下所示

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M3</version>
    <configuration>
        <skipTests>${skipChildNtest}</skipTests>
    </configuration>
</plugin>

Basically i want to statically declare in the parent POM which child projects should run the test and which not.基本上我想在父 POM 中静态声明哪些子项目应该运行测试,哪些不运行。

However those properties seems to have no effect at all and all it's driven by the original property然而,这些属性似乎根本没有影响,而且都是由原始属性驱动的

<maven.test.skip>true</maven.test.skip>

which runs the tests on the children if false and it does not if it is true.如果为假,则对子项运行测试,如果为真则不运行。

I always issue the command mvn test on the parent project我总是在父项目上发出命令mvn test

Did I configured the children wrong?我是不是把孩子配置错了?

UPDATE更新

Looking on the maven-surefire-plugin test goal details i read the following about the skip parameter:查看 maven-surefire-plugin 测试目标详细信息,我阅读了有关跳过参数的以下内容:

" Set this to "true" to bypass unit tests entirely. Its use is NOT RECOMMENDED, especially if you enable it using the "maven.test.skip" property, because maven.test.skip disables both running the tests and compiling the tests. Consider using the skipTests parameter instead. " "将此设置为 "true" 以完全绕过单元测试。不推荐使用它,特别是如果您使用 "maven.test.skip" 属性启用它,因为 maven.test.skip 禁用运行测试和编译测试. 考虑改用skipTests 参数。

So what I read on stackoverflow and many other places was not correct.所以我在 stackoverflow 和许多其他地方读到的都是不正确的。 maven.test.skip drives both packagin and running the tests maven.test.skip 驱动打包和运行测试

You could just overwrite the property in the child projects with <maven.test.skip>${skipChildNtest}</maven.test.skip>您可以使用<maven.test.skip>${skipChildNtest}</maven.test.skip>覆盖子项目中的属性

So then the property <maven.test.skip> in your parent project would not interfere with your child projects.因此,您的父项目中的属性<maven.test.skip>不会干扰您的子项目。

Maybe you can also get rid of the plugin declaration in your child projects, but of that im not sure.也许你也可以在你的子项目中去掉插件声明,但我不确定。

Did I configured the children wrong?我是不是把孩子配置错了?

There are several related properties for the Surefire plugin: skipTests , skipExec and skip . Surefire 插件有几个相关的属性: skipTestsskipExecskip

When you set the skipTests property in the configuration, it overrides the older skip property that you're setting through the maven.test.skip property.当您在配置中设置skipTests属性时,它会覆盖您通过maven.test.skip属性设置的旧skip属性。

The corresponding properties and config names are:相应的属性和配置名称是:

Property财产 Config配置
skipTests skipTests
maven.test.skip.exec skipExec
maven.test.skip skip

To correspond to the maven.test.skip property, you should use:要对应于maven.test.skip属性,您应该使用:

    <configuration>
        <skip>${skipChildNtest}</skip>
    </configuration>

instead.反而。

You could also consider the plugin's advice, and use skipTests for both, to still compile the tests but not run the,.您还可以考虑插件的建议,并为两者使用skipTests ,以仍然编译测试但不运行,。

SOLUTION解决方案

As suggested by Reto I simply redeclared maven.test.skip in all child projects.正如 Reto 所建议的,我只是在所有子项目中重新声明了 maven.test.skip。 The value is still configured in the parent project.该值仍然在父项目中配置。 As an example:举个例子:

From a parent perspective, i define the following property:从父母的角度来看,我定义了以下属性:

<skipChild1Test>true</skipChild1Test>

From CHILD1 perspective i define the following property:从 CHILD1 的角度来看,我定义了以下属性:

<maven.test.skip>${skipChild1Test}</maven.test.skip>

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

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