当前位置:网站首页>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方法


边栏推荐
- 常见的SQL面试题:经典50例
- 2022.8.1-----leetcode.1374
- Nacos source code analysis topic (2) - service registration
- Curriculum Vitae;CV
- 2022牛客多校三_F G
- Recursively check if a configuration item has changed and replace it
- 架构:微服务网关(SIA-Gateway)简介
- [LeetCode] 83. Delete duplicate elements in the sorted list
- * 比较版本号
- 2W字!详解20道Redis经典面试题!(珍藏版)
猜你喜欢
随机推荐
mysql8.0.28 download and installation detailed tutorial, suitable for win11
DVWA之SQL注入
1688API
Go语学习笔记 - gorm使用 - 原生sql、命名参数、Rows、ToSQL Web框架Gin(九)
MySQL8.0.28 installation tutorial
ROS2自学笔记:launch文件完整编写流程
2W字!梳理50道经典计算机网络面试题(收藏版)
【LeetCode】145.二叉树的后序遍历
最大层内元素和
7、MySQL Workbench 导出导入数据库
【LeetCode】20. Valid parentheses
esp32经典蓝牙和单片机连接,,,手机蓝牙作为主机
ReentrantLock工作原理
2022牛客多校三_F G
ASP WebShell 后门脚本与免杀
MySQL8--Windows下使用压缩包安装的方法
Flask入门学习教程
"Paid paddling" stealthily brushes Brother Ali's face scriptures, challenges bytes three times, and finally achieves positive results
【每日一道LeetCode】——9. 回文数
PHP WebSehll backdoor script and detection tool









