通过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 ...
随机推荐
- FX-玩列表
list = []while True: meus = ("1.查看","2.添加","3.删除","0.退出") pr ...
- JS中的变量和数据类型
所谓变量,就是里面存储的数据是可以改变的. 在使用变量之前,我们需要先声明变量.声明变量的关键字有var let const 在ES里面声明变量可以使用var,如下: //var 变量名 var ...
- jmeter遇到问题及解决办法
1.要得到前一个sampler的响应信息,是加beanshell sampler 还是加beanshell postprocessor? 答:在http取样器后添加beanshell sample ...
- my goal
I want to get a good command of a programming language at the university, and I have to pass the tes ...
- 5、AngularJS 直接绑定显示html ($sce、$sanitize服务)
1.直接使用$sce服务(angularjs中:$sce.trustAsHtml($scope.snippet).html:ng-bind-html="snippet") 以下代码 ...
- maven profile实现多环境配置
每次项目部署上线都需要手动去修改配置文件(比如数据库配置,或者一个自定义的配置)然后才能打包,很麻烦,网上找到 maven profile可以完成这个工作,记录如下: 环境:eclipse + spr ...
- 棋盘(noip2017普及组)
题目描述 有一个m \times mm×m的棋盘,棋盘上每一个格子可能是红色.黄色或没有任何颜色的.你现在要从棋盘的最左上角走到棋盘的最右下角. 任何一个时刻,你所站在的位置必须是有颜色的(不能是无色 ...
- tcp 与udp 的区别
1.TCP和UDP对比 TCP(Transmission Control Protocol)可靠的.面向连接的协议(eg:打电话).传输效率低全双工通信(发送缓存&接收缓存).面向字节流.使用 ...
- Beta冲刺 7
前言 队名:拖鞋旅游队 组长博客:https://www.cnblogs.com/Sulumer/p/10129067.html 作业博客:https://edu.cnblogs.com/campus ...
- dubbo入门学习笔记之环境准备
粗略的学完springcloud后由于公司的项目有用到一点dubbo,刚好手头上又有dubbo的学习资料,于是趁机相对系统的学了下duboo框架,今天开始记录下我的所学所悟;说来惭愧,今年之前,作为一 ...