Pergunta

I'm having some issues running my unit tests when my pom is set to packaging type "pom". At first, it was saying no goals needed for this project, so I added the maven-surefire-plugin to my pom.xml to bind the test phase to the maven-surefire-plugin test goal.

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.9</version>
            <executions>
                <execution>
                    <phase>test</phase>
                    <goals>
                        <goal>test</goal>
                    </goals>
                </execution>
            </executions>
        </plugin> 

Now the surefire plugin is getting executed, but it says there are no tests to run. If I change the packaging type to jar and run mvn test then it picks up my tests files.

When I run mvn test -X it says "testSourceDirectory = C:\dev\dsl\src\test\java", which is the correct location. Is the test location different for the packaging type "pom" than for "jar"? I tried adding

            <configuration>
                <testSourceDirectory>src/test/java</testSourceDirectory>
            </configuration>

to the surefire plugin, but it didn't help at all.

Foi útil?

Solução

As commented by Dave, if you are using pom packaging, it only executes the following lifecycle goals. Refer to this related maven documentation.

  • package
  • install
  • deploy

If you need it to run any other goal, you would need to explicitly specify it. For instance,

mvn clean compiler:testCompile surefire:test
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top