使用步骤
- 导包: Spring单元测试包spring-test-4.0.0.RELEASE.jar
- @ContextConfiguration(locations=””)来指定Spring的配置文件
- @RunWith指定用哪种驱动进行单元测试,默认JUnit
@RunWith(SpringJUnit4ClassRunner.class)
使用Spring的单元测试模块来执行标了@Test的测试方法
好处是不需要获取Bean1
2
3
4
5
6
7
8
9
10
11
12
13@ContextConfiguration(locations="classpath:ioc.xml")
@RunWith(SpringJUnit4ClassRunner.class)
public class SpringIOCTest {
ApplicationContext ioc = null;
@Autowired
BookServlet bookServlet;
@Test
public void test() {
System.out.println("--"+bookServlet);
}
}