pitest无法找到junit测试 [英] pitest not able to locate junit test
问题描述
我的gradle pitest无法给我正确的结果.看来找不到我的测试文件.
My gradle pitest is not able to give me the right results. It looks like it is not able to locate my test files.
我有以下build.gradle文件:
I have the following build.gradle file:
apply plugin: "java" apply plugin: "maven" apply plugin: "info.solidsoft.pitest"
group = "myorg" version = 1.0
repositories {
mavenCentral() }
sourceSets.all { set ->
def jarTask = task("${set.name}Jar", type: Jar) {
baseName = baseName + "-$set.name"
from set.output
}
artifacts {
archives jarTask
} }
sourceSets {
api
impl main{ java { srcDir 'src/api/java' srcDir 'src/impl/java' } } test { java { srcDir 'src/test/java' } } }
buildscript {
repositories {
mavenCentral()
//Needed only for SNAPSHOT versions
//maven { url "http://oss.sonatype.org/content/repositories/snapshots/" }
}
dependencies {
classpath 'info.solidsoft.gradle.pitest:gradle-pitest-plugin:1.1.6'
} }
dependencies {
apiCompile 'commons-codec:commons-codec:1.5'
implCompile sourceSets.api.output
implCompile 'commons-lang:commons-lang:2.6'
testCompile 'junit:junit:4.9'
testCompile sourceSets.api.output
testCompile sourceSets.impl.output
runtime configurations.apiRuntime
runtime configurations.implRuntime }
jar {
from sourceSets.api.output
from sourceSets.impl.output }
pitest { println sourceSets.main
targetClasses = ['doubler.*'] targetTests = ['doubler.*'] verbose="on" }
输出存储在正确的文件夹中.而且当我进行gradle测试时,它也可以正常运行.
THe output is stored in the correct folder. And when I run gradle test, it also runs fine.
推荐答案
最重要的用户组中提供了有关此问题的一些其他信息.
Some additional information about this issue was supplied in the pitest user group.
https://groups.google.com/forum/#! topic/pitusers/8C7BHh-Vb6Y
正在运行的测试如下.
@Test
public void testIt2() {
assert new DoublerImpl().testIt(1) == 2;
}
Pitest正确地报告这些测试提供了该类的0%覆盖率.没有覆盖范围,因为使用了assert
关键字.
Pitest is correctly reporting that these tests provide 0% coverage of the class. There is no coverage because the assert
keyword has been used.
除非在运行测试断言的JVM中设置了-ea
标志,否则将禁用它.编译器生成的这段代码周围的if块基本上是隐藏的
Unless the -ea
flag is set in the JVM running the tests assertions are disabled. There is basically hidden if block around this code generated by the compiler
@Test
public void testIt2() {
if (assertionsEnabled) {
assert new DoublerImpl().testIt(1) == 2;
}
}
由于未启用断言,因此不会执行任何代码.
As assertions are not enabled no code is executed.
要解决此问题,请改用内置的JUnit断言.
To fix the issue use the built in JUnit assertions instead.
http://junit.sourceforge.net/javadoc/org/junit/Assert.html
这篇关于pitest无法找到junit测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!