当前位置:网站首页>JunitTest单元测试
JunitTest单元测试
2022-08-02 02:56:00 【兄dei!】
1.Junit单元测试,用于测试自己写的类的方法是否有问题。
用法:
//被测试的类
public class MyUtils {
//加法
public int add(int a, int b){
return a-b;//故意写错
}
//减法
public int sub(int a,int b){
return a-b;
}
}
import org.junit.Test;//导入这个
@Test//加上Test注解,导入junit.test
public void testAdd(){
MyUtils U = new MyUtils();
// System.out.println(U.add(1,2));
//加个断言 如果结果是3说明正确
Assert.assertEquals(3,U.add(1,2));//前面是断言的结果,后面是实际的结果
}
@Test
public void testSub(){
MyUtils U = new MyUtils();
//加个断言 如果结果是3说明正确
Assert.assertEquals(3,U.add(6,3));
}
测试add方法(故意写错) 以及正确的sub方法
边栏推荐
猜你喜欢
随机推荐
Tree Chain Segmentation-
22-08-01 西安 尚医通(01)跨域配置、Swagger2、R类、统一异常处理和自定义异常、Logback日志
isa指针使用详情
analog IC layout-Environmental noise
淘宝详情.
mysql8.0.28 download and installation detailed tutorial, suitable for win11
svm.SVC应用实践1--乳腺癌检测
第10章_索引优化与查询优化
cadence landscape bindkey
PHP WebSehll backdoor script and detection tool
【每日一道LeetCode】——1. 两数之和
【LeetCode】206.反转链表
搭建zabbix监控及邮件报警(超详细教学)
* 比较版本号
WebShell Feature Value Summary and Detection Tool
消息队列经典十连问
PHP WebShell 免杀
esp32经典蓝牙和单片机连接,,,手机蓝牙作为主机
"Paid paddling" stealthily brushes Brother Ali's face scriptures, challenges bytes three times, and finally achieves positive results
mysql使用on duplicate key update批量更新数据