[ http://jira.codehaus.org/browse/SUREFIRE-116?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_86270 ]
Will Currie commented on SUREFIRE-116: -------------------------------------- I needed to get the forkMode=always option to work with a Junit TestCase that has a suite() method. It appeared that JUnitTestSet was not setting the classloader properly when it was building up the list of things to fork. I was getting the following when trying to run MyTest (foo.properties was in target/test-classes): Caused by: org.apache.maven.surefire.booter.SurefireBooterForkException: foo.MyTest; nested exception is java.io.FileNotFoundException: class path resource [foo.properties] cannot be opened because it does not exist; nested exception is org.apache.maven.surefire.testset.TestSetFailedException: foo.MyTest; nested exception is java.io.FileNotFoundException: class path resource [foo.properties] cannot be opened because it does not exist at org.apache.maven.surefire.booter.SurefireBooter.getTestSets(SurefireBooter.java:398) at org.apache.maven.surefire.booter.SurefireBooter.runSuitesForkPerTestSet(SurefireBooter.java:337) at org.apache.maven.surefire.booter.SurefireBooter.run(SurefireBooter.java:201) at org.apache.maven.plugin.surefire.SurefirePlugin.execute(SurefirePlugin.java:398) ... 18 more Caused by: org.apache.maven.surefire.testset.TestSetFailedException: foo.MyTest; nested exception is java.io.FileNotFoundException: class path resource [foo.properties] cannot be opened because it does not exist at org.apache.maven.surefire.junit.JUnitTestSet.getTestCount(JUnitTestSet.java:260) at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.locateTestSets(AbstractDirectoryTestSuite.java:101) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.apache.maven.surefire.booter.SurefireBooter.getTestSets(SurefireBooter.java:386) ... 21 more Caused by: java.io.FileNotFoundException: class path resource [foo.properties] cannot be opened because it does not exist at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:135) at foo.MyTest.suite(MyTest.java:86) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.apache.maven.surefire.junit.JUnitTestSet.createInstanceFromSuiteMethod(JUnitTestSet.java:177) at org.apache.maven.surefire.junit.JUnitTestSet.constructTestObject(JUnitTestSet.java:137) at org.apache.maven.surefire.junit.JUnitTestSet.getTestCount(JUnitTestSet.java:244) ... 27 more I made the following to change to JUnitTestSet in the 2.3-SNAPSHOT and the problem appears solved: --- surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java (revision 498497) +++ surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java (working copy) @@ -174,7 +174,14 @@ if ( Modifier.isPublic( suiteMethod.getModifiers() ) && Modifier.isStatic( suiteMethod.getModifiers() ) ) { - testObject = suiteMethod.invoke( null, EMPTY_CLASS_ARRAY ); + ClassLoader previousLoader = Thread.currentThread().getContextClassLoader(); + try { + Thread.currentThread().setContextClassLoader( testClass.getClassLoader() ); + + testObject = suiteMethod.invoke( null, EMPTY_CLASS_ARRAY ); + } finally { + Thread.currentThread().setContextClassLoader( previousLoader ); + } } } catch ( NoSuchMethodException e ) How do I go about submitting this as a patch? > [regression] Test-resources not on classpath in forkMode always > --------------------------------------------------------------- > > Key: SUREFIRE-116 > URL: http://jira.codehaus.org/browse/SUREFIRE-116 > Project: Maven Surefire > Issue Type: Bug > Affects Versions: 2.0 (2.2 plugin) > Reporter: Geoffrey De Smet > Fix For: 2.3 > > > Before surefire plugin 2.2 at spring-richclient: > - our build succeeded > - ValidationResultsTests worked > - <testFailureIgnore>true</testFailureIgnore> due to an unrelated testcase: > HandlerTest > - <forkMode>pertest</forkMode> > Since 2.2: > - our build failes > - ValidtorResultTests failed too > - while it's still <testFailureIgnore>true</testFailureIgnore> (how can it > fail in that case?) > - <forkMode>pertest</forkMode> or <forkMode>always</forkMode> (same result) > The entire discussion (with stacktraces etc) on the user list is here: > http://article.gmane.org/gmane.comp.jakarta.turbine.maven.user/45131 -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira