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);
}
}