Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven is automatically skipping tests

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{         //...     }  } 
like image 675
Petr Mensik Avatar asked Jul 09 '13 12:07

Petr Mensik


People also ask

Why is Maven skipping a test?

However, there are some situations where it could be useful — maybe when we're developing new code and want to run intermediate builds in which the tests are not passing or compiling. In these kinds of situations only, we might skip the tests to avoid the overhead of compiling and running them.

Why Maven surefire plugin tests are skipped?

When the Surefire plugin reaches the test goal, it will skip the unit tests if the maven. test. skip properties is set to true . Another way to configure Maven to skip unit tests is to add this configuration to your project's pom.

How do I skip test cases in Maven?

To skip running the tests for a particular project, set the skipTests property to true. You can also skip the tests via the command line by executing the following command: mvn install -DskipTests.

What is DskipTests in Maven?

Maven docs: -DskipTests compiles the tests, but skips running them. -Dmaven.test.skip=true skips compiling the tests and does not run them. Also this one might be important. maven.test.skip is honored by Surefire, Failsafe and the Compiler Plugin.


1 Answers

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

like image 133
user944849 Avatar answered Nov 06 '22 02:11

user944849