Unit tests depending on manifest
How can I make sure the manifest file gets generated before the unit tests are executed? My use case is: - a Java code base, under src/main/java - unit tests under src/test/java - pom.xml specifies packaging jar - JUnit 4.8.1 is a dependency - Java code uses a property from the manifest to determine meta data (library version) - Maven automatically generates the correct manifest file - the unit tests attempt to validate that Java code, but the manifest file is not generated, it's only part of the JAR Any suggestions? Note that I'm new to Maven, but I used shell scripts and Ant build files a lot. FYI, here is the actual code and POM: http://github.com/znerd/logdoc/blob/master/base/src/main/java/org/znerd/logdoc/Library.java http://github.com/znerd/logdoc/blob/master/base/src/test/java/org/znerd/logdoc/LibraryTest.java http://github.com/znerd/logdoc/blob/master/base/pom.xml Cheers, Ernst de Haan
Re: Unit tests depending on manifest
How can I make sure the manifest file gets generated before the unit tests are executed? - the unit tests attempt to validate that Java code, but the manifest file is not generated, it's only part of the JAR Instead of running that test in this module's build, add another module alongside it that depends on this artifact, and run this test there. It will bring in the jar which, as you said, has the manifest in it. You will need a parent pom as well over both modules, and always build your project from the parent. Wayne - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org
Re: Unit tests depending on manifest
Wayne, How can I make sure the manifest file gets generated before the unit tests are executed? - the unit tests attempt to validate that Java code, but the manifest file is not generated, it's only part of the JAR Instead of running that test in this module's build, add another module alongside it that depends on this artifact, and run this test there. It will bring in the jar which, as you said, has the manifest in it. You will need a parent pom as well over both modules, and always build your project from the parent. Brilliant! Thank you for he advice, this is indeed what I will do, I'll add another module. Note that I'm new to Maven, I typically use Ant (and an occasional shell script). Although this approach seems the most logical, given the fixed model Maven enforces, it does give the impression that it makes me go against the basic principle Maven appears to herald, which is that one (sub-)project is a contained entity, self-sufficient, including all resources required to build and test the main codebase. What I find in (a few days) practice, is that I need to add an extra module in multiple cases: - to test code that depends on the manifest - to test plugin code, since that needs to be compiled before the plugin can be accessed by Maven /me ponders But hey, thanks for giving me an easy way out that is very acceptable (at the least). Cheers, Ernst - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org
Re: Unit tests depending on manifest
On 5/24/10 1:04 PM, Ernst de Haan wrote: Wayne, How can I make sure the manifest file gets generated before the unit tests are executed? - the unit tests attempt to validate that Java code, but the manifest file is not generated, it's only part of the JAR Instead of running that test in this module's build, add another module alongside it that depends on this artifact, and run this test there. It will bring in the jar which, as you said, has the manifest in it. You will need a parent pom as well over both modules, and always build your project from the parent. Brilliant! Thank you for he advice, this is indeed what I will do, I'll add another module. Note that I'm new to Maven, I typically use Ant (and an occasional shell script). Although this approach seems the most logical, given the fixed model Maven enforces, it does give the impression that it makes me go against the basic principle Maven appears to herald, which is that one (sub-)project is a contained entity, self-sufficient, including all resources required to build and test the main codebase. What I find in (a few days) practice, is that I need to add an extra module in multiple cases: - to test code that depends on the manifest - to test plugin code, since that needs to be compiled before the plugin can be accessed by Maven As an alternative to creating a separate module, you may be able to use the integration-test phase. This happens after your project is packaged, but before it is installed. Justin /me ponders But hey, thanks for giving me an easy way out that is very acceptable (at the least). Cheers, Ernst - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org
Re: Unit tests depending on manifest
Instead of running that test in this module's build, add another module alongside it that depends on this artifact, and run this test there. It will bring in the jar which, as you said, has the manifest in it. You will need a parent pom as well over both modules, and always build your project from the parent. Another question: How do I make the test-module use the *JAR* instead of just the classes? Here's what I have done: - create a separate base-test module with a separate POM that depends on the base module - move all unit tests to the base-test module - run mvn clean and then mvn test What happens is: - the classes get compiled for the base module (but no JAR is generated) - the unit tests in base-test are executed, using the classes (not the JAR) - the tests (obviously) fail So I try forcing the JAR to be created, using mvn install, which works. But still the unit tests fail, because they appear to use the classes instead of the JAR... Any hints to this next piece of the puzzle? Ernst - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org
Re: Unit tests depending on manifest
run your tests after the package phase, i.e. plugin groupIdorg.apache.maven.plugins/groupId artifactIdmaven-surefire-plugin/artifactId version2.5/version executions execution phaseintegration-test/phase goals goaltest/goal /goals configuration testSourceDirectory${basedir}/src/test2/java/testSourceDirectory /configuration /execution /executions /plugin I have not tested it but it should work regards, Kristian On Mon, May 24, 2010 at 11:23 PM, Ernst de Haan er...@ernstdehaan.com wrote: Instead of running that test in this module's build, add another module alongside it that depends on this artifact, and run this test there. It will bring in the jar which, as you said, has the manifest in it. You will need a parent pom as well over both modules, and always build your project from the parent. Another question: How do I make the test-module use the *JAR* instead of just the classes? Here's what I have done: - create a separate base-test module with a separate POM that depends on the base module - move all unit tests to the base-test module - run mvn clean and then mvn test What happens is: - the classes get compiled for the base module (but no JAR is generated) - the unit tests in base-test are executed, using the classes (not the JAR) - the tests (obviously) fail So I try forcing the JAR to be created, using mvn install, which works. But still the unit tests fail, because they appear to use the classes instead of the JAR... Any hints to this next piece of the puzzle? Ernst - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org -- Kristian Meier + Saumya Sharma + Sanuka Meier Vadakkethu House, Edayanmula West PO - 689532, Pathanamthitta District, Kerala, INDIA tel: +91 468 2319577 protect your privacy while searching the net: www.ixquick.com _=_ q(-_-)p '_) (_` /__/ \ _(_ / )_ (__\_\_|_/__) - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org
Re: Unit tests depending on manifest
better off using maven-failsafe-plugin for that On 24 May 2010 20:00, kristian m.krist...@web.de wrote: run your tests after the package phase, i.e. plugin groupIdorg.apache.maven.plugins/groupId artifactIdmaven-surefire-plugin/artifactId version2.5/version executions execution phaseintegration-test/phase goals goaltest/goal /goals configuration testSourceDirectory${basedir}/src/test2/java/testSourceDirectory /configuration /execution /executions /plugin I have not tested it but it should work regards, Kristian On Mon, May 24, 2010 at 11:23 PM, Ernst de Haan er...@ernstdehaan.com wrote: Instead of running that test in this module's build, add another module alongside it that depends on this artifact, and run this test there. It will bring in the jar which, as you said, has the manifest in it. You will need a parent pom as well over both modules, and always build your project from the parent. Another question: How do I make the test-module use the *JAR* instead of just the classes? Here's what I have done: - create a separate base-test module with a separate POM that depends on the base module - move all unit tests to the base-test module - run mvn clean and then mvn test What happens is: - the classes get compiled for the base module (but no JAR is generated) - the unit tests in base-test are executed, using the classes (not the JAR) - the tests (obviously) fail So I try forcing the JAR to be created, using mvn install, which works. But still the unit tests fail, because they appear to use the classes instead of the JAR... Any hints to this next piece of the puzzle? Ernst - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org -- Kristian Meier + Saumya Sharma + Sanuka Meier Vadakkethu House, Edayanmula West PO - 689532, Pathanamthitta District, Kerala, INDIA tel: +91 468 2319577 protect your privacy while searching the net: www.ixquick.com _=_ q(-_-)p '_) (_` /__/ \ _(_ / )_ (__\_\_|_/__) - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org
Re: Unit tests depending on manifest
better off using maven-failsafe-plugin for that Stephen, thanks for the pointer. Will give that a try. I was getting nowhere (yet) with all sorts of variants of the snippet Kristian sent. An alternative route is welcomed :) /me struggles on... Cheers, Ernst - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org
Re: Unit tests depending on manifest
better off using maven-failsafe-plugin for that How do I know for sure verify is using my JAR? I tried the failsafe plugin, but it still /appears/ to be using the classes, not the JAR, even from my new LibraryIT.java integration test. It does execute, but the test fails. Here's my POM for the base module: http://github.com/znerd/logdoc/blob/master/base/pom.xml And here's the one for the base-test module: http://github.com/znerd/logdoc/blob/master/base-test/pom.xml Can I debug the failsafe plugin? Ernst - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org
Re: Unit tests depending on manifest
failsafe is surefire just bound to theintegration-test phase. changing surefire to be bound to the integration-test phase can cause subtle issues as you use more plugins. we should be able to convince failsafe to use the jars if they are available... can you file an enhancement request in JIRA? -Stephen On 24 May 2010 22:54, Ernst de Haan er...@ernstdehaan.com wrote: better off using maven-failsafe-plugin for that How do I know for sure verify is using my JAR? I tried the failsafe plugin, but it still /appears/ to be using the classes, not the JAR, even from my new LibraryIT.java integration test. It does execute, but the test fails. Here's my POM for the base module: http://github.com/znerd/logdoc/blob/master/base/pom.xml And here's the one for the base-test module: http://github.com/znerd/logdoc/blob/master/base-test/pom.xml Can I debug the failsafe plugin? Ernst - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org
Re: Unit tests depending on manifest
On 5/24/10 5:54 PM, Ernst de Haan wrote: better off using maven-failsafe-plugin for that How do I know for sure verify is using my JAR? You could inspect the classloader. Something like: URLClassLoader ucl = (URLClassLoader) getClass().getClassLoader(); System.out.println(Arrays.asList(ucl.getURLs())); I tried the failsafe plugin, but it still /appears/ to be using the classes, not the JAR, even from my new LibraryIT.java integration test. It does execute, but the test fails. Here's my POM for the base module: http://github.com/znerd/logdoc/blob/master/base/pom.xml And here's the one for the base-test module: http://github.com/znerd/logdoc/blob/master/base-test/pom.xml Can I debug the failsafe plugin? Do you want to debug the plugin or the test? If the former, use mvnDebug. If the latter, invoke Maven with -Dmaven.failsafe.debug=true HTH, Justin Ernst - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org