gpt4 book ai didi

java - pitest 无法定位 junit 测试

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:16:15 24 4
gpt4 key购买 nike

我的 gradle pitest 无法给我正确的结果。看起来它无法找到我的测试文件。

我有以下 build.gradle 文件:

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 test 时,它也运行良好。

最佳答案

pitest 用户组中提供了有关此问题的一些其他信息。

https://groups.google.com/forum/#!topic/pitusers/8C7BHh-Vb6Y

正在运行的测试看起来像这样。

@Test
public void testIt2() {
assert new DoublerImpl().testIt(1) == 2;
}

Pitest 正确地报告这些测试提供了 0% 的类覆盖率。没有覆盖,因为使用了 assert 关键字。

除非在运行测试的 JVM 中设置了 -ea 标志,否则断言将被禁用。编译器生成的这段代码周围基本上隐藏了 if block

@Test
public void testIt2() {
if (assertionsEnabled) {
assert new DoublerImpl().testIt(1) == 2;
}
}

由于未启用断言,因此不会执行任何代码。

要解决此问题,请改用内置的 JUnit 断言。

http://junit.sourceforge.net/javadoc/org/junit/Assert.html

关于java - pitest 无法定位 junit 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34948524/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com