szpak / gradle-pitest-plugin

Gradle plugin for PIT Mutation Testing
http://gradle-pitest-plugin.solidsoft.info/
212 stars 57 forks source link

Copy 'test' task system properties to pitest jvmArgs #216

Open pkubowicz opened 4 years ago

pkubowicz commented 4 years ago

If Gradle 'test' task is configured with system properties then it's nearly guaranteed that Pitest will fail unless you take care of configuring Pitest.

Use case

I use Spring constructor injection in my JUnit 5 tests:

test {
    useJUnitPlatform()
    systemProperty 'spring.test.constructor.autowire.mode', 'all'
}

pitest {
    junit5PluginVersion = '0.12'
}

My tests pass, but fail in Pitest. This is because spring.test.constructor.autowire.mode is not passed to JVM executing tests for Pitest.

The workaround is to manually pass all system properties you have:

pitest {
    jvmArgs = ['-Dspring.test.constructor.autowire.mode=all']
}

Expected solution

I think the Gradle plugin should do this copying if it's possible. You should assume that any system property set in 'test' task is required and tests won't pass without it. This property does not need to be related to Spring, it can be something like a queue URL, database port, path to a directory with some data required for tests.

Until it is implemented, it would be good to clearly document in README that you need to manually copy your system properties as the plugin is not taking care of it.

szpak commented 4 years ago

It sounds sensible to copy the test properties by default, unless set to an empty list (or anything else). Probably the plugin should only take into account the test task named test (and ignore other - e.g. funcTest).