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

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top