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


边栏推荐
- MySQL8--Windows下使用压缩包安装的方法
- Duplicate entry ‘XXX‘ for key ‘XXX.PRIMARY‘解决方案。
- 【LeetCode】104.二叉树的最大深度
- KICAD 小封装拉线卡顿问题 解决方法
- 【Koltin Flow(三)】Flow操作符之中间操作符(一)
- MySQL索引优化实战
- [LeetCode] 94. Inorder traversal of binary tree
- 架构:分布式任务调度系统(SIA-Task)简介
- DVWA安装教程(懂你的不懂·详细)
- WebShell connection tools (Chinese kitchen knife, WeBaCoo, Weevely) use
猜你喜欢
随机推荐
iVX低代码平台系列详解 -- 概述篇(二)
PHP WebSehll backdoor script and detection tool
Qt自定义控件和模板分享
mysql8.0.28下载和安装详细教程,适配win11
leetcode 143. 重排链表
Flask入门学习教程
[LeetCode] 94. Inorder traversal of binary tree
【LeetCode】1374. Generate a string with an odd number of each character
暴力破解全攻略
Flask 报错:WARNING This is a development server. Do not use it in a production deployment
MySQL8 -- use msi (graphical user interface) under Windows installation method
2022.8.1-----leetcode.1374
AcWing 1053. 修复DNA 题解(状态机DP、AC自动机)
Istio微服务治理网格的全方面可视化监控(微服务架构展示、资源监控、流量监控、链路监控)
非稳压 源特电子 隔离电源模块芯片 5W VPS8504B 24V
Hit the programmer interview scene: What did Baidu interviewers ask me?
消息队列经典十连问
isa指针使用详情
JSP Webshell 免杀
【LeetCode】104. Maximum depth of binary tree









