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

Maven简单的配置Junit测试及使用简单的mock的更多相关文章

  1. maven环境变量配置及测试

    首先要确认,你是否已经安装了jdk,并且已经成功配置了环境变量. 和java配置类似,计算机右键属性->高级系统设置->环境变量. 添加如下变量: 变量名:maven_home 变量值:C ...

  2. Maven学习笔记-02-Maven项目打包配置与测试

    一 Maven项目打包配置 1 为整个项目统一指定字符集 <properties> <project.build.sourceEncoding>UTF-</project ...

  3. maven编译的时候排除junit测试类

    maven项目中使用junit进行单元测试,在进行编译的时候,可以通过2种方式排除test测试类的编译. 有2种方式 : 使用命令的时候带上参数 mvn install -Dmaven.test.sk ...

  4. 【IDEA】单元测试:项目中引入JUnit测试框架+Mock简单了解

    一.Junit 使用和说明: 参考:单元测试第三弹--使用JUnit进行单元测试-HollisChuang's Blog http://www.hollischuang.com/archives/17 ...

  5. Spring4.2.3+Hibernate4.3.11整合( IntelliJ maven项目)(使用Annotation注解)(Junit测试类)

    1. 在IntelliJ中新建maven项目 给出一个建好的示例 2. 在pom.xml中配置依赖 包括: spring-context spring-orm hibernate-core mysql ...

  6. Javaspring+mybit+maven中实现Junit测试类

    在一个Javaspring+mybit+maven框架中,增加Junit测试类. 在测试类中遇到的一些问题,利用spring 框架时,里面已经有保密security+JWT设定的场合,在你的secur ...

  7. 《maven实战》笔记(2)----一个简单maven项目的搭建,测试和打包

    参照<maven实战>在本地创建对应的基本项目helloworld,在本地完成后项目结构如下: 可以看到maven项目的骨架:src/main/java(javaz主代码)src/test ...

  8. 【maven】之配置开发,测试,正式环境pom.xml文件

    在进行web程序开发,如果项目组没有使用自动化发布工具(jenkins + maven + svn + tomcat ),我们一般会使用maven的热部署来完成发布,在部署的过程中我们开发,测试,生产 ...

  9. 无废话Android之android下junit测试框架配置、保存文件到手机内存、android下文件访问的权限、保存文件到SD卡、获取SD卡大小、使用SharedPreferences进行数据存储、使用Pull解析器操作XML文件、android下操作sqlite数据库和事务(2)

    1.android下junit测试框架配置 单元测试需要在手机中进行安装测试 (1).在清单文件中manifest节点下配置如下节点 <instrumentation android:name= ...

随机推荐

  1. 单用户模式进入centos

    修改root密码----------------单用户模式操作 个人原创博客,转载请注明,否则追究法律责任 author: headsen chen date: 2017-9-30 1,开机后,迅速按 ...

  2. 微信小游戏 egret.getDefinitionByName获取不到

    使用getDefinitionByName获取类定义 输出为null,获取不了 增加window["LoadingUI"] = LoadingUI 获取成功 总结: 这样无论是游戏 ...

  3. Android dialog 全屏

    Android中让Dialog全屏: 一.在style中定义样式: <?xml version="1.0" encoding="utf-8"?> & ...

  4. Postgresql源码安装

    以在64位CentOS6.5操作系统上源码安装postgresql-9.6beta1为例 一.进入官网下载代码(postgresql-9.6beta1.tar.gz) https://www.post ...

  5. php中的魔术方法(Magic methods)和魔术常亮

    PHP中把以两个下划线__开头的方法称为魔术方法,这些方法在PHP中充当了举足轻重的作用. 魔术方法包括: __construct(),类的构造函数 __destruct(),类的析构函数 __cal ...

  6. CodeForces 651 C Watchmen

    C. Watchmen time limit per test 3 seconds memory limit per test 256 megabytes input standard input o ...

  7. sosi-statistics

    set echo offset scan onset lines 150set pages 66set verify offset feedback offset termout offcolumn ...

  8. string unicode utf8 ascii in python and js

    http://www.jb51.net/article/62155.htm http://www.cnblogs.com/dkblog/archive/2011/03/02/1980644.html ...

  9. VirtualBox Guest Additions installation

    在使用VirtualBox为CentOS安装增强功能时,输出是: 文本: Verifying archive integrity... All good. Uncompressing VirtualB ...

  10. python控制台输出颜色

    python_控制台输出带颜色的文字方法在开发项目过程中,为了方便调试代码,经常会向stdout中输出一些日志,默认的这些日志就直接显示在了终端中.而一般的应用服务器,第三方库,甚至服务器的一些通告也 ...