jmockit jacoco冲突

背景

jmockit是单测mock框架  http://jmockit.org

jacoco是测试覆盖率工具 http://eclemma.org/jacoco/

问题

两者在java开发的测试上都有不错的表现,但是在一起使用时,可能会出现水土不服:

比如像:

java.lang.instrument.IllegalClassFormatException: Error while instrumenting class xxx类.
    at org.jacoco.agent.rt_1r70et.CoverageTransformer.transform(CoverageTransformer.java:94)
    at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
    at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:424)
    at sun.instrument.InstrumentationImpl.redefineClasses0(Native Method)
    at sun.instrument.InstrumentationImpl.redefineC
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
是的,在子模块中也需要导入jmockit和junit的依赖项,否则你将无法使用这些库进行单元测试。此外,如果你想使用jacoco插件生成代码覆盖率报告,也需要在子模块的pom.xml文件中导入jacoco插件。 需要注意的是,在父工程中只声明依赖项并不会真正地将这些依赖项引入到子模块中,因此你需要在子模块的pom.xml文件中显式地声明这些依赖项。你可以在子模块的pom.xml文件中添加类似以下的依赖项: ``` <dependencies> <dependency> <groupId>org.jmockit</groupId> <artifactId>jmockit</artifactId> <version>1.49</version> <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.2</version> <scope>test</scope> </dependency> </dependencies> ``` 其中,`<scope>test</scope>`表示这些依赖项只在测试阶段使用,不会影响到生产环境的代码。如果你想使用jacoco插件生成代码覆盖率报告,还需要在子模块的pom.xml文件中添加jacoco插件的配置,例如: ``` <build> <plugins> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.7</version> <executions> <execution> <goals> <goal>prepare-agent</goal> </goals> </execution> <execution> <id>report</id> <phase>test</phase> <goals> <goal>report</goal> </goals> </execution> </executions> </plugin> </plugins> </build> ``` 这样,在执行`mvn clean test jacoco:report`命令时,jacoco插件就会在测试过程中生成代码覆盖率信息,并在测试结束后生成代码覆盖率报告。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值