导入坐标
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.2.8.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
//替换原来的运行器,让测试运行于Spring测试环境
@RunWith(SpringJUnit4ClassRunner.class)
//加载spring核心配置文件
//@ContextConfiguration("classpath:applicationContext.xml")
//加载spring核心配置类
@ContextConfiguration(classes = {Configuration.class})
public class Test {
//注入testService对象
@Autowired
private TestServiceImpl testService;
@Test
public void test1(){
testService.test();
}
}
网友评论