Spring整合Junit测试

1.测试类需要继承 AbstractJUnit4SpringContextTests类

2.测试类上边添加注解

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring/applicationContext-*.xml")

3.即可注入组件测试

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring/applicationContext-*.xml")
public class UserServiceTest extends AbstractJUnit4SpringContextTests{

	@Autowired
	private UserService userService;
	
	@Test
	public void test() {
		List<User> list = this.userService.findAll();
		System.out.println(list);
	}

}
posted @ 2017-08-01 22:11  关小西  阅读(480)  评论(0编辑  收藏  举报