Junit单元测试实例

1、非注解

public class Test {
    @org.junit.Test
    public void  testPrice() {
        
    ClassPathXmlApplicationContext beans = new ClassPathXmlApplicationContext(new String[]{"spring.xml","spring-mybatis.xml"} );
        IStationService stationService = (IStationService) beans.getBean("stationService");
        Double s=stationService.calcuStationEndPrice("k596", "砀山", "芜湖");
        System.out.println(s);
    }
}

2、注解

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:spring.xml","classpath:spring-mybatis.xml"})
public class Test {
    @Autowired
    private IStationService stationService;
    @org.junit.Test
    public void  testPrice() {
        Double s=stationService.calcuStationEndPrice("k596", "砀山", "芜湖");
        System.out.println(s);
    }
}

这里更推荐使用注解的方法。

posted @ 2017-03-05 15:50  小卖铺的老爷爷  阅读(378)  评论(0编辑  收藏  举报


^
TOP