You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Linghua Wang <mm...@gmail.com> on 2008/12/12 08:43:16 UTC
How to add test classes into jar?
Hi,
I want to try maven-surefire-plugin. There are two projects A and B, A
depends on B, and some test classes in A depend on that of in B. Both A and
B's POM has the following snippet.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
Steps:
1. CD to directory of project B, execute mvn compiler:testCompile and mvn
install
2. CD to directory of project A, execute mvn compiler:testComplie, maven
always complain that some test classes can not be found in project B.
Question:
Simply, we can resolve it by adding test classes into jar (default
packaging). Somebody could tell me how? Or any other suggestions would be
appriciated.
Thanks.
Linghua.
Re: How to add test classes into jar?
Posted by Linghua Wang <mm...@gmail.com>.
Thanks! I found out it based on your comments. Followings is the details I
have done.
1. Add <build> snippet into pom.xml of project B. After the execution of
mvn:install, then .../src/main/java/ and /src/test/java were packaged
respectively and installed on my local repository.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - -
<project>
<...>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<...>
</project>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - -
2. Add this dependency into project A.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - -
<!--The test myapp-hut-->
<dependency>
<groupId>com.mycompany.hut</groupId>
<artifactId>myapp-hut</artifactId>
<version>1.0-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - -
3. Then mvn test, things go smoothly.
Thank again.
2008/12/12 Wayne Fay <wa...@gmail.com>
> > Simply, we can resolve it by adding test classes into jar (default
> > packaging). Somebody could tell me how? Or any other suggestions would be
> > appriciated.
>
> You want to create and use a test-jar artifact. This is documented on
> the Maven site and in various other places, eg:
> http://stackoverflow.com/questions/174560/sharing-test-code-in-maven
>
> Wayne
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
Re: How to add test classes into jar?
Posted by Wayne Fay <wa...@gmail.com>.
> Simply, we can resolve it by adding test classes into jar (default
> packaging). Somebody could tell me how? Or any other suggestions would be
> appriciated.
You want to create and use a test-jar artifact. This is documented on
the Maven site and in various other places, eg:
http://stackoverflow.com/questions/174560/sharing-test-code-in-maven
Wayne
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: How to add test classes into jar?
Posted by Linghua Wang <mm...@gmail.com>.
So specific as Wayne said. BTW, now in JUnit4, test class don't have to
extends TestCase because of new design based on the JDK5's new
feature(annotation), so test class have a new chance to extends another
class.
Regards.
Linghua
2008/12/14 Wayne Fay <wa...@gmail.com>
> > You have some test classes that extends something else than TestCase and
> you
> > want to share these intermediate classes between projects ?
>
> Or perhaps he has some utility classes that are used only by his
> tests, or he wants to re-use some test classes for some other reasons.
> There are many good reasons to make the test-jar artifact and share
> test classes amongst multiple projects.
>
> Wayne
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
Re: How to add test classes into jar?
Posted by Wayne Fay <wa...@gmail.com>.
> You have some test classes that extends something else than TestCase and you
> want to share these intermediate classes between projects ?
Or perhaps he has some utility classes that are used only by his
tests, or he wants to re-use some test classes for some other reasons.
There are many good reasons to make the test-jar artifact and share
test classes amongst multiple projects.
Wayne
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: How to add test classes into jar?
Posted by Anders Kristian Andersen <an...@gmail.com>.
Hi
I'm not 100 pct sure I get this right.
You have some test classes that extends something else than TestCase
and you want to share these intermediate classes between projects ?
If this is the case.
I re comment to re-engineer your test cases so they only extends
TestCase
/Anders
On 12/12/2008, at 08.43, Linghua Wang wrote:
> Hi,
>
> I want to try maven-surefire-plugin. There are two projects A and B, A
> depends on B, and some test classes in A depend on that of in B.
> Both A and
> B's POM has the following snippet.
>
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> - - - -
> - - - -
> <plugin>
> <groupId>org.apache.maven.plugins</groupId>
> <artifactId>maven-surefire-plugin</artifactId>
> <configuration>
> <skip>false</skip>
> </configuration>
> </plugin>
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> - - - -
> - - - -
>
> Steps:
>
> 1. CD to directory of project B, execute mvn compiler:testCompile
> and mvn
> install
> 2. CD to directory of project A, execute mvn compiler:testComplie,
> maven
> always complain that some test classes can not be found in project B.
>
> Question:
>
> Simply, we can resolve it by adding test classes into jar (default
> packaging). Somebody could tell me how? Or any other suggestions
> would be
> appriciated.
>
> Thanks.
> Linghua.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org