Interview Questions

Can You Explain the Exception: "No runnable methods"?

JUnit Questions and Answers


(Continued from previous question...)

Can You Explain the Exception: "No runnable methods"?

You will get this exception, if you use the JUnit 4.4 core runner to execute a class that has no "@Test" method. You can try this sample class:

public class Hello { 
  public static void main(String[] arg) {
    System.out.print("Hello world!");
  }
}

Run this class with the JUnit 4.4 core runner:

java -cp .;junit-4.4.jar org.junit.runner.JUnitCore Hello

JUnit version 4.4
.E
Time: 0
There was 1 failure:
1) initializationError0(Hello)
java.lang.Exception: No runnable methods
 at org.junit.internal.runners.MethodValidator.validateInstanceM
 at org.junit.internal.runners.MethodValidator.validateMethodsFo
 at org.junit.internal.runners.JUnit4ClassRunner.validate(JUnit4
 at org.junit.internal.runners.JUnit4ClassRunner.(JUnit4Cl
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Nativ
 ...
 at org.junit.runner.JUnitCore.run(JUnitCore.java:100)
 at org.junit.runner.JUnitCore.runMain(JUnitCore.java:81)
 at org.junit.runner.JUnitCore.main(JUnitCore.java:44)

FAILURES!!!
Tests run: 1,  Failures: 1

Other Interview Questions