Invoke tests classes from another Maven project
I have 2 maven projects, one for the sources: ProjSource, containing one class: Class-A.. and another one: ProjTest containing a test class for Class-A named Class-A-Test . I开发者_运维技巧 want my test class to be run when I call an mvn:install on ProjSource.
What is the simplest way to perform such thing? note that my experience with unit tests is very basic.. I don't know how to tell Maven that Class-A-Test is designed to test Class-A..
I followed the steps described using the maven-jar-plugin with test-jar Goal here and defining the resulting *******-tests.jar as a dependency for ProjSource with:
<type>test-jar</type>
<scope>test</scope>
but when i run an mvn:install, the output says that: "There are no tests to run". Have I missed something ?
Any help is highly appreciable, and many thanks in advance !
Regards,
don't do it that way. The maven way to do it is to have standard sources under
src/main/java
and test sources undersrc/test/java
. By default, standard sources will be added to the resulting JAR, while tests in the test source dir will be executed automatically. This is well-tested behavior, why change it? If you want / need a test jar, call jar:test-jar in the pom.xml of this project and use the buildhelper plugin to attach the resulting artifact for deploy. That way you can keep the standard project layout and still have a test jar.if you insist on doing it, you would have to do it the other way around. The test project would have to have a dependency to the main project (you can't test what you don't know). I would suggest to just put the test code in
src/test/java
in the test project, then maven's magic can work the default way. Insert bold text from above here, too.
But the reason why the maven lifecycle was defined as it was is that failed tests are supposed to fail the build. There is no point in building a library that doesn't do what it's supposed to do.
精彩评论