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

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

Junit单元测试实例的更多相关文章

  1. spring框架学习(三)junit单元测试

    spring框架学习(三)junit单元测试 单元测试不是头一次听说了,但只是听说从来没有用过.一个模块怎么测试呢,是不是得专门为一单元写一个测试程序,然后将测试单元代码拿过来测试? 我是这么想的.学 ...

  2. springmvc 项目完整示例02 项目创建-eclipse创建动态web项目 配置文件 junit单元测试

    包结构 所需要的jar包直接拷贝到lib目录下 然后选定 build path 之后开始写项目代码 配置文件 ApplicationContext.xml <?xml version=" ...

  3. 使用junit单元测试

    使用junit单元测试 一.方法 二.说明 使用这个测试函数或者调试错误非常方便 三.代码实例 后面补

  4. junit单元测试(keeps the bar green to keeps the code clean)

    error是程序错误,failure是测试错误. junit概要: JUnit是由 Erich Gamma (设计模式的创始人)和 Kent Beck (敏捷开发的创始人之一)编写的一个回归测试框架( ...

  5. spring && Cobertura && maven &&junit 单元测试以及测试覆盖率

    1. 目的:       junit 单元测试,Cobertura   测试覆盖率报告       项目目录结构          2. maven 配置     <project xmlns= ...

  6. 解决Junit单元测试 找不到类 ----指定Java Build Path

    做junit 单元测试时,发现怎么执行都是以前编译过得代码. 最后找到原因了, src/test/java 编译完的.class路径是 Default output folder Default ou ...

  7. JUnit单元测试框架的使用

    http://blog.csdn.net/mao520741111/article/details/51462215 原文地址 http://www.open-open.com/lib/view/op ...

  8. Java 工具 JUnit单元测试

    Java 工具 JUnit单元测试 @author ixenos 1.1.   JUnit单元测试框架的基本使用 一.搭建环境: 导入junit.jar包(junit4) 二.写测试类: 0,一般一个 ...

  9. Spring框架中整合JUnit单元测试的方法

    一. 步骤: 1. 拷贝jar包: 1. JUnit-4.9.jar和spring-test-4.2.4.RELEASE.jar ; 2. 替换原来的main函数: 1. 在测试类上使用注解方式替换: ...

随机推荐

  1. LayUI分页,LayUI动态分页,LayUI laypage分页,LayUI laypage刷新当前页

    LayUI分页,LayUI动态分页,LayUI laypage分页,LayUI laypage刷新当前页 >>>>>>>>>>>> ...

  2. Qt5构建出错问题解决办法

    我之前用的Qt其他版本,因为一些原因我更换了Qt版本,从Qt5.9.1又更换到之前用的Qt5.3.2,但是发现无法build,问题提示如下: 19:54:03: 为项目untitled执行步骤 ... ...

  3. Redux源码分析之applyMiddleware

    Redux源码分析之基本概念 Redux源码分析之createStore Redux源码分析之bindActionCreators Redux源码分析之combineReducers Redux源码分 ...

  4. 图解虚数 - A Visual, Intuitive Gudie to Imaginary Numbers

    这是一篇发表在 betterexplained 上的文章.它通过类比.图解的方式简明地介绍了虚数的意义. 作者:Kalid 原文:A Visual, Intuitive Gudie to Imagin ...

  5. docke镜像上传到dockerhub仓库和阿里云docker仓库的方法

    操作指南   1.  登录阿里云docker registry: $ sudo docker login --username=linjiaxin897591495 registry.cn-hangz ...

  6. 获取本机IP(适用于Linux系统)

    获取本机IP(适用于Linux系统) /** * @desc 获取本机IP(适用于Linux系统) * @return Ip */ public static String getLocalIP() ...

  7. 一个想法照进现实-《IT连》创业项目:一个转折一个反思

    前言: 距离上一篇介绍IT连创业项目的文章,已经过去2个月了,没想到我竟然这么久没写文章向大伙汇报进度了,实在抱歉. 关于这事,我得好好反省,认真检讨,好好写文,哈. 今天主要是讲述一下最近创业的进展 ...

  8. 含有n个元素的整型数组,将这个n个元素重新组合,求出最小的数,如{321,3,32},最小的数为321323

    public class GetMinNumber { public static void main(String[] args) { String[] arr = null; System.out ...

  9. Git异常情况汇总

    本篇博客总结下Git使用情况中遇到的异常情况并给出解决方案,关于Git的常用命令请移步我的另一篇博客<Git常用命令> 异常情况如下: 1.git远程删除分支后,本地git branch ...

  10. linux下scrapy环境搭建

    最近使用scrapy做数据挖掘,使用scrapy定时抓取数据并存入MongoDB,本文记录环境搭建过程以作备忘 OS:ubuntu 14.04  python:2.7.6 scrapy:1.0.5 D ...