Home > Software design >  Weird behaviour maven tests
Weird behaviour maven tests

Time:10-22

I tought I was quite familiar with maven and it's behaviour but i'm not figuring out this one. 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

<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.

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

Did I configured the children wrong?

UPDATE

Looking on the maven-surefire-plugin test goal details i read the following about the skip parameter:

"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."

So what I read on stackoverflow and many other places was not correct. maven.test.skip drives both packagin and running the tests

CodePudding user response:

You could just overwrite the property in the child projects with <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.

Maybe you can also get rid of the plugin declaration in your child projects, but of that im not sure.

CodePudding user response:

SOLUTION

As suggested by Reto I simply redeclared maven.test.skip in all child projects. 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:

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

CodePudding user response:

Did I configured the children wrong?

There are several related properties for the Surefire plugin: skipTests, skipExec and skip.

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.

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:

    <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,.

  • Related