34

How come that Maven is skipping all of my tests by default?I have a pom.xml with few profiles and I am not able to run my tests through neither of them. One of my profiles looks like

<profile>
        <id>jsf-test</id>
        <dependencies>
            <dependency>
                <groupId>org.jboss.as</groupId>
                <artifactId>jboss-as-arquillian-container-remote</artifactId>
                <version>${jboss.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>com.jsf.tests</groupId>
                <artifactId>jsf-app</artifactId>
                <version>${jsf-app.version}</version>
                <type>war</type>
            </dependency>
        </dependencies>
        <build>
            <plugins>                
                <plugin>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>2.6</version>
                    <executions>
                        <execution>
                            <id>copy-jsf-app</id>
                            <phase>validate</phase>
                            <goals>
                                <goal>copy</goal>
                            </goals>
                            <configuration>
                                <artifactItems>
                                    <artifactItem>
                                        <groupId>com.jsf.tests</groupId>
                                        <artifactId>jsf-app</artifactId>
                                        <version>${jsf-app.version}</version>
                                        <type>war</type>
                                        <destFileName>jsfapp.war</destFileName>
                                        <outputDirectory>target</outputDirectory>
                                    </artifactItem>
                                </artifactItems>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>${maven-surefire.version}</version>
                    <configuration>
                        <skipTests>false</skipTests> <!-- desperate trial -->
                        <properties>
                            <property>
                                <name>listener</name>
                                <value>${testng.listeners}</value>
                            </property>
                        </properties>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>

If I run mvn verify -Pjsf-test then the project is compiled, jsf-app artifact is correctly copied into target directory and tests are skipped. mvn verify -Dtest=TestCalculator has the same result. I am using Arquillian and TestNG to perform the actual tests but I am not sure if it matters for this question.

EDIT

Running in debug will give (the relevant part)

[DEBUG]   (s) reportFormat = brief
[DEBUG]   (s) reportsDirectory = /home/pmensik/Work/workspace/epp-test/cdi-arquillian-    test/target/surefire-reports
[DEBUG]   (f) reuseForks = true
[DEBUG]   (s) runOrder = filesystem
[DEBUG]   (s) skip = true
[DEBUG]   (s) skipTests = false
[DEBUG]   (s) systemPropertyVariables = {jsfPortlet=true}
[DEBUG]   (s) testClassesDirectory = /home/pmensik/Work/workspace/epp-test/cdi-arquillian-test/target/test-classes
[DEBUG]   (s) testFailureIgnore = false
[DEBUG]   (s) testNGArtifactName = org.testng:testng
[DEBUG]   (s) testSourceDirectory = /home/pmensik/Work/workspace/epp-test    /cdi-arquillian-test/src/test/java
[DEBUG]   (s) trimStackTrace = true
[DEBUG]   (s) useFile = true
[DEBUG]   (s) useManifestOnlyJar = true
[DEBUG]   (s) useSystemClassLoader = true
[DEBUG]   (s) useUnlimitedThreads = false
[DEBUG]   (s) workingDirectory = /home/pmensik/Work/workspace/epp-test/cdi-arquillian-test
[DEBUG]   (s) project = MavenProject: org.jboss.gatein.test:cdi-portlet-test:6.1-ER01 @ /home/pmensik/Work/workspace/epp-test/cdi-arquillian-test/pom.xml
[DEBUG]   (s) session = org.apache.maven.execution.MavenSession@3c3483ec
[DEBUG] -- end configuration --
[INFO] Tests are skipped.

My simplest test looks like this

public class Test {

    @Drone
    protected WebDriver driver;

    @Deployment(testable = false)
    public static WebArchive createTestArchive() {
        return ShrinkWrap.createFromZipFile(WebArchive.class, new File("target/CDIPortlet.war"));
    }

    @Test
    public void testCase{
        //...
    }

}
Petr Mensik
  • 26,874
  • 17
  • 90
  • 115
  • Are you sure you aren't running with `-DskipTests` somehow? What does `mvn clean verify` or `mvn clean install` do? – vikingsteve Jul 09 '13 at 12:51
  • 1
    Try running with `-X` to get debug output, then look at the surefire plugin's configuration. I would also suspect a plugin inheritance problem. Is the surefire plugin configured in a parent POM? – user944849 Jul 09 '13 at 14:00
  • and where are your tests defined? – John Ament Jul 09 '13 at 21:10
  • @vikingsteve - exactly the same result – Petr Mensik Jul 10 '13 at 13:06
  • @user944849 - see my edit. And yes, I am inheriting from really simple POM, there is just a definition of Surefire plugin in `pluginManagement` with skipped configuration, nothing else – Petr Mensik Jul 10 '13 at 13:07
  • @PetrMensik Ok, does the default configuration for `maven-surefire-plugin` have include or exclude patterns? Look through all the parent poms. If so, adding ` none ` in your profile `` might help. – vikingsteve Jul 10 '13 at 13:15

1 Answers1

41

The debug output shows this:

[DEBUG]   (s) skip = true

which not only skips running the tests, it will also skip compiling them. Check the parent POM (directly referenced by this POM, also any corporate POMs or super POMs introduced by Arquillian) to see where this flag is being set, if you're curious.

The fix is to add

<skip>false</skip>

to the surefire plugin config in this module, or add

-Dmaven.test.skip=false

to your command line.

Reference

user944849
  • 14,524
  • 2
  • 61
  • 83
  • 8
    true -- tests are compiled, but not runned. – Nikita Bosik Jun 28 '16 at 14:44
  • 4
    true -- tests are not even compiled. – Nikita Bosik Jun 28 '16 at 14:44
  • 1
    This works for me, but I have no idea why it works. Since none of my pom.xml files are setting this to false. – C.J. Oct 01 '18 at 19:52
  • I think adding `-Dmaven.test.skip=false` to command while there's `true` in the POM is ignored. Just a note. It didn't work for me anyway until I changed it to `false` – Nom1fan Oct 03 '21 at 12:40
  • 1
    @Nom1fan - correct. If the value has been hardcoded like that, the value in the property can no longer be used. If you have access to the POM, removing the hardcoding and using the properties is the way to go. – user944849 Oct 04 '21 at 22:03