How do I make the manifest available during a Maven/Surefire unittest run "mvn test" ?
Posted
by Ernst de Haan
on Stack Overflow
See other posts from Stack Overflow
or by Ernst de Haan
Published on 2010-05-26T19:43:01Z
Indexed on
2010/05/26
21:11 UTC
Read the original article
Hit count: 304
How do I make the manifest available during a Maven/Surefire unittest run "mvn test" ?
I have an open-source project that I am converting from Ant to Maven, including its unit tests. Here's the project source repository with the Maven project: http://github.com/znerd/logdoc
My question pertains to the primary module, called "base". This module has a unit test that tests the behaviour of the static method getVersion()
in the class org.znerd.logdoc.Library
. This method returns:
Library.class.getPackage().getImplementationVersion()
The getImplementationVersion()
method returns a value of a setting in the manifest file. So far, so good. I have tested this in the past and it works well, as long as the manifest is indeed available on the classpath at the path META-INF/MANIFEST.MF
(either on the file system or inside a JAR file).
Now my challenge is that the manifest file is not available when I run the unit tests:
mvn test
Surefire runs the unit tests, but my unit test fails with a mesage indicating that Library.getVersion()
returned null
.
When I want to check the JAR, I find that it has not even been generated. Maven/Surefire runs the unit tests against the classes, before the resources are added to the classpath.
So can I either run the unit tests against the JAR (implicitly requiring the JAR to be generated first) or can I make sure the resources (including the manifest file) are generated/copied under target/classes
before the unit tests are run?
Note that I use Maven 2.2.0, Java 1.6.0_17 on Mac OS X 10.6.2, with JUnit 4.8.1.
© Stack Overflow or respective owner