spring与junit的整合

springjunit整合

第一步:导入jar

<dependency>

    <groupId>org.springframeworkgroupId>

    <artifactId>spring-testartifactId>

    <version>4.2.4.RELEASEversion>

    <scope>testscope>

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

}

}

你可能感兴趣的:(ssh的Spring)