Coding⏱️ 3 min read📅 2026-06-03

How to Fix: java.lang.Exception: No runnable methods exception in running JUnits

The issue is caused by the missing @RunWith annotation on the TestRunner class. Add @RunWith(JUnitCore.class) to the TestRunner class to fix the exception.

Quick Answer: Add @RunWith(JUnitCore.class) to the TestRunner class to resolve the No runnable methods exception.

Error: java.lang.Exception: No runnable methods exception in running JUnits. This issue affects developers who are trying to run their JUnit tests on Linux command prompts.

This error can be frustrating as it prevents the test from executing, and it may cause delays in project completion.

💡 Why You Are Getting This Error

  • The primary reason for this error is that the JUnit runner requires a main method annotated with @RunWith or @Main. However, in your case, you are using JUnitCore which does not require a main method.
  • Another possible cause could be a mismatch between the JAR files and classpaths. Make sure that the hamcrest-core-1.3.jar and junit.jar files are correctly placed in the classpath.

🚀 How to Resolve This Issue

Using JUnitCore with a custom Runner

  1. Step 1: Create a new class that extends JUnitCore
  2. Step 2: Annotate this class with @RunWith to specify the custom runner
  3. Step 3: Use the TestRunner class from org.junit.runner package

Using a Main Method with JUnit4

  1. Step 1: Annotate your test class with @RunWith(JUnit4.class)
  2. Step 2: Add the main method to your test class
  3. Step 3: Use the JUnit4 classpath instead of JUnitCore

🎯 Final Words

To resolve this issue, you can either use a custom runner with JUnitCore or add a main method to your test class using JUnit4. By following these steps, you should be able to run your JUnit tests successfully on Linux command prompts.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions