Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running tests with maven packaging type "pom"

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.

like image 405
user977208 Avatar asked Jan 12 '12 22:01

user977208


People also ask

What is packaging type pom in Maven?

“pom” packaging is nothing but the container, which contains other packages/modules like jar, war, and ear. if you perform any operation on outer package/container like mvn clean compile install. then inner packages/modules also get clean compile install. no need to perform a separate operation for each package/module.

What is the use of packaging packaging in Maven?

The packaging type is an important aspect of any Maven project. It specifies the type of artifact the project produces. Generally, a build produces a jar, war, pom, or other executable. Maven offers many default packaging types and also provides the flexibility to define a custom one.

What is valid packaging type for Maven?

Some of the valid packaging values are jar , war , ear and pom . If no packaging value has been specified, it will default to jar . Each packaging contains a list of goals to bind to a particular phase.

Is Maven used to run tests?

The Maven surefire plugin is easy to use. It has only one goal: test. Therefore, with the default configuration, we can execute all tests in the project by the command mvn test. Sometimes, we may want to execute one single test class or even one single test method.


1 Answers

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
like image 120
Raghuram Avatar answered Sep 20 '22 05:09

Raghuram