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

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

原文地址:https://www.cnblogs.com/laoyeye/p/6505672.html