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); } }
这里更推荐使用注解的方法。
本文对比了在Spring环境下,不使用注解和使用注解的方式进行单元测试的区别,并推荐了使用注解的方法来简化测试配置。
583

被折叠的 条评论
为什么被折叠?



