testng + mockito + spring boot test 基本操作

news/2024/9/24 7:21:49

代码地址

https://gitee.com/bzrj/thresh-boot

如何使用

  1. thresh-dependencies 目录执行 mvn clean install
  2. 在跟目录执行 make

效果

jacoco

image

image

allure

image

image

关键配置

thresh-test

  1. 此模块包含了测试需要的依赖
  2. 定义了两个 testng 监听

thresh-report

此模块专门用于聚合 jacoco 和 allure 的报告

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>com.laolang.thresh</groupId><artifactId>thresh-boot</artifactId><version>${revision}</version></parent><artifactId>thresh-report</artifactId><dependencies><dependency><groupId>com.laolang.thresh</groupId><artifactId>thresh-module-system-biz</artifactId></dependency><dependency><groupId>com.laolang.thresh</groupId><artifactId>thresh-module-auth-biz</artifactId></dependency></dependencies><build><plugins><!-- 生成聚合报告 --><plugin><groupId>org.jacoco</groupId><artifactId>jacoco-maven-plugin</artifactId><executions><execution><id>prepare-agent</id><goals><goal>prepare-agent</goal></goals></execution><execution><id>report</id><phase>test</phase><goals><goal>report-aggregate</goal></goals></execution></executions></plugin></plugins></build>
</project>

模块 pom

注意:
由于使用了 powermock , 所以需要使用 jacoco 的 offline 模式

    <build><plugins><plugin><groupId>org.jacoco</groupId><artifactId>jacoco-maven-plugin</artifactId><version>${jacoco-maven-plugin.version}</version><executions><execution><id>default-instrument</id><goals><goal>instrument</goal></goals></execution><execution><id>default-restore-instrumented-classes</id><goals><goal>restore-instrumented-classes</goal></goals></execution><execution><id>pre-test</id><goals><goal>prepare-agent</goal></goals></execution><execution><id>post-test</id><phase>prepare-package</phase><goals><goal>report</goal></goals><configuration><dataFile>${project.build.directory}/jacoco.exec</dataFile></configuration></execution></executions></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>${maven-surefire-plugin.version}</version><configuration><argLine>-Dfile.encoding=UTF-8-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"</argLine><testFailureIgnore>true</testFailureIgnore><systemPropertyVariables><jacoco-agent.destfile>${project.build.directory}/jacoco.exec</jacoco-agent.destfile></systemPropertyVariables><!--生成allure-result的目录--><systemProperties><!--是否忽略html,解释见下图。与之后在reportNg报告上显示截图相关。当前已经使用allure了,这里可以直接去掉啦--><!--<org.uncommons.reportng.escape-output>false</org.uncommons.reportng.escape-output>--><!--定义输出在项目 target 目录--><property><name>allure.results.directory</name><value>target/allure-results</value></property></systemProperties><suiteXmlFiles><!--该文件位于工程根目录时,直接填写名字,其它位置要加上路径--><suiteXmlFile>${xmlFileName}</suiteXmlFile></suiteXmlFiles></configuration></plugin></plugins></build>

根目录

用于配置插件依赖

    <build><finalName>${project.artifactId}</finalName><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>${maven-compiler-plugin.version}</version><configuration><source>${maven.compiler.source}</source><target>${maven.compiler.target}</target><encoding>${project.build.sourceEncoding}</encoding></configuration></plugin></plugins><pluginManagement><plugins><plugin><groupId>org.jacoco</groupId><artifactId>jacoco-maven-plugin</artifactId><version>${jacoco-maven-plugin.version}</version></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>${maven-surefire-plugin.version}</version></plugin></plugins></pluginManagement></build>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.ryyt.cn/news/46607.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈,一经查实,立即删除!

相关文章

【球类识别系统】图像识别Python+卷积神经网络算法+人工智能+深度学习+TensorFlow

一、介绍 球类识别系统,本系统使用Python作为主要编程语言,基于TensorFlow搭建ResNet50卷积神经网络算法模型,通过收集 美式足球, 棒球, 篮球, 台球, 保龄球, 板球, 足球, 高尔夫球, 曲棍球, 冰球, 橄榄球, 羽毛球, 乒乓球, 网球, 排球等15种常见的球类图像作为数据集,然后…

[春秋云镜] Initial

Initial是一套难度为简单的靶场环境,完成该挑战可以帮助玩家初步认识内网渗透的简单流程。该靶场只有一个flag,各部分位于不同的机器上。[春秋云镜] Initial**整套网络环境拓扑:**​​ 一、打进内网 开局一个ip:39.101.184.25,fscan扫一下 ​​ 存在thinkphp5.0.23的漏洞,…

Vite-Wechat网页聊天室|vite5.x+vue3+pinia+element-plus仿微信客户端

基于Vue3+Pinia+ElementPlus仿微信网页聊天模板Vite5-Vue3-Wechat。 vite-wechat使用最新前端技术vite5+vue3+vue-router@4+pinia+element-plus搭建网页端仿微信界面聊天系统。包含了聊天、通讯录、朋友圈、短视频、我的等功能模块。支持收缩侧边栏、背景壁纸换肤、锁屏、最大化…

6月27日云技术研讨会 | 中央集中架构新车型功能和网络测试解决方案

会议摘要“软件定义汽车”新时代下,整车电气电气架构向中央-区域集中式发展已成为行业共识,车型架构的变革带来更复杂的整车功能定义、更多的新技术的应用(如SOA服务化、TSN等)和更短的车型研发周期,对整车和新产品研发的质量验证提出更高的要求。本次研讨会经纬恒润将结合…

k8s集群搭建及对一些组件的简单理解(一)

背景 k8s的学习环境(用kubeadm方式搭建),我也搭过几次了,但都有点问题。 要么在云服务器上弄,这个的问题是就只有一台轻量服务器,只能搭个单节点的;后来买了一台便宜的,所以就有了两台,但是不在一个zone,一个是广州,一个是成都,内网不通,感觉搭起来很麻烦,还没试…

Qt版本选择01

嵌入式推荐用Qt4.8,打包的程序小:Qt4.8.7是Qt4的终结版本,是Qt4系列版本中最稳定最经典的 最后支持xp系统的长期支持版本:Qt5.6.3;Qt5.7.0是最后支持xp系统的非长期支持版本。 最后提供mysql数据库插件的版本:Qt5.12.3。 最后支持win7的版本:Qt5.15系列。Qt6不支持win7 …

架构师必知的11种API性能优化方法

前言 接口性能优化是后端开发人员经常碰到的一道面试题,因为它是一个跟开发语言无关的公共问题。 这个问题既可以很简单,也可以相当复杂。有时候,只需要添加一个索引就能解决。 有时候,代码需要进行重构。 有时候,必须增加缓存。 有时候,需要引入一些中间件,例如消息队列…

接口面试题

postman接口测试,它有一个功能可以设置参数化,你有用过吗?多接口怎么测? (1)有 (2){{}}、a、设置环境变量、b、在run中通过导入csv文件引用变量 (3)postman里面有一个批量处理,将多个接口放至一个项目文件夹中,点击run,选择环境变量、修改运行次数和延迟秒数、选中c…