Maven -DskipTests ignored
Asked Answered
D

6

49

I'm building a Maven project with following SureFire configuration:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>${version.maven-surefire-plugin}</version>
    <configuration>
        <includes>
            <include>**/*Test.java</include>
        </includes>
    </configuration>
</plugin>

Problem is, that when I build it with mvn clean install -DskipTests=true, the tests are still being executed. What could be the problem?

I tried both -DskipTests(which is from the Maven website) and -DskipTests=true, which is added by IntelliJ Idea when I check "skip tests" checkbox.

I don't use any Maven settings.xml.

  • Maven version: 2.2.1
  • Surefire plugin: 2.3

EDIT If I comment out the SureFire plugin configuration, the parameter behaves as I expect to. What could be the problem with the configuration above?

Diaz answered 7/11, 2013 at 14:42 Comment(15)
have your try -Dmaven.test.skipDiagnostician
farmer: EDIT: This works, but it does something different. The tests are not only disabled, but also not compiled Reimus: Same resultDiaz
could you paste the full pom.xml and i will see if i can test itDiagnostician
That surefire configuration is redundant. Surefire is always run even without explicitly configuring the plugin because it's a standard plugin. Get rid of the whole section and see what happens.Merari
artbristol: It's a multimodule project with thousands of lines of poms. Is there something I could check?Diaz
Could you post your entire pom.xml?Swart
en. i think you can check if pom.xml has a parent pom.xmlDiagnostician
Please see my edit. I think the problematic part of the pom is what I've already posted.Diaz
Are your tests in the standard src/test/java directory for each of your modules or in different locations? What is the purpose of having the section you posted in your POM?Haem
yes, they are in the correct place. The reason for the configuration is, that I have a class TestSettings which I use for static configuration and I don't want it to be executed as a JUnit test. I only want files like xxxTest.java tested.Diaz
Don't you use decorations to mark which classes/methods are part of your actual test suite?Haem
artbistol: It helped, but I don't see why. I need the configuration, because I don't like the default pattern for what is and isn't a JUnit test. Nicola Musatti: I don't know what that is so I think no.Diaz
@Diaz What version of surefire are you using?Swart
@JamesB. I was using 2.3. When I upgraded to newer version it is fine. Thanks for your help.Diaz
Just rename TestSettings to something without Test in the nameMerari
S
17

What you did should work. How to debug this further:

  1. Run mvn help:effective-pom to see the whole POM that Maven will execute. Search it for test (case insensitive) to see if there is something odd.

  2. Run mvn test -X to get debug output. This will print the options used to configure the maven-surefire-plugin. Make sure you redirect the output to a file!

    In the log, you will see

    [DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-surefire-plugin:2.15:test' with basic configurator -->
    

    and then, some lines below that:

    [DEBUG]   (s) runOrder = filesystem
    [DEBUG]   (s) skip = false
    [DEBUG]   (s) skipTests = false
    

    These values mean that tests aren't skipped.

  3. Are you using a recent version of the plugin? Check here. Maybe this option wasn't supported for your version.

Susansusana answered 7/11, 2013 at 15:8 Comment(6)
In step 1 I don't see anything odd, but I don't know exactly what to look for either. I see none of these parameters in step 2. these are the parameters I have(which I think could mean something in this problem): forkMode=once; childDelegation=false; parallel=false;useFile=trueDiaz
Which version of the plugin?Susansusana
Update to version 2.15. 2.3 is pretty old. Maybe it doesn't support the compact syntax.Susansusana
ahh... now I understand it. It works when I remove the surefire configuration exactly because it uses newer version otherwise.Diaz
@AaronDigulla you seem to have been the first to suggest updating surefire. Why don't you post your comment as an answer so that NeplatnyUdaj can accept it? This would give you a little reputation increase and make the solution much more visible.Haem
Nicola: I was about to suggest that too :)Diaz
S
67

Maven knows two types of parameters for skipping tests:

-Dmaven.test.skip=true 

or

-DskipTests=true 

The surefire-plugin documentation only mentions the first one, which you have not tried yet.

Supination answered 7/11, 2013 at 14:49 Comment(4)
But maven.test.skip also skips compiling the tests. This is not necessarily what the OP wants.Swart
Is it possible to compile tests and just not run them?Diaz
The flag you are using should do that @DiazSwart
Yes. It should. Apparently my surefire plugin configuration breaks it. Please see the edit of the original post.Diaz
S
17

What you did should work. How to debug this further:

  1. Run mvn help:effective-pom to see the whole POM that Maven will execute. Search it for test (case insensitive) to see if there is something odd.

  2. Run mvn test -X to get debug output. This will print the options used to configure the maven-surefire-plugin. Make sure you redirect the output to a file!

    In the log, you will see

    [DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-surefire-plugin:2.15:test' with basic configurator -->
    

    and then, some lines below that:

    [DEBUG]   (s) runOrder = filesystem
    [DEBUG]   (s) skip = false
    [DEBUG]   (s) skipTests = false
    

    These values mean that tests aren't skipped.

  3. Are you using a recent version of the plugin? Check here. Maybe this option wasn't supported for your version.

Susansusana answered 7/11, 2013 at 15:8 Comment(6)
In step 1 I don't see anything odd, but I don't know exactly what to look for either. I see none of these parameters in step 2. these are the parameters I have(which I think could mean something in this problem): forkMode=once; childDelegation=false; parallel=false;useFile=trueDiaz
Which version of the plugin?Susansusana
Update to version 2.15. 2.3 is pretty old. Maybe it doesn't support the compact syntax.Susansusana
ahh... now I understand it. It works when I remove the surefire configuration exactly because it uses newer version otherwise.Diaz
@AaronDigulla you seem to have been the first to suggest updating surefire. Why don't you post your comment as an answer so that NeplatnyUdaj can accept it? This would give you a little reputation increase and make the solution much more visible.Haem
Nicola: I was about to suggest that too :)Diaz
M
12

it is not -DskipTests=true it is just -DskipTests considering you are using surfire version 2.3

so you run it as

mvn install -DskipTests
Morrill answered 7/11, 2013 at 15:20 Comment(3)
I do this all the time. But my surefire version is 2.5.. I just tried it with 2.3 surefire version and it is ignoring the skipTests. Can you tried it with 2.5?Morrill
Yes. That was the problem. It perfectly explains the behavior I observedDiaz
both can be used -DskipTests being just more convenientBenton
M
3

I'm not sure why the correct answer hasn't been posted yet. In older versions of SureFire the flag to compile tests but not run them is -Dmaven.test.skip.exec.

Misbecome answered 14/3, 2016 at 16:50 Comment(1)
This is the answer.Arresting
B
3

It's old question, but maybe my case help for someone.

So, -DskipTests/-DskipTests=true/-DskipITs/etc didn't work, and I didn't know why. I had <profiles> in my parent pom.xml and problem was in configuration of surefire/failsafe.

<profiles>
        <profile>
            <id>unit-test</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <id>integration-test</id>
            <properties>
                <skip.unit-tests>true</skip.unit-tests>
                <skip.integration-tests>false</skip.integration-tests>
                <skip.end-to-end-tests>true</skip.end-to-end-tests>
            </properties>
        </profile>
...
</profiles>

In plugins configuration I used like below:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>${maven-surefire-plugin.version}</version>
    <configuration>
        <skipTests>${skip.unit-tests}</skipTests>
    </configuration>
...
</plugin>

This command didn't work:

mvn clean install -DskipTests -DskipITs

This works:

mvn clean install -Dskip.unit-tests=true -Dskip.integration-tests=true -Dskip.end-to-end-tests=true
Barrel answered 26/11, 2019 at 8:29 Comment(0)
G
0

Try the following configuration for your surefire plugin

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>${version.surefire.plugin}</version>
    <configuration>
        <skip>true</skip>
    </configuration>
</plugin>
Goya answered 7/11, 2013 at 14:45 Comment(3)
Exactly. I want them to be executed on the build server and when someone checkout the code. I just need to disable them in my project configurationDiaz
You can create distinct Maven build profiles for distinct scenarios in which you'd need either to skip or execute the testsGoya
This seems like an overkill for such simple thing.Diaz

© 2022 - 2024 — McMap. All rights reserved.