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.
“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.
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.
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.
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.
As commented by Dave, if you are using pom
packaging, it only executes the following lifecycle goals. Refer to this related maven documentation.
If you need it to run any other goal, you would need to explicitly specify it. For instance,
mvn clean compiler:testCompile surefire:test
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With