1

I am using spring boot 2.0.1.RELEASE and TestNG for testing. But unable to load spring context and autowire repository. Kindly guide me.

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class ApplictionTestsWithTestNG extends AbstractTestNGSpringContextTests{

    @Autowired
    MyRepository repo;

    @BeforeTest
    public void setup() {
        System.out.println("repository found "+repo);
    }

    @Test
    public void matchLastSavedData() {
        System.out.println("repository found " + repo);
        assertEquals(5,5);
    }
}

When running, it throws

java.lang.Exception: No runnable methods
    at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:191)
Feedforward
  • 4,521
  • 4
  • 22
  • 34

3 Answers3

1

You have no methods annotated @Test.

There are no tests to run, just as the error message told you.

Write a test method annotated with @Test.

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
  • I have written @Test but still it shows the same error, But when running my test class via TestNG test. It runs but again it's not loading the context. The main issue is that I am unable to get repository bean. – roushan kumar Singh Jun 21 '18 at 04:38
  • Please edit your question to show what you have tried that is not working. – Jim Garrison Jun 21 '18 at 04:40
  • I have edited my question, But the issue is same while running it as a JUnit test, I have installed TestNG plugins in eclipse, then running it as a TestNG test, It works fine. But now I am unable to run mvn test via command. – roushan kumar Singh Jun 21 '18 at 05:05
1

@RunWith(SpringJUnit4ClassRunner.class) works with JUnit. Needs to define context configuration which should wire MyRepository bean.

0

try like this @RunWith(SpringRunner.class)