4

私のグラドルピテストは正しい結果を与えることができません。私のテストファイルを見つけることができないようです。

次の 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 を実行すると、問題なく実行されます。

4

1 に答える 1

2

この問題に関するいくつかの追加情報は、pitest ユーザー グループで提供されました。

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

実行中のテストは次のようになります。

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

Pitest は、これらのテストがクラスの 0% のカバレッジを提供することを正しく報告しています。assertキーワードが使用されているため、カバレッジはありません。

-eaテスト アサーションを実行している JVM でフラグが設定されていない限り、無効になります。基本的に、コンパイラによって生成されたこのコードの周りに if ブロックが隠されています

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

アサーションが有効になっていないため、コードは実行されません。

この問題を解決するには、代わりに組み込みの JUnit アサーションを使用してください。

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

于 2016-01-23T11:55:11.347 に答える