spring与junit的整合
第一步:导入jar包
<!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.2.4.RELEASE</version>
<scope>test</scope>
</dependency>
第二步:加上两个注解,初始化我们的spring容器
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:applicationContext2.xml") //加上这个两个注解,表示我们的spring的容器已经初始化了
public class SpringJunitTest {
@Autowired
private GoodsImpl goodsImpl;
@Resource(name="ordersImpl")
private OrdersImpl ordersImpl;
@Test
public void getOrdersImpl() throws Exception {
OrdersImpl ordersImpl = goodsImpl.getOrdersImpl();
ordersImpl.getOrder();
ordersImpl.getOrder();
}
}