Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pitest/JUnit5 issue using a Kotlin DSL Gradle script #7

Closed
Giroteti opened this issue Jun 18, 2018 · 10 comments
Closed

Pitest/JUnit5 issue using a Kotlin DSL Gradle script #7

Giroteti opened this issue Jun 18, 2018 · 10 comments

Comments

@Giroteti
Copy link

Hi,

I'm looking fowarward to using pitest on a kotlin/Junit5/Springboot2 api which builds with help of a Kotlin DSL Gradle script.

I converted the Groovy DSL configuration : (that I found here : https://gradle-pitest-plugin.solidsoft.info/)

buildscript {
   repositories {
       mavenCentral()
   }
   configurations.maybeCreate('pitest')
   dependencies {
       classpath 'info.solidsoft.gradle.pitest:gradle-pitest-plugin:1.3.0'
       pitest 'org.pitest:pitest-junit5-plugin:0.3'
   }
}

pitest {
    testPlugin = 'junit5'
    // rest of your pitest config
}

into the Kotlin DSL (there's a bunch of springboot related stuff, but I think all is here):

    import org.gradle.api.tasks.testing.logging.TestExceptionFormat
    import org.gradle.api.tasks.testing.logging.TestLogEvent
    import org.gradle.kotlin.dsl.getting
    import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

    val pitest = configurations.maybeCreate("pitest")

    plugins {
        val kotlinVersion = "1.2.41"
        id("org.springframework.boot") version "2.0.2.RELEASE"
        id("org.jetbrains.kotlin.jvm") version kotlinVersion
        id("org.jetbrains.kotlin.plugin.spring") version kotlinVersion
        id("org.jetbrains.kotlin.plugin.jpa") version kotlinVersion
        id("io.spring.dependency-management") version "1.0.5.RELEASE"
        id("info.solidsoft.pitest") version "1.3.0"
    }

    version = "1.0.0-SNAPSHOT"

    tasks.withType<KotlinCompile> {
        kotlinOptions {
            jvmTarget = "1.8"
            freeCompilerArgs = listOf("-Xjsr305=strict")
        }
    }
    pitest {
        targetClasses = setOf("api.*")
        threads = 8
        testPlugin = "junit5"
        outputFormats = setOf("HTML")
        jvmArgs = listOf("-Xmx1024m")
        verbose = true
        pitestVersion = "1.4.0"
    }

    val test by tasks.getting(Test::class) {
        useJUnitPlatform()
        testLogging {
            showExceptions = true
            showStackTraces = true
            exceptionFormat = TestExceptionFormat.FULL
            events = setOf(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED, TestLogEvent.STANDARD_ERROR)
        }
    }

    repositories {
        mavenCentral()
    }

    dependencies {
        compile("org.springframework.boot:spring-boot-starter-web")
        compile("org.springframework.boot:spring-boot-starter-data-jpa")
        compile("com.h2database:h2")
        compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
        compile("org.jetbrains.kotlin:kotlin-reflect")
        compile("com.fasterxml.jackson.module:jackson-module-kotlin")
        testCompile("org.springframework.boot:spring-boot-starter-test") {
            exclude(module = "junit")
        }
        testCompile("org.mockito:mockito-junit-jupiter:2.18.3")
        testCompile("org.assertj:assertj-core:3.10.0")
        testCompile("org.assertj:assertj-core")
        testImplementation("org.junit.jupiter:junit-jupiter-api")
        testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
        pitest("org.pitest:pitest-junit5-plugin:0.5")
    }

And I run into the following error :

20:24:40 PIT >> FINE : MINION : org.pitest.util.PitError: Could not load requested test plugin junit5

Please copy and paste the information and the complete stacktrace below when reporting an issue
VM : OpenJDK 64-Bit Server VM
Vendor : JetBrains s.r.o
Version : 25.152-b01
Uptime : 259

20:24:40 PIT >> FINE : MINION : Input ->
 1 : -Xmx1024m
 2 : -javaagent:/var/folders/1_/p3v6_7916_zf08nv_xvkt_pc0000gn/T/1529346279976072913329877657186029561337768291024.jar
 3 : -Dfile.encoding=UTF-8
 4 : -Duser.country=FR
 5 : -Duser.language=fr
 6 : -Duser.variant
BootClassPathSuppo
20:24:40 PIT >> FINE : MINION : rted : true

        at org.pitest.mutationtest.config.MinionSettings.getTestFrameworkPlugin(MinionSettings.java:38)
        at org.pitest.coverage.execute.CoverageMinion.createTestPlugin(CoverageMinion.java:166)
        at org.pitest.coverage.execute.CoverageMinion.getTestsFr
20:24:40 PIT >> FINE : MINION : omParent(CoverageMinion.java:135)
        at org.pitest.coverage.execute.CoverageMinion.main(CoverageMinion.java:84)

20:24:40 PIT >> SEVERE : Coverage generator Minion exited abnormally due to UNKNOWN_ERROR
Exception in thread "main" org.pitest.util.PitError: Coverage generation minion exited abnormally!

Please copy and paste the information and the complete stacktrace below when reporting an issue
VM : OpenJDK 64-Bit Server VM
Vendor : JetBrains s.r.o
Version : 25.152-b01
Uptime : 726
Input ->
 1 : -Dfile.encoding=UTF-8
 2 : -Duser.country=FR
 3 : -Duser.language=fr
 4 : -Duser.variant
BootClassPathSupported : true


Please copy and paste the information and the complete stacktrace below when reporting an issue
VM : OpenJDK 64-Bit Server VM
Vendor : JetBrains s.r.o
Version : 25.152-b01
Uptime : 726
Input ->
 1 : -Dfile.encoding=UTF-8
 2 : -Duser.country=FR
 3 : -Duser.language=fr
 4 : -Duser.variant
BootClassPathSupported : true

        at org.pitest.util.Unchecked.translateCheckedException(Unchecked.java:20)
        at org.pitest.coverage.execute.DefaultCoverageGenerator.calculateCoverage(DefaultCoverageGenerator.java:103)
        at org.pitest.coverage.execute.DefaultCoverageGenerator.calculateCoverage(DefaultCoverageGenerator.java:49)
        at org.pitest.mutationtest.tooling.MutationCoverage.runReport(MutationCoverage.java:115)
        at org.pitest.mutationtest.tooling.EntryPoint.execute(EntryPoint.java:116)
        at org.pitest.mutationtest.tooling.EntryPoint.execute(EntryPoint.java:49)
        at org.pitest.mutationtest.commandline.MutationCoverageReport.runReport(MutationCoverageReport.java:87)
        at org.pitest.mutationtest.commandline.MutationCoverageReport.main(MutationCoverageReport.java:45)
Caused by: org.pitest.util.PitError: Coverage generation minion exited abnormally!

So I guess there's something I configured wrong with the plugin (it suppose to make pitest jUnit5-compatible right ?)...
Any idea ?

Thank you in advance !

@tomashanley-toast
Copy link

tomashanley-toast commented Jul 7, 2018

I'm getting the same error.
I have a kotlin project (not using the kotlin gradle DSL) where pitest worked with JUnit4. JUnit5 works fine by itself, but I keep getting this same error when trying to run pitest after upgrading to JUnit5.
I've tried with gradle 4.7 and 4.5.

buildscript {
    ext.kotlin_version = '1.2.50'
    repositories {
        mavenCentral()
    }
    configurations.maybeCreate("pitest")
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'info.solidsoft.gradle.pitest:gradle-pitest-plugin:1.3.0'
        pitest 'org.pitest:pitest-junit5-plugin:0.5'
    }
}


pitest {
    pitestVersion = "1.4.0"
    testPlugin = "junit5"
    avoidCallsTo = ['kotlin.jvm.internal']
    threads = 8
    outputFormats = ['HTML']
    jvmArgs = ['-Xmx1024m']
}

So it seems like a kotlin issue?

@szpak
Copy link
Contributor

szpak commented Jul 16, 2018

Guys, you can provide a minimal project with PIT and Kotlin configuration reproducing that issue. Maybe I will be able to find a reason and use that project as a functional test to prevent regressions (currently I don't test gradle-pitest-plugin with Kotlin, but it is on my todo list - szpak/gradle-pitest-plugin#59).

@tomashanley-toast
Copy link

tomashanley-toast commented Jul 23, 2018

So I was working on providing the minimal project yesterday, and came across #8, which it turns out is the cause of my error as my kotlin module is a submodule. Adding the dependency to the root module solved the error.
However, now pitest runs without error, but it does not pick up any tests.

>> Generated 920 mutations Killed 0 (0%)
>> Ran 0 tests (0 tests per mutation)

Running gradle test works fine, so I'm not sure what the problem is, still trying to figure it out.

@snowe2010
Copy link

Any update on this? The plugin appears to work fine, but it fails to run any tests (it finds them), though I get errors about jupiter.

11:11:41 PM PIT >> INFO : Verbose logging is disabled. If you encounter an problem please enable it before reporting an issue.
11:11:41 PM PIT >> INFO : Sending 86 test classes to minion
11:11:41 PM PIT >> INFO : Sent tests to minion
11:11:41 PM PIT >> INFO : MINION : 11:11:41 PM PIT >> INFO : Checking environment

11:11:42 PM PIT >> INFO : MINION : Jan 31, 2019 11:11:42 PM org.junit.platform.launcher.core.DefaultLauncher handleThrowable
WARNING: TestEngine with ID 'junit-jupiter' failed to discover tests
java.lang.NoClassDefFoundError: org/junit/jupiter/api/extension/ExtensionContext
	at org.junit
11:11:42 PM PIT >> INFO : MINION : .jupiter.engine.JupiterTestEngine.discover(JupiterTestEngine.java:60)
	at org.junit.platform.launcher.core.DefaultLauncher.discoverEngineRoot(DefaultLauncher.java:130)
	at org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java
11:11:42 PM PIT >> INFO : MINION : :117)
	at org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:82)
	at org.pitest.junit5.JUnit5TestUnitFinder.findTestUnits(JUnit5TestUnitFinder.java:49)

@yanivnahoum
Copy link

yanivnahoum commented Jun 16, 2019

Here we go - JDK 11, Gradle 4.5.1 (Kotlin DSL), JUnit Jupiter

import info.solidsoft.gradle.pitest.PitestPluginExtension

plugins {
    java
}

java {
    sourceCompatibility = JavaVersion.VERSION_11
}

buildscript {
    val pitest = configurations.maybeCreate("pitest")
    dependencies {
        classpath("info.solidsoft.gradle.pitest:gradle-pitest-plugin:1.4.0")
        pitest("org.pitest:pitest-junit5-plugin:0.9")
    }
}

apply(plugin = "info.solidsoft.pitest")
configure<PitestPluginExtension> {
    testPlugin = "junit5"
}

repositories {
    mavenCentral()
}

dependencies {
    val mockitoVersion = "2.28.2"
    testImplementation("org.junit.jupiter:junit-jupiter:5.4.2")
    testImplementation("org.assertj:assertj-core:3.12.2")
    testImplementation("org.mockito:mockito-core:$mockitoVersion")
    testImplementation("org.mockito:mockito-junit-jupiter:$mockitoVersion")
}

@szpak
Copy link
Contributor

szpak commented Jun 16, 2019

@yanivnahoum Does it reproduce the problem or it just works fine? :)

@yanivnahoum
Copy link

Works great 😊

@szpak
Copy link
Contributor

szpak commented Feb 25, 2020

@EGI-OCTO Can this issue be closed?

@Giroteti
Copy link
Author

Giroteti commented Feb 25, 2020 via email

@szpak
Copy link
Contributor

szpak commented Feb 25, 2020

Ok. I asked as there is a working example of PIT + Gradle with Kotlin (which is also a part of the functional tests in gradle-pitest-plugin), so in general it works. You might encountered some corner case. Or maybe it was already fixed.

P.S. Please close this issue as the creator (I bumped into it once looking for problems with PIT and Gradle in the Internet :-) ).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants