Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: java.lang.Exception: No runnable methods

Tags:

junit

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?

like image 912
user3572052 Avatar asked May 02 '14 11:05

user3572052


2 Answers

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.

like image 184
Jeff Bowman Avatar answered Sep 23 '22 14:09

Jeff Bowman


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)
like image 38
Artyom Rebrov Avatar answered Sep 22 '22 14:09

Artyom Rebrov