[英]Spring boot testing with testNG
I am using spring boot 2.0.1.RELEASE and TestNG for testing.我正在使用 spring boot 2.0.1.RELEASE 和 TestNG 进行测试。 But unable to load spring context and autowire repository.但无法加载 spring 上下文和自动装配存储库。 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
.您没有注释@Test
方法。
There are no tests to run, just as the error message told you.正如错误消息告诉您的那样,没有要运行的测试。
Write a test method annotated with @Test
.编写一个用@Test
注释的测试方法。
@RunWith(SpringJUnit4ClassRunner.class) works with JUnit. @RunWith(SpringJUnit4ClassRunner.class) 与 JUnit 一起工作。 Needs to define context configuration which should wire MyRepository bean.需要定义应该连接 MyRepository bean 的上下文配置。
试试这样@RunWith(SpringRunner.class)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.