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
