ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rick Mann <rm...@latencyzero.com>
Subject Problems running "pure" JUnit4 tests (get "no runnable method" exception)
Date Sat, 26 Aug 2006 21:44:02 GMT
I read a thread from back in March where people were discussing the  
"no runnable method" exception generated when trying to use the  
latest Ant/JUnit4 against tests written against JUnit3. In my case,  
I'm running a "pure" JUnit4 test, with a single method annotated with  
@Test, and I'm getting this error.

I should point out that my @Test method does, in fact, execute:

     [junit]     at com.mycompany.myapp.bus.TestThing.getSessionTest 
(TestThingjava:47)
     [junit]     at sun.reflect.NativeMethodAccessorImpl.invoke0 
(Native Method)
     [junit]     at sun.reflect.NativeMethodAccessorImpl.invoke 
(NativeMethodAccessorImpl.java:39)
     [junit]     at sun.reflect.DelegatingMethodAccessorImpl.invoke 
(DelegatingMethodAccessorImpl.java:25)
     [junit]     at java.lang.reflect.Method.invoke(Method.java:585)
     [junit]     at  
org.junit.internal.runners.TestMethodRunner.executeMethodBody 
(TestMethodRunner.java:99)
     [junit]     at org.junit.internal.runners.TestClassRunner.run 
(TestClassRunner.java:52)
     [junit]     at junit.framework.JUnit4TestAdapter.run 
(JUnit4TestAdapter.java:32)
     [junit]     at  
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run 
(JUnitTestRunner.java:366)


I've built Ant from the 2006.08.25 snapshot, and added some logging  
code to the JUnitTestRunner taskdef so see if I could figure out  
what's going on. As near as I can tell, it's setting up a  
JUnit4TestAdapter and using that to determine that it's running  
against JUnit4. The problems is, according to the Ant 1.7 docs for  
JUnit,

     It also works with JUnit 4.0, including "pure"
     JUnit 4 tests using only annotations and no
     JUnit4TestAdapter.

So that seems to me that it should not use JUnit4TestAdapter. My  
build target looks like this:

<target name="test" depends="build, compile-test" description="Run  
unit tests">
     <junit printsummary="on"
         fork="false"
         haltonfailure="false"
         failureproperty="tests.failed"
         showoutput="true"
         filtertrace="false">

         <jvmarg value="-ea"/>
         <jvmarg value="-esa"/>

         <classpath refid="test.classpath"/>

         <formatter type="brief" usefile="false"/>

         <batchtest fork="yes" todir="${test.reports}">
             <fileset dir="${testsrc}">
                 <include name="**/*Test*.java"/>
             </fileset>
         </batchtest>
     </junit>
</target>


And my test looks like this:

//
//  Third-party Imports
//

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;



public
class
TestThing
{
     @Test
     public
     void
     getSessionTest()
     {
         System.err.println("getSessionTest()");
     }
}


Perhaps this is a bug in JUnit--I have yet to try running the test  
outside of Ant. But if anyone can shed any light, I'd appreciate it.  
Thanks!


-- 
Rick



Mime
View raw message