当前位置: 首页 > news >正文

【Java】DT怎么写?

  1. 几个重要的注解
    在这里插入图片描述

  2. 怎么用mockito写单元测试?

package Biz;import Client.FileIOClient;
import Req.FileRequest;
import Res.FileResponse;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;/*** @Author:TieJiang* @Date: 2021/1/19 8:44 下午* 人一能之,己十之,人十能之,己百之,果能此道矣,虽愚必明,虽柔必强。*/
@RunWith(MockitoJUnitRunner.class)
public class FileIOBizTest {@InjectMocksFileIOBiz fileIOBiz;@MockFileIOClient fileIOClient;@Testpublic void getFile() {
//        Mock阶段
//        构造参数FileRequest request = new FileRequest();request.setName("Title");
//        Mock Clientwhen(fileIOClient.FileRead(any())).thenReturn(5);when(fileIOClient.FileWrite(any())).thenReturn(5);//        Mock结果,进行校验:结果一定是根据现有逻辑能判断出来的FileResponse response = fileIOBiz.GetFile(request);Assert.assertNotNull(response);Assert.assertEquals(response.getValue(),"5 5");}
}

参考代码:https://github.com/OriKey/MockTutorials/tree/master

  1. 怎么写SpringRunner的单元测试?
@RunWith(SpringRunner.class) //14.版本之前用的是SpringJUnit4ClassRunner.class
@SpringBootTest(classes = Application.class) //1.4版本之前用的是//@SpringApplicationConfiguration(classes = Application.class)
public class SystemInfoServiceImplTest {@Autowiredprivate ISystemInfoService systemInfoservice;@Testpublic void add() throws Exception {}@Testpublic void findAll() throws Exception {}}

pom文件:

<!--spring-test测试=--><dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId><version>4.3.7.RELEASE</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-test</artifactId><version>1.5.9.RELEASE</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version></dependency>

参考:
https://blog.csdn.net/qq_43547991/article/details/119997923
https://blog.csdn.net/sliping123/article/details/83817737

http://www.lryc.cn/news/34376.html

相关文章:

  • xcode14安装swift package设置github账户token
  • css面试题1
  • Hive基础
  • 信息收集-
  • 【sdx12】sdx12获取Serial Number操作方法及源码分享Serial Number的寄存器地址
  • 23种设计模式-工厂模式(安卓应用场景介绍)
  • sheng的学习笔记-服务熔断与降级组件Hystrix
  • 简单给WordPress怎么添加自定义字段面板
  • 大数据框架之Hive:第6章 查询
  • CentOS 8搭建EMQX集群
  • 基于神经网络的自监督学习方法音频分离器(Matlab代码实现)
  • yocto 如何添加python module
  • [深入理解SSD系列综述 2.1.2] SLC、MLC、TLC、QLC、PLC NAND_固态硬盘闪存颗粒类型
  • Matlab实现FFT变换
  • JVM调优面试题——垃圾回收专题
  • java启动命令中-D和--的区别
  • QML Popup详解
  • [2.1.6]进程管理——线程的实现方式和多线程模型
  • 小白做什么兼职项目赚钱?宝妈拍短视频赚钱的方法
  • 第十四届蓝桥杯第三期模拟赛 C/C++ B组 原题与详解
  • Linux中断操作
  • 看看CabloyJS是如何异步加载并执行go wasm模块的
  • 嵌入式C语言九大数据结构操作方式详解
  • 【C++学习】栈 | 队列 | 优先级队列 | 反向迭代器
  • Python—看我分析下已经退市的 可转债 都有什么特点
  • 【第八课】空间数据基础与处理——数据结构转化
  • MATLAB绘制三Y轴坐标图:补充坐标轴及字体设置
  • springboot项目中Quartz
  • Presto本地开发,plugin的设置
  • 2023年3月西安/杭州/深圳/东莞NPDP产品经理认证考试报名