user6405863 user6405863 - 1 year ago 149
Java Question

Maven running external JUnit Jar causes java.lang.Exception: No runnable methods

I have project where a user creates and uploads a

filled with
tests. My project is running in
and for some reason it will not run. I can hard code some
tests and they work fine but once I put the exact code in a .jar file the file won't run. This is my first question on Stack Overflow and I would appreciate any help.

Here is my code


import org.junit.Test;
public class simpletest {
public void sayHello() {
System.out.println("Simple test ran");

URL[] classLoaderUrls = new URL[]{new URL("file:///c:/Work/simpletest.jar")};
URLClassLoader urlClassLoader = new URLClassLoader(classLoaderUrls);
Class<?> appiumClass = null;
try {
appiumClass = urlClassLoader.loadClass("simpletest.simpletest");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
// Run the class using JUnitCore
JUnitCore junit = new JUnitCore();
Result result =;
//Display if test was successful

Answer Source

When you are loading the URLClassLoader you need to supply the current ClassLoader for it to load the required JUnit libraries.

        //Code to run junit test
        URLClassLoader urlClassLoader = new URLClassLoader(classLoaderUrls, getClass().getClassLoader());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download