当前位置:网站首页>2022-08-08 The fifth group Gu Xiangquan study notes day31-collection-junit unit test
2022-08-08 The fifth group Gu Xiangquan study notes day31-collection-junit unit test
2022-08-09 03:06:00 【aggressive leeks】
JUnit单元测试
Junit是一个Java语言的单元测试框架
Junit单元测试的好处
- A series of test methods can be written,Unit test all interfaces or methods of the project
- 启动后,自动化的测试
- Just need to see the final result
- The use cases of each unit test are relatively independent,有Junit启动
- 添加,删除,Testing of shielding methods
jar包
If the introduction is a third-party plug-in,xxx.jar的文件.
First, import this file into our project directory
凄恻,To be added to the project's since directory
测试方法
- There can be no return pride
- 不能有参数列表
- 必须有Test注解
Junit断言
JunitAll assertions of Assert类中
This class provides many useful assertions to write test cases
Only invalid assertions are logged
asserEquals:Check that the two variables or lighting are balanced
assertTrue:检查条件是否为真
assertFalse:Check if the field is home
assertNot Null:检查对象是否不为空
assertNull:检查对象是否为空
Before:在测试方法之前执行
After:在测试方法之后执行
命名规范:
The naming of the unit test class,被测试类的类名,Test
测试方法的命名,test + The method name of the method being tested
Junit4、Junit5,建议使用4
测试ArrayList与LinkedList
Test tail insertion efficiency(尾插100w个元素)
package com.jsoft.junit;
import org.junit.Test;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
public class Demo1 {
// 测试ArrayListTail insertion element efficiency
@Test
public void testArrayList() {
long begin = System.currentTimeMillis();
List<Integer> list = new ArrayList<>(1000000);
long end = System.currentTimeMillis();
for (int i = 0; i < 1000000; i++) {
list.add(i);
}
System.out.println("耗时:" + (end - begin) + "ms");
}
// 测试LinkedListTail insertion element efficiency
@Test
public void testLinkedList() {
List<Integer> list = new LinkedList<>();
long begin = System.currentTimeMillis();
for (int i = 0; i < 1000000; i++) {
list.add(i);
}
long end = System.currentTimeMillis();
System.out.println("耗时:" + (end - begin) + "ms");
}
}
We tested the results three times,取平均值
ArrayList耗时:1ms (1ms、1ms、1ms)
LinkedList耗时:108ms (115ms、105ms、103ms)
Test the efficiency of random retrieval(对10wrandom retrieval of data10w次)
package com.jsoft.junit;
import org.junit.Test;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
public class Demo1 {
// 测试ArrayListRandom retrieval element efficiency
@Test
public void testArrayList() {
// itit
Random r = new Random();
List<Integer> list = new ArrayList<>(100000);
for (int i = 0; i < 100000; i++) {
list.add(i);
}
// begin
long begin = System.currentTimeMillis();
for (int i = 0; i < list.size(); i++) {
list.get(r.nextInt(list.size()));
}
long end = System.currentTimeMillis();
System.out.println("耗时:" + (end - begin) + "ms");
}
// 测试LinkedListRandom retrieval element efficiency
@Test
public void testLinkedList() {
// itit
Random r = new Random();
List<Integer> list = new LinkedList<>();
for (int i = 0; i < 100000; i++) {
list.add(i);
}
// begin
long begin = System.currentTimeMillis();
for (int i = 0; i < list.size(); i++) {
list.get(r.nextInt(list.size()));
}
long end = System.currentTimeMillis();
System.out.println("耗时:" + (end - begin) + "ms");
}
}
We tested the results three times,取平均值
ArrayList耗时:ms (6ms、5ms、3ms)
LinkedList耗时:ms (5190ms、5158ms、5232ms)
边栏推荐
- SQL注入(1)
- 【洛谷】P1082 同余方程
- Building PO layered architecture of automated testing framework from 0
- C专家编程 第9章 再论数组 9.6 C语言的多维数组
- Zabbix 5.0 监控教程(五)
- Second data CEO CAI data warming invited to jointly organize the acceleration data elements online salon
- 多御安全浏览安卓版升级尝鲜,新增下载管理功能
- 7月更新速递 | 产品实验室N+1,EasyV For Unreal上线!
- 20220524搜索和排序:搜索二维矩阵II
- SQL注入(2)
猜你喜欢
深度学习:优化器
【CAS:41994-02-9 |Biotinyl Tyramide|】生物素基酪氨酰胺
关于eBPF与可观测性,你想知道的都在这里
开发工程师必备————【Day05】UDP协议;进程的并发与并行
365 days challenge LeetCode1000 topic - Day 051 special binary sequence partition
The building had been registry cluster, load balancing
Kubernetes:(十三)secret与configmap的那些事
2022微服务面试题 最新50道题(含答案解析)
OpenLORIS-Object Datasets
MVVM项目开发(商品管理系统二)
随机推荐
SA-SSD环境搭建——血与泪的教训
Hudi从内核到实战介绍
C专家编程 第9章 再论数组 9.1 什么时候数组与指针相同
CI/CD:持续集成/持续部署(难舍难分)
Building PO layered architecture of automated testing framework from 0
网路编程_socket返回值
phpStdudy的下载和DVWA的搭建
MVVM项目开发(商品管理系统二)
二分搜索法和二叉搜索树
非关系型数据库MongoDB:(二)副本集部署说明、数据迁移、限制内存、启用mongo认证
20220526动态规划:不同路径
Zabbix 5.0 监控教程(四)
Linux安装Redis
OpenLORIS-Object Datasets
【图像去噪】基于边缘增强扩散 (cEED) 和 Coherence Enhancing Diffusion (cCED) 滤波器实现图像去噪附matlab代码
Chrome的JSON美化插件
2021-07-21
SQLserver重新累计问题
unshift() :将一个或多个元素添加到数组的开头
Solve the Final Fantasy 13-2 Clock Puzzle with DFS