1、根目录的pom.xml 文件
1 2 3 4 5 6 7 8 9 10 11 12 13 | <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.7</version> <executions> <execution> <id>prepare-agent</id> <goals> <goal>prepare-agent</goal> </goals> </execution> </executions> </plugin> |
模块关系
----parent
|---- test-module 单元测试模块
| ---- business-module1 业务模块1
| ---- business-module2 业务模块2
test-module 依赖 business-module1 和 business-module2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | <!--把依赖的模块解压出来放到classes目录下,原依赖的模块都是jar包方式存在,mvn test时会找不到--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>unpack</id> <phase>prepare-package</phase> <goals> <goal>unpack</goal> </goals> <configuration> <artifactItems> <!--把每个依赖的模块,都配置进来--> <artifactItem> <groupId>com.lishiots.cloud.datacenter</groupId> <artifactId>datacenter-service</artifactId> <version>1.0.1</version> <type>jar</type> <includes>**/*. class </includes> <overWrite> false </overWrite> <outputDirectory>${project.build.directory}/classes</outputDirectory> </artifactItem> </artifactItems> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <!-- junit 5 版本至少为2.22.2,且需要增加其他依赖 --> <version>2.7.1</version> <configuration> <runOrder>random</runOrder> <testFailureIgnore> true </testFailureIgnore> </configuration> </plugin> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.7</version> <executions> <!--整合所有子模块报告--> <execution> <id>report-aggregate</id> <phase>test</phase> <goals> <goal>report-aggregate</goal> </goals> </execution> </executions> </plugin> |
所有的单元测试代码再test-module的src/test/java 下
test-module的pom.xml
依次执行如下命令
1 2 3 4 5 6 7 8 9 10 | 先编译 mvn clean -U -Dmaven.test.skip= true package 保证test-module的target/classes中存在依赖的模块代码 如果启动需要依赖yml文件,需要先替换target/classes/bootstart.yml中的占位符 再执行测试 mvn test |
参考:https://www.jianshu.com/p/4c2af38bc85f
https://blog.csdn.net/skh2015java/article/details/121775806
作者:Work Hard Work Smart
出处:http://www.cnblogs.com/linlf03/
欢迎任何形式的转载,未经作者同意,请保留此段声明!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
2021-06-19 Python unittest和HTMLTestRunner生成报告
2021-06-19 Python 单元测试
2021-06-19 Python requests库使用
2015-06-19 Andaroid L新特性