当前位置:网站首页>单体测试使用Assert.assertThat(expected,Matcher matcher)来对比结果和预期
单体测试使用Assert.assertThat(expected,Matcher matcher)来对比结果和预期
2022-04-21 13:24:00 【zhangsan3333】
hamcrest core 1.3.jar和junit 4.12.jar
JUnit4.11和hamcrest-core-1.3 搭建自己的测试环境(非eclipse内置Junit)
package test.Demo;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
public class CalculatorTest {
@Test
public void add() {
int result = new Calculator().add(1,3);
Assert.assertEquals(4,result);
}
@Test
public void sub() {
int result = new Calculator().sub(1,3);
Assert.assertEquals(-2,result);
}
@Test
public void divide(){
int result = new Calculator().divide(3,1);
Assert.assertThat(result, Matchers.is(4));
}
}
package test.Demo;
public class Calculator {
public int add(int a, int b) {
return a + b;
}
public int sub(int a, int b) {
return a - b;
}
public int divide(int a,int b){
return a/b;
}
}

版权声明
本文为[zhangsan3333]所创,转载请带上原文链接,感谢
https://blog.csdn.net/djydjy3333/article/details/124318319
边栏推荐
- Detailed explanation of Flink related API development and operation architecture and implementation principle
- The return value of [SV] function is a parameterized function of variable matrix
- OJ daily practice - output new array in reverse order
- LLVM之父Chris Lattner:编译器的黄金时代
- 36 day assault Tencent finally took the offer! Redis, high concurrency
- Wang Baiping: my way to envoy maintainer
- S: Unit gain compensation
- Algorithem_ Populating Next Right Pointers in Each Node
- 3-4Dom形XSS详解以及演示
- [C#]给地球来点光
猜你喜欢

Small and medium-sized manufacturing enterprises transformation capacity-building sharing
![[digital signal processing] linear constant coefficient difference equation (use matlab to solve the example of](/img/7c/20f38a030de8ba25d91163d851822a.png)
[digital signal processing] linear constant coefficient difference equation (use matlab to solve the example of "linear constant coefficient difference equation" | a vector analysis | B vector analysi

S: Unit gain compensation

Elements of network

3、 Label preparation

Can great talents be of little use? Oceanbase integration scenario test

实战ora2pg迁移oracle11g到pg12.4

跑步运动耳机哪个牌子好、适合运动的耳机

Flink相关API开发及运行架构和实现原理详解

Go语言 文件操作
随机推荐
20210818 diary
LLVM之父Chris Lattner:编译器的黄金时代
Go language file operation
Flink相关API开发及运行架构和实现原理详解
3、 Label preparation
【数字信号处理】线性常系数差分方程 ( 使用 matlab 求解 “ 线性常系数差分方程 “ 示例 | A 向量分析 | B 向量分析 | 输入序列分析 | matlab 代码 )
After the completion of hundreds of millions of yuan of financing, smart bank plans to land urban intelligent driving products in more than 100 cities
Which brand of running headphones is good and suitable for sports
After the completion of hundreds of millions of yuan of financing, smart bank plans to land urban intelligent driving products in more than 100 cities
美创科技受邀为海淀区教育科学研究院开展数据安全培训
Wireless network protocol terms
(recommended intensive reading) this refers to the north
JDBC 驱动升级到 Version 8.0.28 连接 MySQL 的踩坑记录
【csnote】db异常(冗余数据、修改异常、删除异常、插入异常)
[traitement du signal numérique] coefficient de corrélation (analyse conceptuelle du coefficient de corrélation | constante d'énergie du signal | séquence conjuguée | corrélation de la séquence au mêm
[digital signal processing] linear constant coefficient difference equation (determine whether the system is a "linear time invariant system" according to "linear constant coefficient difference equat
万字干货!帮你深度掌握设计中的「光影」知识点
运动耳机什么样的舒服、运动健身耳机推荐
News compendium of foreign Internet products last week - Angel
L2-013 红色警报 (25 分)

