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 sec

Results :

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的更多相关文章

  1. 写好unit test的建议和例子

    最近翻了下写unit test 的文章,总结如下 What's unit test? "Unit testing is a software testing method by which ...

  2. 使用 JUnit 进行单元测试 - 教程

    tanyuanji@126.com 版本历史 JUnit 该教程主要讲解 JUnit 4.x 版本的使用,以及如何在Eclipse IDE 中如何使用JUnit   目录 tanyuanji@126. ...

  3. Junit概述

    Junit ->  java unit.也就是说Junit是xunit家族中的一员. unit   <- unit test case,即单元测试用例. Junit  = java uni ...

  4. Maven的安装配置及初次创建项目与java单元测试工具JUnit

    Maven  安装     1.把maven安装包解压到某个位置     2.配置M2_HOME环境变量指向这个位置 3.在path环境变量中添加;%M2_HOME%\bin 配置镜像 国内的阿里云镜 ...

  5. Java学习:Junit简介

    Junit简介 概述: JUnit 是用于编写和运行可重复的自动化测试的开源测试框架,这样可以保证我们的代码按预期工作.JUnit 可广泛用于工业和作为支架(从命令行)或IDE(如 IDEA)内单独的 ...

  6. 积极主动敲代码,使用Junit学习Java程序设计

    积极主动敲代码,使用JUnit学习Java 早起看到周筠老师在知乎的回答软件专业成绩很好但是实际能力很差怎么办?,很有感触. 从读大学算起,我敲过不下100本程序设计图书的代码,我的学习经验带来我的程 ...

  7. 关于intellij IDEA 上junit的用法

    话说,最近正在看视频学java.里面有个叫做junit的东西很有用.但是实话说我摆弄了半天都没弄明白. 今天呢通过一些资料,终于弄清楚了junit的大致用法,这里写出来,用以分享和备忘. 首先,环境和 ...

  8. 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 ...

  9. java单元测试(使用junit)

    JUnit是由 Erich Gamma 和 Kent Beck 编写的一个回归测试框架(regression testing framework),供Java开发人员编写单元测试之用. 1.概述 Ju ...

随机推荐

  1. python入门(五)

    一.函数返回值 1.函数如果返回多个值,他会把这几个值放到一个元组里面 2.也可以用多个变量来接收 返回多个值放到元组里面 def say(): num1=1 num2=2 num3=3 return ...

  2. SpringSecurity简单记录

    在pom.xml中将springsecurity导入后,对于springsecurity会出现三个依赖包:spring-security-web,spring-security-config,spri ...

  3. ConcurrentHashMap实现原理

    ConcurrentHashMap是Java并发包中提供的一个线程安全且高效的HashMap实现(若对HashMap的实现原理还不甚了解,可参考我的另一篇文章HashMap实现原理及源码分析),Con ...

  4. ffmpeg使用示例

    /* 视频格式转换 ffmpeg -i "F:\Test\1.mp4" -y -vcodec copy -acodec copy "F:\Test\11.avi" ...

  5. Main Steps to Setup an ODI data sync

    0. Get ODI installed 1. Topo physical Architecture/new physical schema 2. New Logical schema 3. New ...

  6. angular.js 渲染

    angular.js 小常识   具体看代码,转载请备注来源. html结构 <%@ page language="java" contentType="text/ ...

  7. servlet操作本地文件汇总: 判断文件是否存在;文件重命名;文件复制; 获取文件属性信息,转成Json对象; 获取指定类型的文件; 查找替换.txt中的文本

    package servlet; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; ...

  8. JS的作用域链与原型链

    来一波,好记性不如烂笔头. 这两条链子可是很重要的. 作用域链 当执行一段JS代码(全局代码或函数)时,JS引擎会创建为其创建一个作用域又称为执行上下文(Execution Context),在页面加 ...

  9. jmeter下载和配置

    一.下载 1.进入官网:http://jmeter.apache.org/ 3.环境变量相关配置 电脑桌面---->“计算机”图标---->鼠标右键选择“属性”---->点击高级系统 ...

  10. Groovy学习笔记-陷阱

    1.def和in是关键字 2.==映射到了equals() 中,如果有Comparable接口实现,则优先compareTo str1 = 'hello' str2 = str1 str3 = new ...