使用Powermock时,Gradle Jacoco不会跟踪Spock测试的覆盖范围 [英] Gradle Jacoco does not track the coverage of Spock test when using Powermock
问题描述
我正在使用Gradle Jacoco
插件记录我们软件的测试范围.该软件包含一些遗留代码,这些遗留代码大量使用了静态方法.为了模拟它们,我们提出了Powermock并将其集成到我们的Spock测试中.
I am using Gradle Jacoco
plugin to record the test coverage of our software. The software contains some legacy code that makes heavy use of static methods. In order to mock them we came up with Powermock and integrated it into our Spock tests.
一切正常. only 的问题是,Jacoco
不会跟踪使用Powermock进行的测试的测试范围.按预期报告了普通Spock测试(不使用Powermock的测试)的测试范围.
Everything works fine some far. The only thing is that Jacoco
does not track the test coverage of tests that are using Powermock. The coverage of tests of plain Spock tests (tests that do not use Powermock) are reported as expected.
有人知道如何使Jacoco
记录我的Powermock测试的覆盖范围吗?
Does anyone have a clue how to make Jacoco
record the coverage of my Powermock tests?
请在下面找到Spock测试.
Please find the Spock test below.
@PrepareForTest([CodeCacheManager])
class SampleSpec extends Specification {
@Rule
PowerMockRule powerMockRule = new PowerMockRule();
@Unroll
void "Convert CodeIdentifier #insertvalue toString #returnvalue"() {
given:
def converter = new CodeIdentifierCodeInternalNameCustomConverter()
and:
mockStatic(CodeCacheManager.class)
Mockito.when(CodeCacheManager.getInternalNameForCode(insertvalue)).thenReturn(returnvalue)
when:
String value = converter.convertTo(insertvalue, null)
then:
value == returnvalue
where:
insertvalue | returnvalue
PartnerCodes.Geschlecht.mannlich | "männlich"
null | "NO INTERNAL NAME"
}
}
和测试方法的实现看起来
and the implementation of the tested method looks
public String convertTo (CodeIdentifier source, String destination)
{
if (source != null)
{
return CodeCacheManager.getInternalNameForCode (source);
}
return "NO INTERNAL NAME";
}
推荐答案
PowerMock和Jacoco不兼容,并且不能同时使用.
PowerMock and Jacoco are incompatible and do not work when using them together.
这篇关于使用Powermock时,Gradle Jacoco不会跟踪Spock测试的覆盖范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!