在类名上面加上注解
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:spring-hibernate.xml", "classpath:spring-mvc.xml", "classpath:spring.xml"})
public class Demo {
。。。。。。。。
}
classpath是spring一系列的配置文件。
需要依赖
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
在类中使用junit测试的方法即可测试
@Autowired
private UserService userService;
@Test
public void ssss(){
System.out.println(userService.getAll().size());
}