Question

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());

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top