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. 基于react的MQ管理系统遇到的问题以及解决办法

    跟一般的管理系统差不多 一.需求 1.新增申请和修改的弹窗里面的部门跟应用组改成下拉框,并调取后台接口获取到相应的值.1.1相应的代码 // 获取部门 getDepartment = () => ...

  2. Spring 发送内嵌图片的邮件 遇到的问题

    问题1:spring 发送带图片的html格式的邮件? 解决方法1:直接在发送内容里面添加 <img src="http://www.rgagnon.com/images/jht.gi ...

  3. pseudo-class与pseudo-element的不同点与相同点

    关于两者的区别,其实是很古老的问题.但是时至今日,由于各种网络误传以及一些不负责任的书籍误笔,仍然有相当多的人将伪类与伪元素混为一谈,甚至不乏很多CSS老手.早些年刚入行的时候,我自己也被深深误导,因 ...

  4. java基础知识—字符串

    1.声明字符串的方法: String s ="你好" String s=new String("你好"); 2.字符串的长度: 字符串.length(); 3. ...

  5. 2—ARM中的异常中断

    ARM体系中的3种控制程序执行的方式 正常执行过程中,每执行1条ARM指令,PC的值加4个字节:每执行1条Thumb指令,PC的值加2个字节.整个过程按照顺序执行. 通过跳转指令,调到特定的地址开始执 ...

  6. [.NET] 使用ValidationContext快速进行模型资料的验证

    在进行WebAPI功能开发的时候,一般传统的验证资料是否合法的方式,都是透过if/else的方式进行判断若是使用ValidationContext,就可以省去很多自行撰写程式码的工作 要使用Valid ...

  7. CG-ctf WP

    week one 1 /x00 提示:有多种解法,你能找到几种 源码: writer up: 题目直接给出了源码,get 到一个 nctf 这个变量,int ereg(string pattern, ...

  8. python常见的数据转化函数

    python常用类型转换函数 函数格式 使用示例 描述 int(x [,base]) int("8")   可以转换的包括String类型和其他数字类型,但是会丢失精度       ...

  9. Struts2配合layui多文件上传--下载

    先说上传: 前台上传文件的js代码: var demoListView = $('#demoList') ,uploadListIns = upload.render({ elem: '#testLi ...

  10. GoGland 快捷键说明

    关于Gogland一些常用快捷键的说明,我在网上没有搜索到,于是乎,我找到了官网中的视频介绍,然后将其中的一部分摘录了出来,希望能帮住大家... Gogland——使用说明前面是苹果|后面是linux ...