Index: src/main/groovy/lang/GroovyShell.java =================================================================== --- src/main/groovy/lang/GroovyShell.java (revision 18145) +++ src/main/groovy/lang/GroovyShell.java (working copy) @@ -340,7 +340,7 @@ private Object runJUnit4Test(Class scriptClass) { try { return InvokerHelper.invokeStaticMethod("org.codehaus.groovy.vmplugin.v5.JUnit4Utils", - "realRunJUnit4Test", new Object[]{scriptClass}); + "realRunJUnit4Test", new Object[]{scriptClass, this.loader}); } catch (ClassNotFoundException e) { throw new GroovyRuntimeException("Failed to run the JUnit 4 test."); } @@ -349,7 +349,7 @@ private Object runTestNgTest(Class scriptClass) { try { return InvokerHelper.invokeStaticMethod("org.codehaus.groovy.vmplugin.v5.TestNgUtils", - "realRunTestNgTest", new Object[]{scriptClass}); + "realRunTestNgTest", new Object[]{scriptClass, this.loader}); } catch (ClassNotFoundException e) { throw new GroovyRuntimeException("Failed to run the TestNG test."); } Index: src/main/org/codehaus/groovy/vmplugin/v5/JUnit4Utils.java =================================================================== --- src/main/org/codehaus/groovy/vmplugin/v5/JUnit4Utils.java (revision 18145) +++ src/main/org/codehaus/groovy/vmplugin/v5/JUnit4Utils.java (working copy) @@ -75,11 +75,12 @@ * @param scriptClass the class we want to run as a test * @return the result of running the test */ - static Object realRunJUnit4Test(Class scriptClass) { + static Object realRunJUnit4Test(Class scriptClass, GroovyClassLoader loader) { // invoke through reflection to eliminate mandatory JUnit 4 jar dependency try { - Object result = InvokerHelper.invokeStaticMethod("org.junit.runner.JUnitCore", + Class junitCoreClass = loader.loadClass("org.junit.runner.JUnitCore"); + Object result = InvokerHelper.invokeStaticMethod(junitCoreClass, "runClasses", new Object[]{scriptClass}); System.out.print("JUnit 4 Runner, Tests: " + InvokerHelper.getProperty(result, "runCount")); System.out.print(", Failures: " + InvokerHelper.getProperty(result, "failureCount")); Index: src/main/org/codehaus/groovy/vmplugin/v5/TestNgUtils.java =================================================================== --- src/main/org/codehaus/groovy/vmplugin/v5/TestNgUtils.java (revision 18145) +++ src/main/org/codehaus/groovy/vmplugin/v5/TestNgUtils.java (working copy) @@ -73,13 +73,15 @@ * @param scriptClass the class we want to run as a test * @return the result of running the test */ - static Object realRunTestNgTest(Class scriptClass) { + static Object realRunTestNgTest(Class scriptClass, GroovyClassLoader loader) { // invoke through reflection to eliminate mandatory TestNG jar dependency try { - Object testng = InvokerHelper.invokeConstructorOf("org.testng.TestNG", new Object[]{}); + Class testNGClass = loader.loadClass("org.testng.TestNG"); + Object testng = InvokerHelper.invokeConstructorOf(testNGClass, new Object[]{}); InvokerHelper.invokeMethod(testng, "setTestClasses", new Object[]{scriptClass}); - Object listener = InvokerHelper.invokeConstructorOf("org.testng.TestListenerAdapter", new Object[]{}); + Class listenerClass = loader.loadClass("org.testng.TestListenerAdapter"); + Object listener = InvokerHelper.invokeConstructorOf(listenerClass, new Object[]{}); InvokerHelper.invokeMethod(testng, "addListener", new Object[]{listener}); Object result = InvokerHelper.invokeMethod(testng, "run", new Object[]{}); return result;