1、maven依赖配置如下

        <dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>RunJob</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
</plugin>
</plugins>
</build>

2、编写测试代码

public class SimpleTest {
@Test
public void test() {
Assert.assertTrue("a".equals("a"));
} @Test
public void testMock() {
List m = mock(List.class);
m.add(1);
m.clear(); verify(m).add(1);//验证执行过add(1)操作
verify(m).clear();//验证执行过clear操作
} @Test
public void when_thenReturn() {
//mock一个Iterator类
Iterator iterator = mock(Iterator.class);
//预设当iterator调用next()时第一次返回hello,第n次都返回world
when(iterator.next()).thenReturn("hello").thenReturn("world");
//使用mock的对象
String result = iterator.next() + " " + iterator.next() + " " + iterator.next();
//验证结果
assertEquals("hello world world", result);
}
}

最新文章

  1. 1.把二元查找树转变成排序的双向链表[BST2DoubleLinkedList]
  2. 虚拟机下samba简单安装配置
  3. php基础21:上传文件
  4. 淘宝(阿里百川)手机客户端开发日记第六篇 Service详解(二)
  5. MySQL(二) —— 数据类型与操作数据表
  6. Educational Codeforces Round 1(C. Nearest vectors)
  7. Java学习系列(一)Java的运行机制、JDK的安装配置及常用命令详解
  8. Ubuntu12.10 下搭建基于KVM-QEMU的虚拟机环境(十三)
  9. unity3d NGUI入门(描述和使用插件参数)
  10. [每日一题] OCP1z0-047 :2013-07-19 Rules of Precedence――括号的使用
  11. 【WCF】错误处理(三):错误协定
  12. a.变量及基本数据结构
  13. net user命令详解
  14. java宜立方商城项目
  15. Jenkins + Gradle + pgyer + Android自动发布
  16. yield(),wait(),sleep(),join()
  17. flex学习笔记 使用函数,显示实时更新的标签
  18. [Python 从入门到放弃] 1. 列表的基本操作
  19. 【Asp.net入门06】第一个ASP.NET 应用程序-案例说明
  20. 使用mysql遇到的异常

热门文章

  1. Redis字符串类型的操作
  2. 关于Visual Studio 20**自动添加头部注释信息
  3. OC开发_代码片段——使用Xib自定义tableViewCell
  4. ST-LINK使用注意
  5. 【HTTP header】【Access-Control-Allow-Credentials】跨域Ajax请求时是否带Cookie的设置
  6. mysql GROUP_CONCAT 用法
  7. Spring Boot - Building RESTful Web Services
  8. elk----es settings--logstash--performance---bigdesk---logstash plugin online/offline
  9. ES_DEVOPS-1
  10. 【Javascript】Windows下Node.js与npm的安装与配置