1

Is it possible to get Package.getImplementationVersion() method available for junits? I am using maven and eclipse. I tried to execute mvn war:manifest to create the manifest file, so I could verify that the Implementation Version is not null.

Currently here is my test unit which is failing:

assertNotNull(Version.class.getPackage().getImplementationVersion());

Steve
  • 1,145
  • 1
  • 11
  • 25

1 Answers1

1

If you want to verify if the MANIFEST file of the war contains certain fields, a standard unit-test is too early, since the war hasn't been packaged yet. Instead I would write a junit-test for the maven-failsafe-plugin. Now your testclass has to end with IT instead of Test so it is recognized as an integration test by the plugin. Next, find the war-file in the target-directory and read it as a JarFile, so you have direct access to the Manifest. The rest shouldn't be too hard.

Robert Scholte
  • 11,889
  • 2
  • 35
  • 44
  • Sorry for the delay but I did what you suggested and it worked! Thank you. Also I found this as a duplicate: http://stackoverflow.com/questions/2916209/how-do-i-make-the-manifest-available-during-a-maven-surefire-unittest-run-mvn-t – Steve Jul 19 '13 at 17:22