第一章 Spring集成Junit4
1.1 集成步骤
- 导入jar包
- spring-test-5.3.1.jar
- 指定Spring的配置文件的路径
- 【@ContextConfiguration】
- 指定Spring环境下运行Junit4的运行器
- @RunWith
1.2 示例代码
/**
* @author Chunsheng Zhang 尚硅谷
* @create 2022/3/28 14:12
*/
@ContextConfiguration(locations = "classpath:applicationContext.xml")
@RunWith(SpringJUnit4ClassRunner.class)
public class TestSpringJunit4 {
@Autowired
private DeptService deptService;
@Test
public void testService(){
//创建容器对象
// ApplicationContext context =
// new ClassPathXmlApplicationContext("applicationContext.xml");
// DeptService deptService = context.getBean("deptService", DeptServiceImpl.class);
deptService.saveDept(new Dept());
}
}