Reputation: 61
I am facing one problem while running the Junit scripts. I am getting the below error message.
I have three java classes under which i have commented all the @Test annotations from Class A and Class B but have four @Test annotations in Class C..but still it is showing the below error message.
Can anyone help me how to fix this issue?
Error: java.lang.Exception: No runnable methods
at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:169)
at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:104)
at org.junit.runners.ParentRunner.validate(ParentRunner.java:355)
at org.junit.runners.ParentRunner.<init>(ParentRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.Parameterized$TestClassRunnerForParameters.<init>(Parameterized.java:171)
at org.junit.runners.Parameterized.createRunnersForParameters(Parameterized.java:319)
at org.junit.runners.Parameterized.<init>(Parameterized.java:282)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
Can anyone please help here?
Upvotes: 5
Views: 26312
Reputation: 1
I also had the same problem. The problem was that in each of the tests I imported the wrong @Test. The correct one should be
org.junit.Test
. I corrected the correct @Test in each of the classes and now I can execute the @RunWith(Suite.class).
See this picture for the correct @Test to use:
Upvotes: 0
Reputation: 691
Make sure you have this import:
import org.junit.Test;
instead of:
import org.junit.jupiter.api.Test;
As well as the following annotations on test class if your project is SpringBoot 2:
@SpringBootTest
@RunWith(SpringRunner.class)
Upvotes: 7
Reputation: 366
I faced the same issue "Error: java.lang.Exception: No runnable methods" in my simple Spring-boot project. I resolved the issue by doing the following steps.
Make sure that the the test class is in src/test/java folder. In my project settings the Test class was in src/test folder.
Make sure that src/test/java is in Java Build Path. Go to Project->properties->Java Build Path ->source and add src/test/java folder.
Test class should be in same package as the source Java class with main method.
Upvotes: 3
Reputation: 5260
Make sure you import the right package :
import org.junit.runners.Parameterized;
and not the testng package
Upvotes: -2
Reputation: 95634
Ensure that all of your relevant test case objects are public
and non-abstract
, and that your test methods are annotated with @Test
but are also public void
and non-static
.
See more at the JUnit Getting Started Guide.
Upvotes: 11