0

I have a Springboot, java, maven project. Here are the version - java - 1.8; Junit- 4; SpringBoot version- 2.1.6-RELEASE

There is this TestClass. PFA the code -

@RunWith(SpringRunner.class)
@SpringBootTest
public class TestClass {

    @BeforeMethod
    public void setUp() {
        // code
    }

    @Test
    public void testMethod() throws ExecutionException {
        // Test method
    }

    static abstract class class1 {
        // code
    }

    static abstract class class2 {
        // code
    }
}

When I run this as JUnit, I get the following error message -


java.lang.Exception: No runnable methods
    at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:191)
    at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:128)
    at org.junit.runners.ParentRunner.validate(ParentRunner.java:416)
    at org.junit.runners.ParentRunner.<init>(ParentRunner.java:84)
    at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:65)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:137)

Can someone please suggest what am I doing wrong here?

  • Does this answer your question? [java.lang.Exception: No runnable methods exception in running JUnits](https://stackoverflow.com/questions/24319697/java-lang-exception-no-runnable-methods-exception-in-running-junits) – Max Urbanowicz Dec 05 '19 at 09:09
  • Just to be sure you are using BeforeMethod annotation from TestNG package right? – Malay Shah Dec 05 '19 at 09:15
  • @MalayShah - Right. –  Dec 05 '19 at 09:17
  • I tried and the code worked just fine for me. most probably seems like Spring setup issue or the way you are executing it. Can you share how are you executing it? – Malay Shah Dec 05 '19 at 09:21
  • Were you able to run it in IDE or the terminal? @MalayShah –  Dec 05 '19 at 09:22
  • I am running via Eclipse - Run as Junit. –  Dec 05 '19 at 09:23
  • I executed via Eclipse - I have a maven project where in test resource I created class with your code above and Run as Junit and it worked. – Malay Shah Dec 05 '19 at 09:30

0 Answers0