|
View:
New views
7 Messages
—
Rating Filter:
Alert me
|
|
|
maven2 with Junit 4 ignores @Test annotationsI am trying to use maven with Junit4 test cases. Eclipse runs these
tests just fine but maven doesn't recognize any of these tests. Here is the code import org.junit.Test; import static org.junit.Assert.*; public class AdditionTest { private int x = 1; private int y = 1; @Test public void addition() { int z = x + y; assertEquals(2, z); } } POM file <dependencies> <dependency> <groupId>org.junit</groupId> <artifactId>junit</artifactId> <version>4.4</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.4.3</version> <configuration> <includes> <include>**/*Test.java</include> </includes> </configuration> </plugin> </plugins> </build> Am I doing anything wrong here? Or anything else needs to be done? Thanks Sankar |
|
|
Re: maven2 with Junit 4 ignores @Test annotationsSankar,
Sorry for the late response. Did you ever find an answer? David Saff On Thu, May 29, 2008 at 5:47 PM, Sankar <vsnk70@...> wrote: > I am trying to use maven with Junit4 test cases. Eclipse runs these > tests just fine but maven doesn't recognize any of these tests. > > Here is the code > import org.junit.Test; > import static org.junit.Assert.*; > > public class AdditionTest { > private int x = 1; > private int y = 1; > > @Test > public void addition() { > int z = x + y; > assertEquals(2, z); > } > } > > POM file > <dependencies> > <dependency> > <groupId>org.junit</groupId> > <artifactId>junit</artifactId> > <version>4.4</version> > </dependency> > </dependencies> > > <build> > <plugins> > <plugin> > <groupId>org.apache.maven.plugins</groupId> > <artifactId>maven-compiler-plugin</artifactId> > <configuration> > <source>1.5</source> > <target>1.5</target> > </configuration> > </plugin> > <plugin> > > <groupId>org.apache.maven.plugins</groupId> > > <artifactId>maven-surefire-plugin</artifactId> > <version>2.4.3</version> > <configuration> > <includes> > > <include>**/*Test.java</include> > </includes> > </configuration> > </plugin> > </plugins> > </build> > > > Am I doing anything wrong here? Or anything else needs to be done? > > Thanks > Sankar > > > ------------------------------------ > > Yahoo! Groups Links > > > > |
|
|
Re: maven2 with Junit 4 ignores @Test annotationsAre your tests in the src/test/java folder?
On Thu, May 29, 2008 at 11:47 PM, Sankar <vsnk70@...> wrote: > I am trying to use maven with Junit4 test cases. Eclipse runs these > tests just fine but maven doesn't recognize any of these tests. > > Here is the code > import org.junit.Test; > import static org.junit.Assert.*; > > public class AdditionTest { > private int x = 1; > private int y = 1; > > @Test > public void addition() { > int z = x + y; > assertEquals(2, z); > } > } > > POM file > <dependencies> > <dependency> > <groupId>org.junit</groupId> > <artifactId>junit</artifactId> > <version>4.4</version> > </dependency> > </dependencies> > > <build> > <plugins> > <plugin> > <groupId>org.apache.maven.plugins</groupId> > <artifactId>maven-compiler-plugin</artifactId> > <configuration> > <source>1.5</source> > <target>1.5</target> > </configuration> > </plugin> > <plugin> > > <groupId>org.apache.maven.plugins</groupId> > > <artifactId>maven-surefire-plugin</artifactId> > <version>2.4.3</version> > <configuration> > <includes> > > <include>**/*Test.java</include> > </includes> > </configuration> > </plugin> > </plugins> > </build> > > Am I doing anything wrong here? Or anything else needs to be done? > > Thanks > Sankar > > > -- ----------------------------------------------------- Joakim Ohlrogge Agical AB VÀsterlÄnggatan 79, 2 tr 111 29 Stockholm, SWEDEN Mobile: +46-708-754004 Blog: johlrogge.wordpress.com E-mail: joakim.ohlrogge@... [Non-text portions of this message have been removed] |
|
|
Re: maven2 with Junit 4 ignores @Test annotationsI seem to be having the same problem. I will try to find a solution online, but I was hoping someone might be able to shed some light on the situation.
$mvn -version Apache Maven 2.2.0 (r788681; 2009-06-26 06:04:01-0700) Java version: 1.6.0_15 Java home: /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home Default locale: en_US, platform encoding: MacRoman OS name: "mac os x" version: "10.6.1" arch: "x86_64" Family: "mac" Junit version: 4.4
|
|
|
Re: maven2 with Junit 4 ignores @Test annotationsI would try the following things:
1. make sure that your project respects the maven structure (sources in src/main/java, tests in src/test/java) 2. remove the settings for maven-surefire-plugin. I personally never needed to specify them. It worked out of the box 3. run maven with -e switch, perhaps you will get some hints on what exactly is happening. Oh, and btw: what exactly is the outcome? Is maven throwing some error? Is it not running the tests at all, ignoring them? Bogdan Mocanu --- In junit@..., iGeek <javageek@...> wrote: > > > I seem to be having the same problem. I will try to find a solution online, > but I was hoping someone might be able to shed some light on the situation. > > $mvn -version > Apache Maven 2.2.0 (r788681; 2009-06-26 06:04:01-0700) > Java version: 1.6.0_15 > Java home: /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home > Default locale: en_US, platform encoding: MacRoman > OS name: "mac os x" version: "10.6.1" arch: "x86_64" Family: "mac" > > Junit version: 4.4 > > > David Saff wrote: > > > > Sankar, > > > > Sorry for the late response. Did you ever find an answer? > > > > David Saff > > > > On Thu, May 29, 2008 at 5:47 PM, Sankar <vsnk70@...> wrote: > >> I am trying to use maven with Junit4 test cases. Eclipse runs these > >> tests just fine but maven doesn't recognize any of these tests. > >> > >> Here is the code > >> import org.junit.Test; > >> import static org.junit.Assert.*; > >> > >> public class AdditionTest { > >> private int x = 1; > >> private int y = 1; > >> > >> @Test > >> public void addition() { > >> int z = x + y; > >> assertEquals(2, z); > >> } > >> } > >> > >> POM file > >> <dependencies> > >> <dependency> > >> <groupId>org.junit</groupId> > >> <artifactId>junit</artifactId> > >> <version>4.4</version> > >> </dependency> > >> </dependencies> > >> > >> <build> > >> <plugins> > >> <plugin> > >> <groupId>org.apache.maven.plugins</groupId> > >> <artifactId>maven-compiler-plugin</artifactId> > >> <configuration> > >> <source>1.5</source> > >> <target>1.5</target> > >> </configuration> > >> </plugin> > >> <plugin> > >> > >> <groupId>org.apache.maven.plugins</groupId> > >> > >> <artifactId>maven-surefire-plugin</artifactId> > >> <version>2.4.3</version> > >> <configuration> > >> <includes> > >> > >> <include>**/*Test.java</include> > >> </includes> > >> </configuration> > >> </plugin> > >> </plugins> > >> </build> > >> > >> > >> Am I doing anything wrong here? Or anything else needs to be done? > >> > >> Thanks > >> Sankar > >> > >> > >> ------------------------------------ > >> > >> Yahoo! Groups Links > >> > >> > >> > >> > > > > > > -- > View this message in context: http://www.nabble.com/maven2-with-Junit-4-ignores-%40Test-annotations-tp17548499p26102430.html > Sent from the JUnit - User mailing list archive at Nabble.com. > |
|
|
Re: maven2 with Junit 4 ignores @Test annotationsI've head this problem before and if I'm not totally mistaken it's one of the followin
A) Your dependencies or transitive dependencies is picking up junit 3.8.X somehere. Run mvn dependency:tree and study the output, and possibly add some exclusions for transitive dependencies. B) Your project language level is .1.3/1.4 I don't remember exactly which one it was, but I'm fairly certain it was one of them --- In junit@..., iGeek <javageek@...> wrote: > > > I seem to be having the same problem. I will try to find a solution online, > but I was hoping someone might be able to shed some light on the situation. > > $mvn -version > Apache Maven 2.2.0 (r788681; 2009-06-26 06:04:01-0700) > Java version: 1.6.0_15 > Java home: /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home > Default locale: en_US, platform encoding: MacRoman > OS name: "mac os x" version: "10.6.1" arch: "x86_64" Family: "mac" > > Junit version: 4.4 > > > David Saff wrote: > > > > Sankar, > > > > Sorry for the late response. Did you ever find an answer? > > > > David Saff > > > > On Thu, May 29, 2008 at 5:47 PM, Sankar <vsnk70@...> wrote: > >> I am trying to use maven with Junit4 test cases. Eclipse runs these > >> tests just fine but maven doesn't recognize any of these tests. > >> > >> Here is the code > >> import org.junit.Test; > >> import static org.junit.Assert.*; > >> > >> public class AdditionTest { > >> private int x = 1; > >> private int y = 1; > >> > >> @Test > >> public void addition() { > >> int z = x + y; > >> assertEquals(2, z); > >> } > >> } > >> > >> POM file > >> <dependencies> > >> <dependency> > >> <groupId>org.junit</groupId> > >> <artifactId>junit</artifactId> > >> <version>4.4</version> > >> </dependency> > >> </dependencies> > >> > >> <build> > >> <plugins> > >> <plugin> > >> <groupId>org.apache.maven.plugins</groupId> > >> <artifactId>maven-compiler-plugin</artifactId> > >> <configuration> > >> <source>1.5</source> > >> <target>1.5</target> > >> </configuration> > >> </plugin> > >> <plugin> > >> > >> <groupId>org.apache.maven.plugins</groupId> > >> > >> <artifactId>maven-surefire-plugin</artifactId> > >> <version>2.4.3</version> > >> <configuration> > >> <includes> > >> > >> <include>**/*Test.java</include> > >> </includes> > >> </configuration> > >> </plugin> > >> </plugins> > >> </build> > >> > >> > >> Am I doing anything wrong here? Or anything else needs to be done? > >> > >> Thanks > >> Sankar > >> > >> > >> ------------------------------------ > >> > >> Yahoo! Groups Links > >> > >> > >> > >> > > > > > > -- > View this message in context: http://www.nabble.com/maven2-with-Junit-4-ignores-%40Test-annotations-tp17548499p26102430.html > Sent from the JUnit - User mailing list archive at Nabble.com. > |
|
|
Re: maven2 with Junit 4 ignores @Test annotationsI am happy to inform that I was able to make the test classes work. It was really strange because the tests from other modules were running but these weren't (and they all shared the same dependencies).
The root of the problem was that the test classes were named something other than the standard, so instead of having MyClassTest.java, they were named MyClassTester.java (I didn't create them). Once I changed them to the former, they all ran like they were supposed to. However, I do think this might be a bug in the maven-surefire-plugin code. When using annotations, it shouldn't matter what the class is named, surefire should be able to "introspect" all methods that are annotated with @Test. I guess I could also try to modify the pom to find '**/*Tester.java' classes for testing, but I try to avoid explicitly setting things as much as I can. Regards, |
| Free embeddable forum powered by Nabble | Forum Help |