[英]Spring 4 TestNG +@Autowired
Have a class in the package com.conf
在包
com.conf
有一个类
@Configuration
public class WebConfTest {
@Autowired
private Environment environment;
}
and unit test into com.service
和单元测试到
com.service
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { WebConfTest.class })
public class DMSServiceImplTest {
@Autowired
WebConfTest webConfTest;
@Test
public void testConnect() throws Exception {
}
}
test dependency : 测试依赖项:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${springframework.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
<scope>test</scope>
</dependency>
In the IDEA navigation between beans work. 在IDEA中,bean之间的导航有效。 But
WebConfTest
== null if I run test. 但是,如果我运行测试,则
WebConfTest
== null。
What is wrong? 怎么了?
Thanks. 谢谢。
@RunWith
is for junit runner. @RunWith
适用于junit运行程序。
If you want to run tests with TestNG, you need to extends AbstractTestNGSpringContextTests
. 如果要使用TestNG运行测试,则需要扩展
AbstractTestNGSpringContextTests
。
http://docs.spring.io/spring/docs/current/spring-framework-reference/html/integration-testing.html#testcontext-support-classes-testng http://docs.spring.io/spring/docs/current/spring-framework-reference/html/integration-testing.html#testcontext-support-classes-testng
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.