通过junit写unit test
how to run test within junit & mvn:
During team development , there are more than 1 person edit your api or file which it's very common. And to improve your api stablity and quality, it's critical important to write unit test.
run all test
mvn test
run specific test
Sometimes we have thousands of unit test, but you need to test only some testcase you have just wrote for verify some case you can specific your only test case:
mvn -Dtest=TestApp1 test
run exclude some specific case
Meanwhile you may exclude some unrelated test case(or include some test case) for a quick verify.
for example, skip TestApp2.java, edit your pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<excludes>
<exclude>**/TestApp2.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins> </build>
serval common case log:
- when not pass test:
Running com.wade.core.TestApp1 Tests run: 1, Failures: 1, Errors: 0,
Skipped: 0, Time elapsed: 0.091 sec <<< FAILURE!
testHelloworld(com.wade.core.TestApp1) Time elapsed: 0.022 sec <<<
FAILURE! junit.framework.ComparisonFailure: expected:<Hello[W]orld>
but was:<Hello[w]orld> at
junit.framework.Assert.assertEquals(Assert.java:100)
- pass test:
Running com.wade.core.TestApp1 Tests run: 1, Failures: 0, Errors: 0,
Skipped: 0, Time elapsed: 0.093 sec Running com.wade.core.TestApp2
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 secResults :
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
- compile error:
[INFO] BUILD FAILURE [INFO]
------------------------------------------------------------------------ [INFO] Total time: 1.392 s [INFO] Finished at:
2016-07-10T23:15:34+08:00 [INFO] Final Memory: 14M/165M [INFO]
------------------------------------------------------------------------ [ERROR] Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile
(default-testCompile) on project unittest: Compilation failure:
Compilation failure: [ERROR]
/Users/dengwei/projects/github/javacourse/unittest/src/test/java/com/wade/TestApp2.java:[8,61]
';' expected [ERROR]
/Users/dengwei/projects/github/javacourse/unittest/src/test/java/com/wade/TestApp1.java:[8,59]
';' expected [ERROR] -> [Help 1] [ERROR]
Appendix:
通过junit写unit test的更多相关文章
- 写好unit test的建议和例子
最近翻了下写unit test 的文章,总结如下 What's unit test? "Unit testing is a software testing method by which ...
- 使用 JUnit 进行单元测试 - 教程
tanyuanji@126.com 版本历史 JUnit 该教程主要讲解 JUnit 4.x 版本的使用,以及如何在Eclipse IDE 中如何使用JUnit 目录 tanyuanji@126. ...
- Junit概述
Junit -> java unit.也就是说Junit是xunit家族中的一员. unit <- unit test case,即单元测试用例. Junit = java uni ...
- Maven的安装配置及初次创建项目与java单元测试工具JUnit
Maven 安装 1.把maven安装包解压到某个位置 2.配置M2_HOME环境变量指向这个位置 3.在path环境变量中添加;%M2_HOME%\bin 配置镜像 国内的阿里云镜 ...
- Java学习:Junit简介
Junit简介 概述: JUnit 是用于编写和运行可重复的自动化测试的开源测试框架,这样可以保证我们的代码按预期工作.JUnit 可广泛用于工业和作为支架(从命令行)或IDE(如 IDEA)内单独的 ...
- 积极主动敲代码,使用Junit学习Java程序设计
积极主动敲代码,使用JUnit学习Java 早起看到周筠老师在知乎的回答软件专业成绩很好但是实际能力很差怎么办?,很有感触. 从读大学算起,我敲过不下100本程序设计图书的代码,我的学习经验带来我的程 ...
- 关于intellij IDEA 上junit的用法
话说,最近正在看视频学java.里面有个叫做junit的东西很有用.但是实话说我摆弄了半天都没弄明白. 今天呢通过一些资料,终于弄清楚了junit的大致用法,这里写出来,用以分享和备忘. 首先,环境和 ...
- How to Use JUnit With JMeter
Do you need to use JUnit in your testing processes? To answer this question, let's take a look first ...
- java单元测试(使用junit)
JUnit是由 Erich Gamma 和 Kent Beck 编写的一个回归测试框架(regression testing framework),供Java开发人员编写单元测试之用. 1.概述 Ju ...
随机推荐
- python入门(四)
今天主要记录下python中文件的编辑与函数. 一.修改文件 一)简单粗暴--直接修改 1.打开一个文件,获取到所有内容2.对内容进行修改3.清空原来的文件4.把新的内容写进去 f = open('u ...
- Scrapy中间件user-agent和ip代理使用
一.定义实现随机User-Agent的下载中间件 1.在middlewares.py中完善代码 import random from Tencent.settings import USER_AGEN ...
- for ,foreach ,map 循环的区别
一.for循环 1.for - 循环代码块一定的次数 遍历数组最常用到的for循环,是最为熟知的一种方法 for (var i=0; i<5; i++) { x=x + "The nu ...
- CG-ctf WP
week one 1 /x00 提示:有多种解法,你能找到几种 源码: writer up: 题目直接给出了源码,get 到一个 nctf 这个变量,int ereg(string pattern, ...
- day03 int bool str
1. 昨日内容回顾 1. while循环 语法: while 条件: 循环体 else: 语句块 执行过程:判断条件是否为真. 如果真, 执行循环体.然后再次判断条件... 直到条件为假循环停止 br ...
- selenium3 - Tomcat and jenkins
一.Tomcat的学习 1.tomcat 下载地址:tomcat.apache.org 2.配置tomcat环境变量: 新建系统变量 - 变量名:CATALINA_HOME 变量值:D:\TO ...
- 解决Exception in thread "main" java.nio.BufferOverflowException报错
学习bytebuffer时,写了简单的demo报错: 错误的提示:Exception in thread "main" java.nio.BufferOverflowExcepti ...
- 国内第一本cbuilder开发web的宝典震撼登场(delphi也可参考)
uniGUI入门到精通cBuilder版 众所周知,cbuilder和delphi是曾经风靡多年的强悍的万能的开发工具,岂奈大浪淘沙,B/S时代的到来让这对孪生兄弟隐姓埋名.然,无数风流人物依然对他们 ...
- MAVEN项目不扫描mybatis的mapper.xml问题
在使用maven+mybatis+spring在开发的时候,遇到问题,总是找不到mapper.xml文件里定义的方法.检查后发现maven编译后并没有将xml文件打包到输出路径,导致bean创建失败. ...
- 《贝贝GO》服务条款
服务条款 一.服务条款的确认与接收 1.贝贝GO客户端软件(以下简称“本软件”)各项电子服务的所有权和运作权归属于“东莞市山水信息技术有限公司”(以下称“本公司”)所有,本软件提供的服务将完全按照其发 ...