You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Frederic Bergeron <FB...@rocketmail.com> on 2011/05/19 13:10:34 UTC
No runnable methods when running junit4 with maven-antrun-plugin
Hi,
I'm trying to execute a unit test (junit4) using the maven-antrun-plugin. I know that the recommended approach is to use the maven-surefire-plugin but some constraints prevent me from doing so. I've simplified my code to reproduce the problem. I always get the following exception:
Testsuite: junit.MyDummyTest
Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0.016 sec
Testcase: unknown took 0 sec
Caused an ERROR
No runnable methods
java.lang.Exception: No runnable methods
at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:177)
at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:122)
at org.junit.runners.ParentRunner.validate(ParentRunner.java:269)
at org.junit.runners.ParentRunner.<init>(ParentRunner.java:66)
at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:58)
at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:13)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
at junit.framework.JUnit4TestAdapter.<init>(JUnit4TestAdapter.java:31)
at junit.framework.JUnit4TestAdapter.<init>(JUnit4TestAdapter.java:24)
at junit.MyDummyTest.suite(MyDummyTest.java:16)
at org.apache.maven.plugin.antrun.AntRunMojo.execute(AntRunMojo.java:270)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
What's missing? Or what am I doing wrong?
If I run the test using Ant, it works fine.
My pom.xml file looks like this:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>gomi</groupId>
<version>0.1.0-SNAPSHOT</version>
<artifactId>junitbug</artifactId>
<packaging>jar</packaging>
<name>JUnitBug</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>test</id>
<phase>compile</phase>
<configuration>
<target>
<property name="build.compiler" value="extJavac" />
<property name="compile_classpath" refid="maven.compile.classpath"/>
<property name="runtime_classpath" refid="maven.runtime.classpath"/>
<property name="test_classpath" refid="maven.test.classpath"/>
<property name="plugin_classpath" refid="maven.plugin.classpath"/>
<echo message="compile classpath: ${compile_classpath}"/>
<echo message="runtime classpath: ${runtime_classpath}"/>
<echo message="test classpath: ${test_classpath}"/>
<echo message="plugin classpath: ${plugin_classpath}"/>
<echo message="junit: ${junit:junit:jar}"/>
<echo message="env.JAVA_HOME=${env.JAVA_HOME}"/>
<echo message="java.home=${java.home}"/>
<echo message="env.ANT_HOME=${env.ANT_HOME}"/>
<echo message="ant.home=${ant.home}"/>
<taskdef name="junit" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask" classpathref="maven.plugin.classpath"/>
<ant antfile="build.xml" target="test" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>clean</id>
<phase>clean</phase>
<configuration>
<target>
<ant antfile="build.xml" target="clean" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-junit</artifactId>
<version>1.6.5</version>
<!--scope>test</scope-->
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<!--scope>test</scope-->
</dependency>
<!--dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-commons-net</artifactId>
<version>1.6.5</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-nodeps</artifactId>
<version>1.6.5</version>
</dependency-->
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-junit</artifactId>
<version>1.6.5</version>
<!--scope>test</scope-->
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<!--scope>test</scope-->
</dependency>
</dependencies>
</project>
And here is my test file:
package junit;
import org.junit.Test;
import static org.junit.Assert.*;
import junit.framework.JUnit4TestAdapter;
public class MyDummyTest {
@Test
public void theSimplestTestEver() {
assertTrue(true);
}
public static junit.framework.Test suite() {
return new JUnit4TestAdapter(MyDummyTest.class);
}
}
For convenience, a zip file containing the whole project can be downloaded here:
http://www.fbergeron.com/tmp/junitbug.zip
Any help would be very appreciated.
Frederic Bergeron
Re: No runnable methods when running junit4 with maven-antrun-plugin
Posted by Frederic Bergeron <FB...@rocketmail.com>.
Hi Rafael,
I tried to rename the test method as suggested but the same problem occurs.
Thanks for the help,
Frederic
________________________________
From: Rafael Vanderlei <ra...@gmail.com>
To: Maven Users List <us...@maven.apache.org>; Frederic Bergeron <FB...@rocketmail.com>
Sent: Thursday, May 19, 2011 9:07 PM
Subject: Re: No runnable methods when running junit4 with maven-antrun-plugin
Maybe, for some reason, the JUnitTask you are running uses JUnit 3.x tests where methods names must start with "test"... I´m just guessing, but you could try to rename your test method to start with "test" like public void testTheSimplestTestEver(){...} and see if it works to confirm (or not).
On Thu, May 19, 2011 at 8:10 AM, Frederic Bergeron <FB...@rocketmail.com> wrote:
Hi,
>
>I'm trying to execute a unit test (junit4) using the maven-antrun-plugin. I know that the recommended approach is to use the maven-surefire-plugin but some constraints prevent me from doing so. I've simplified my code to reproduce the problem. I always get the following exception:
>
>Testsuite: junit.MyDummyTest
>Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0.016 sec
>
>Testcase: unknown took 0 sec
> Caused an ERROR
>No runnable methods
>java.lang.Exception: No runnable methods
> at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:177)
> at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:122)
> at org.junit.runners.ParentRunner.validate(ParentRunner.java:269)
> at org.junit.runners.ParentRunner.<init>(ParentRunner.java:66)
> at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:58)
> at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:13)
> at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
> at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
> at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
> at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
> at junit.framework.JUnit4TestAdapter.<init>(JUnit4TestAdapter.java:31)
> at junit.framework.JUnit4TestAdapter.<init>(JUnit4TestAdapter.java:24)
> at junit.MyDummyTest.suite(MyDummyTest.java:16)
> at org.apache.maven.plugin.antrun.AntRunMojo.execute(AntRunMojo.java:270)
> at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
> at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
> at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
> at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
> at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
> at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
> at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
> at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
> at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
> at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
> at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
> at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
> at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
> at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
> at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
> at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
> at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
>
>What's missing? Or what am I doing wrong?
>
>If I run the test using Ant, it works fine.
>
>My pom.xml file looks like this:
>
><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
> <modelVersion>4.0.0</modelVersion>
> <groupId>gomi</groupId>
> <version>0.1.0-SNAPSHOT</version>
> <artifactId>junitbug</artifactId>
> <packaging>jar</packaging>
> <name>JUnitBug</name>
> <build>
> <plugins>
> <plugin>
> <groupId>org.apache.maven.plugins</groupId>
> <artifactId>maven-antrun-plugin</artifactId>
> <version>1.6</version>
> <executions>
> <execution>
> <id>test</id>
> <phase>compile</phase>
> <configuration>
> <target>
> <property name="build.compiler" value="extJavac" />
>
> <property name="compile_classpath" refid="maven.compile.classpath"/>
> <property name="runtime_classpath" refid="maven.runtime.classpath"/>
> <property name="test_classpath" refid="maven.test.classpath"/>
> <property name="plugin_classpath" refid="maven.plugin.classpath"/>
> <echo message="compile classpath: ${compile_classpath}"/>
> <echo message="runtime classpath: ${runtime_classpath}"/>
> <echo message="test classpath: ${test_classpath}"/>
> <echo message="plugin classpath: ${plugin_classpath}"/>
> <echo message="junit: ${junit:junit:jar}"/>
> <echo message="env.JAVA_HOME=${env.JAVA_HOME}"/>
> <echo message="java.home=${java.home}"/>
> <echo message="env.ANT_HOME=${env.ANT_HOME}"/>
> <echo message="ant.home=${ant.home}"/>
>
> <taskdef name="junit" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask" classpathref="maven.plugin.classpath"/>
> <ant antfile="build.xml" target="test" />
> </target>
> </configuration>
> <goals>
> <goal>run</goal>
> </goals>
> </execution>
> <execution>
> <id>clean</id>
> <phase>clean</phase>
> <configuration>
> <target>
> <ant antfile="build.xml" target="clean" />
> </target>
> </configuration>
> <goals>
> <goal>run</goal>
> </goals>
> </execution>
> </executions>
> <dependencies>
> <dependency>
> <groupId>ant</groupId>
> <artifactId>ant-junit</artifactId>
> <version>1.6.5</version>
> <!--scope>test</scope-->
> </dependency>
> <dependency>
> <groupId>junit</groupId>
> <artifactId>junit</artifactId>
> <version>4.8.2</version>
> <!--scope>test</scope-->
> </dependency>
> <!--dependency>
> <groupId>commons-net</groupId>
> <artifactId>commons-net</artifactId>
> <version>1.4.1</version>
> </dependency>
> <dependency>
> <groupId>ant</groupId>
> <artifactId>ant-commons-net</artifactId>
> <version>1.6.5</version>
> </dependency>
> <dependency>
> <groupId>ant</groupId>
> <artifactId>ant-nodeps</artifactId>
> <version>1.6.5</version>
> </dependency-->
> </dependencies>
> </plugin>
> </plugins>
> </build>
> <dependencies>
> <dependency>
> <groupId>ant</groupId>
> <artifactId>ant-junit</artifactId>
> <version>1.6.5</version>
> <!--scope>test</scope-->
> </dependency>
> <dependency>
> <groupId>junit</groupId>
> <artifactId>junit</artifactId>
> <version>4.8.2</version>
> <!--scope>test</scope-->
> </dependency>
> </dependencies>
></project>
>
>
>And here is my test file:
>
>package junit;
>
>import org.junit.Test;
>import static org.junit.Assert.*;
>import junit.framework.JUnit4TestAdapter;
>
>
>public class MyDummyTest {
>
> @Test
> public void theSimplestTestEver() {
> assertTrue(true);
> }
>
> public static junit.framework.Test suite() {
> return new JUnit4TestAdapter(MyDummyTest.class);
> }
>
>}
>
>For convenience, a zip file containing the whole project can be downloaded here:
>
>http://www.fbergeron.com/tmp/junitbug.zip
>
>Any help would be very appreciated.
>
>Frederic Bergeron
Re: No runnable methods when running junit4 with maven-antrun-plugin
Posted by Rafael Vanderlei <ra...@gmail.com>.
Maybe, for some reason, the JUnitTask you are running uses JUnit 3.x tests
where methods names must start with "test"... I´m just guessing, but you
could try to rename your test method to start with "test" like public void
testTheSimplestTestEver(){...} and see if it works to confirm (or not).
On Thu, May 19, 2011 at 8:10 AM, Frederic Bergeron <FBergeron@rocketmail.com
> wrote:
> Hi,
>
> I'm trying to execute a unit test (junit4) using the maven-antrun-plugin.
> I know that the recommended approach is to use the maven-surefire-plugin but
> some constraints prevent me from doing so. I've simplified my code to
> reproduce the problem. I always get the following exception:
>
> Testsuite: junit.MyDummyTest
> Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0.016 sec
>
> Testcase: unknown took 0 sec
> Caused an ERROR
> No runnable methods
> java.lang.Exception: No runnable methods
> at
> org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:177)
> at
> org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:122)
> at org.junit.runners.ParentRunner.validate(ParentRunner.java:269)
> at org.junit.runners.ParentRunner.<init>(ParentRunner.java:66)
> at
> org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:58)
> at
> org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:13)
> at
> org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
> at
> org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
> at
> org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
> at
> org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
> at junit.framework.JUnit4TestAdapter.<init>(JUnit4TestAdapter.java:31)
> at junit.framework.JUnit4TestAdapter.<init>(JUnit4TestAdapter.java:24)
> at junit.MyDummyTest.suite(MyDummyTest.java:16)
> at
> org.apache.maven.plugin.antrun.AntRunMojo.execute(AntRunMojo.java:270)
> at
> org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
> at
> org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
> at
> org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
> at
> org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
> at
> org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
> at
> org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
> at
> org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
> at
> org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
> at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
> at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
> at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
> at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
> at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
> at
> org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
> at
> org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
> at
> org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
> at
> org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
>
> What's missing? Or what am I doing wrong?
>
> If I run the test using Ant, it works fine.
>
> My pom.xml file looks like this:
>
> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="
> http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
> http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd
> ">
> <modelVersion>4.0.0</modelVersion>
> <groupId>gomi</groupId>
> <version>0.1.0-SNAPSHOT</version>
> <artifactId>junitbug</artifactId>
> <packaging>jar</packaging>
> <name>JUnitBug</name>
> <build>
> <plugins>
> <plugin>
> <groupId>org.apache.maven.plugins</groupId>
> <artifactId>maven-antrun-plugin</artifactId>
> <version>1.6</version>
> <executions>
> <execution>
> <id>test</id>
> <phase>compile</phase>
> <configuration>
> <target>
> <property name="build.compiler"
> value="extJavac" />
>
> <property name="compile_classpath"
> refid="maven.compile.classpath"/>
> <property name="runtime_classpath"
> refid="maven.runtime.classpath"/>
> <property name="test_classpath"
> refid="maven.test.classpath"/>
> <property name="plugin_classpath"
> refid="maven.plugin.classpath"/>
> <echo message="compile classpath:
> ${compile_classpath}"/>
> <echo message="runtime classpath:
> ${runtime_classpath}"/>
> <echo message="test classpath:
> ${test_classpath}"/>
> <echo message="plugin classpath:
> ${plugin_classpath}"/>
> <echo message="junit: ${junit:junit:jar}"/>
> <echo
> message="env.JAVA_HOME=${env.JAVA_HOME}"/>
> <echo message="java.home=${java.home}"/>
> <echo
> message="env.ANT_HOME=${env.ANT_HOME}"/>
> <echo message="ant.home=${ant.home}"/>
>
> <taskdef name="junit"
> classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"
> classpathref="maven.plugin.classpath"/>
> <ant antfile="build.xml" target="test" />
> </target>
> </configuration>
> <goals>
> <goal>run</goal>
> </goals>
> </execution>
> <execution>
> <id>clean</id>
> <phase>clean</phase>
> <configuration>
> <target>
> <ant antfile="build.xml" target="clean" />
> </target>
> </configuration>
> <goals>
> <goal>run</goal>
> </goals>
> </execution>
> </executions>
> <dependencies>
> <dependency>
> <groupId>ant</groupId>
> <artifactId>ant-junit</artifactId>
> <version>1.6.5</version>
> <!--scope>test</scope-->
> </dependency>
> <dependency>
> <groupId>junit</groupId>
> <artifactId>junit</artifactId>
> <version>4.8.2</version>
> <!--scope>test</scope-->
> </dependency>
> <!--dependency>
> <groupId>commons-net</groupId>
> <artifactId>commons-net</artifactId>
> <version>1.4.1</version>
> </dependency>
> <dependency>
> <groupId>ant</groupId>
> <artifactId>ant-commons-net</artifactId>
> <version>1.6.5</version>
> </dependency>
> <dependency>
> <groupId>ant</groupId>
> <artifactId>ant-nodeps</artifactId>
> <version>1.6.5</version>
> </dependency-->
> </dependencies>
> </plugin>
> </plugins>
> </build>
> <dependencies>
> <dependency>
> <groupId>ant</groupId>
> <artifactId>ant-junit</artifactId>
> <version>1.6.5</version>
> <!--scope>test</scope-->
> </dependency>
> <dependency>
> <groupId>junit</groupId>
> <artifactId>junit</artifactId>
> <version>4.8.2</version>
> <!--scope>test</scope-->
> </dependency>
> </dependencies>
> </project>
>
>
> And here is my test file:
>
> package junit;
>
> import org.junit.Test;
> import static org.junit.Assert.*;
> import junit.framework.JUnit4TestAdapter;
>
>
> public class MyDummyTest {
>
> @Test
> public void theSimplestTestEver() {
> assertTrue(true);
> }
>
> public static junit.framework.Test suite() {
> return new JUnit4TestAdapter(MyDummyTest.class);
> }
>
> }
>
> For convenience, a zip file containing the whole project can be downloaded
> here:
>
> http://www.fbergeron.com/tmp/junitbug.zip
>
> Any help would be very appreciated.
>
> Frederic Bergeron
Re: No runnable methods when running junit4 with maven-antrun-plugin
Posted by Anders Hammar <an...@hammar.net>.
I think that your execution of JUnit doesn't see your test code due to
incorrect class paths.
Please, try to eliminate your "constraints" and use the surefire-plugin. It
will save you this type of problems. If something is missing in that plugin,
provide a patch!
/Anders
On Thu, May 19, 2011 at 13:10, Frederic Bergeron
<FB...@rocketmail.com>wrote:
> Hi,
>
> I'm trying to execute a unit test (junit4) using the maven-antrun-plugin.
> I know that the recommended approach is to use the maven-surefire-plugin but
> some constraints prevent me from doing so. I've simplified my code to
> reproduce the problem. I always get the following exception:
>
> Testsuite: junit.MyDummyTest
> Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0.016 sec
>
> Testcase: unknown took 0 sec
> Caused an ERROR
> No runnable methods
> java.lang.Exception: No runnable methods
> at
> org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:177)
> at
> org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:122)
> at org.junit.runners.ParentRunner.validate(ParentRunner.java:269)
> at org.junit.runners.ParentRunner.<init>(ParentRunner.java:66)
> at
> org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:58)
> at
> org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:13)
> at
> org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
> at
> org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
> at
> org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
> at
> org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
> at junit.framework.JUnit4TestAdapter.<init>(JUnit4TestAdapter.java:31)
> at junit.framework.JUnit4TestAdapter.<init>(JUnit4TestAdapter.java:24)
> at junit.MyDummyTest.suite(MyDummyTest.java:16)
> at
> org.apache.maven.plugin.antrun.AntRunMojo.execute(AntRunMojo.java:270)
> at
> org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
> at
> org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
> at
> org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
> at
> org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
> at
> org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
> at
> org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
> at
> org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
> at
> org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
> at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
> at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
> at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
> at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
> at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
> at
> org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
> at
> org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
> at
> org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
> at
> org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
>
> What's missing? Or what am I doing wrong?
>
> If I run the test using Ant, it works fine.
>
> My pom.xml file looks like this:
>
> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="
> http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
> http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd
> ">
> <modelVersion>4.0.0</modelVersion>
> <groupId>gomi</groupId>
> <version>0.1.0-SNAPSHOT</version>
> <artifactId>junitbug</artifactId>
> <packaging>jar</packaging>
> <name>JUnitBug</name>
> <build>
> <plugins>
> <plugin>
> <groupId>org.apache.maven.plugins</groupId>
> <artifactId>maven-antrun-plugin</artifactId>
> <version>1.6</version>
> <executions>
> <execution>
> <id>test</id>
> <phase>compile</phase>
> <configuration>
> <target>
> <property name="build.compiler"
> value="extJavac" />
>
> <property name="compile_classpath"
> refid="maven.compile.classpath"/>
> <property name="runtime_classpath"
> refid="maven.runtime.classpath"/>
> <property name="test_classpath"
> refid="maven.test.classpath"/>
> <property name="plugin_classpath"
> refid="maven.plugin.classpath"/>
> <echo message="compile classpath:
> ${compile_classpath}"/>
> <echo message="runtime classpath:
> ${runtime_classpath}"/>
> <echo message="test classpath:
> ${test_classpath}"/>
> <echo message="plugin classpath:
> ${plugin_classpath}"/>
> <echo message="junit: ${junit:junit:jar}"/>
> <echo
> message="env.JAVA_HOME=${env.JAVA_HOME}"/>
> <echo message="java.home=${java.home}"/>
> <echo
> message="env.ANT_HOME=${env.ANT_HOME}"/>
> <echo message="ant.home=${ant.home}"/>
>
> <taskdef name="junit"
> classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"
> classpathref="maven.plugin.classpath"/>
> <ant antfile="build.xml" target="test" />
> </target>
> </configuration>
> <goals>
> <goal>run</goal>
> </goals>
> </execution>
> <execution>
> <id>clean</id>
> <phase>clean</phase>
> <configuration>
> <target>
> <ant antfile="build.xml" target="clean" />
> </target>
> </configuration>
> <goals>
> <goal>run</goal>
> </goals>
> </execution>
> </executions>
> <dependencies>
> <dependency>
> <groupId>ant</groupId>
> <artifactId>ant-junit</artifactId>
> <version>1.6.5</version>
> <!--scope>test</scope-->
> </dependency>
> <dependency>
> <groupId>junit</groupId>
> <artifactId>junit</artifactId>
> <version>4.8.2</version>
> <!--scope>test</scope-->
> </dependency>
> <!--dependency>
> <groupId>commons-net</groupId>
> <artifactId>commons-net</artifactId>
> <version>1.4.1</version>
> </dependency>
> <dependency>
> <groupId>ant</groupId>
> <artifactId>ant-commons-net</artifactId>
> <version>1.6.5</version>
> </dependency>
> <dependency>
> <groupId>ant</groupId>
> <artifactId>ant-nodeps</artifactId>
> <version>1.6.5</version>
> </dependency-->
> </dependencies>
> </plugin>
> </plugins>
> </build>
> <dependencies>
> <dependency>
> <groupId>ant</groupId>
> <artifactId>ant-junit</artifactId>
> <version>1.6.5</version>
> <!--scope>test</scope-->
> </dependency>
> <dependency>
> <groupId>junit</groupId>
> <artifactId>junit</artifactId>
> <version>4.8.2</version>
> <!--scope>test</scope-->
> </dependency>
> </dependencies>
> </project>
>
>
> And here is my test file:
>
> package junit;
>
> import org.junit.Test;
> import static org.junit.Assert.*;
> import junit.framework.JUnit4TestAdapter;
>
>
> public class MyDummyTest {
>
> @Test
> public void theSimplestTestEver() {
> assertTrue(true);
> }
>
> public static junit.framework.Test suite() {
> return new JUnit4TestAdapter(MyDummyTest.class);
> }
>
> }
>
> For convenience, a zip file containing the whole project can be downloaded
> here:
>
> http://www.fbergeron.com/tmp/junitbug.zip
>
> Any help would be very appreciated.
>
> Frederic Bergeron