简体   繁体   中英

Spring boot testing with testNG

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)

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 .

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

试试这样@RunWith(SpringRunner.class)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM