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. 显式拥塞通告(ECN)及其在Linux上的实现

    1 ECN简介 首先看看ECN握手报文的特点,根据RFC3168,ECN握手报文IP头部不能够设置ECT和CE位的 SYN报文TCP标志字段的CWR和ECE位被置1 SYN-ACK报文的CWR位被置0 ...

  2. OTP gen_server

    erlang behaviour小结之gen_server OTP入门 分类: Erlang2012-08-06 18:55 867人阅读 评论(0) 收藏 举报 servererlangcallba ...

  3. Eclipse远程调试+FTPClient在jdk6以上写法不兼容问题的排查

    业务场景: 应业务新需求的UAT测试,需要部署一份新tomcat到测试环境.新环境正常启动并运行了一天,没太大差错.但今天发现原本在另一个老的tomcat下运行的好好的FTP上传文件模块突然出了问题. ...

  4. centos7 eclispe 编译C++遇到的问题总结

    最近由于工作的需要,又开始回归之前已经遗忘了的技术.arm嵌入式这个古老的名词. 开始选择了linuxminit,开始的linuxminit17以前还可以,可是用了一下linuxminit19,发现r ...

  5. flask记录

    flask文件上传 flask 文件上传  https://www.cnblogs.com/wongbingming/p/6802660.html flask多文件上传:https://blog.cs ...

  6. NVCC src/caffe/util/math_functions.cu

    解决办法:由于安装的cuda版本是7.5,当前下载的caffe版本比较新,需要修改里面的makefile文件,屏蔽下面的代码,cuda<8.0 In the Makefile.example, ...

  7. 图数据库Neo4j

    官网下载:https://neo4j.com/download/ 图数据库Neo4j入门:https://blog.csdn.net/gobitan/article/details/68929118 ...

  8. 芯片烧录器编程AT24C02

    网上买了两款芯片烧录器,因为项目用的到.芯片以后的类型可能是IIC 接口的.就选则了一个IIC接口的AT24C02EEPROM.进行尝试.手头上没有这款芯片. 就想起自己单片机上有这款芯片.然后就开始 ...

  9. Groovy学习笔记-陷阱

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

  10. MAVEN项目不扫描mybatis的mapper.xml问题

    在使用maven+mybatis+spring在开发的时候,遇到问题,总是找不到mapper.xml文件里定义的方法.检查后发现maven编译后并没有将xml文件打包到输出路径,导致bean创建失败. ...