初识junit
来源:互联网 发布:vb.net 获取网页内容 编辑:程序博客网 时间:2024/06/06 00:08
eclipse自带了junit的jar包,另外可以下载最新版本的jar导入到项目中
1、junit-4.12.jar
2、hamcrest-core-1.3.jar
3、hamcrest-library-1.3.jar
package com.dw.junit4.test;import static org.junit.Assert.*;import static org.hamcrest.Matchers.*;//在hamcrest-library-1.3.jar下import org.junit.Test;import com.dw.junit4.T;public class TTest {@Testpublic void test() {int t = new T().add(3, 5);assertEquals(8, t);assertThat(t, is(8));assertThat(t, allOf(greaterThan(3),lessThan(15)));assertThat(t, anyOf(greaterThan(20),lessThan(9)));assertThat(t, anything());assertThat("zhangsan",is("zhangsan"));assertThat("zhangsan",not("zhangsan2"));assertThat("zhangsan",containsString("an"));}}
使用hamcrest中的断言方法,更加自然
最常用的方法是assertThat ,如:
org.junit.Assert下的部分方法:
org.hamcrest.Matchers下的部分方法:
其中,BeforeClass和AfterClass必须对应的是静态方法。
阅读全文
0 0
- 初识JUnit
- 初识JUnit
- 初识junit
- 初识 JUnit 4.0
- 初识Junit(单元测试)
- 初识IntelliJ IDEA下JUnit单元测试
- 初识IntelliJ IDEA下JUnit单元测试
- 初识stub和mock--junit的两种测试策略
- JUNIT
- junit
- Junit
- JUnit
- JUnit
- JUnit
- JUNIT
- junit
- Junit
- JUnit
- VirtualBox 报错VERR_VD_IMAGE_READ_ONLY
- Linux系统变慢原因?
- 关于安卓蓝牙2.0的app开发原理
- 计蒜客 2017 NOIP 提高组模拟赛(二)Day1 A. 邻家男孩
- 数组的初始化方式
- 初识junit
- activiti学习--04流程定义:流程定义组成+部署流程定义+查询流程定义+删除流程定义+删除流程定义+查询最新版本的流程定+查询最新版本的流程定义
- 互联网新闻报道中的突发事件识别研究
- Tensorflow--逻辑回归
- LeetCode:M-36. Valid Sudoku
- nvm、nrm、npm 安装和使用详解
- C++构造函数成员初始值问题
- 批处理
- 测试工具--给自己备份学习