当前位置:网站首页>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方法
边栏推荐
- leetcode 143. 重排链表
- PHP WebShell Free Kill
- Tree Chain Segmentation-
- Recursively check if a configuration item has changed and replace it
- OperatingSystemMXBean to get system performance metrics
- 请教各位大佬,如果我代码里面设置了,这个id我在什么地方可以查到呢?连接到mysql cluste
- [LeetCode] 83. Delete duplicate elements in the sorted list
- MySQL索引优化实战
- 给你一个大厂面试的机会,你能面试上吗?进来看看!
- JSP Webshell 免杀
猜你喜欢
2W字!详解20道Redis经典面试题!(珍藏版)
Nacos源码分析专题(二)-服务注册
MySQL修改最大连接数限制
Istio微服务治理网格的全方面可视化监控(微服务架构展示、资源监控、流量监控、链路监控)
ROS2自学笔记:launch文件完整编写流程
How ReentrantLock works
mysql8.0.28 download and installation detailed tutorial, suitable for win11
analog IC layout-Parasitic effects
aws s3 upload file
WebShell连接工具(中国菜刀、WeBaCoo、Weevely)使用
随机推荐
MySQL8.0.28 installation tutorial
2W字!详解20道Redis经典面试题!(珍藏版)
7、MySQL Workbench 导出导入数据库
MySQL八股文背诵版
【LeetCode】145. Postorder Traversal of Binary Tree
Chrome浏览器无法加载已解压的.crx文件的解决办法
树链剖分-
剑指 Offer 14- I. 剪绳子
Swift运行时(派发机制)
Nacos源码分析专题(二)-服务注册
第10章_索引优化与查询优化
Recursively check if a configuration item has changed and replace it
PHP WebShell 免杀
请教各位大佬,如果我代码里面设置了,这个id我在什么地方可以查到呢?连接到mysql cluste
Curriculum Vitae;CV
暴力破解全攻略
AcWing 1053. Repair DNA problem solution (state machine DP, AC automata)
架构:应用架构的演进以及微服务架构的落地实践
JSP Webshell 免杀
Navicat cannot connect to database Mysql because of WiFi