szpak / gradle-pitest-plugin

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

@ParameterizedTest with @MethodSource doesn't work with gradle plugin #250

Closed St4rG00se closed 2 years ago

St4rG00se commented 3 years ago

@ParameterizedTest with @MethodSource are ignored with gradle plugin

How to reproduce :

Get this MAVEN project : https://github.com/dmitry-timofeev/pitest-with-junit5-issue/tree/master

Update CalculatorTest file

class CalculatorTest {

  @ParameterizedTest
  @MethodSource("args")
  void increment(int i, int expectedResult) {
    assertEquals(expectedResult, Calculator.increment(i));
  }

  public static Stream<Arguments> args(){
    return Stream.of(
        Arguments.of(1,2),
        Arguments.of(2,3)
    );
  }

}

Maven check:

Gradle check

repositories { mavenCentral() }

dependencies { // JUNIT testCompile group: 'org.junit.jupiter', name:'junit-jupiter', version: "5.7.0" }

pitest { testSourceSets = [sourceSets.test] targetClasses = ['dt.pitest.'] targetTests= ['dt.pitest.'] junit5PluginVersion = "0.12" pitestVersion = "1.5.2" testPlugin = "junit5" threads = 1 outputFormats = ['XML', 'HTML'] timestampedReports = false }

test { useJUnitPlatform() }


- Run `./gradlew clean build pitest`
- IT FAILS (See: 'Tests examined' in 'Calculator.java.html' is **empty**) 

Notes:
- It works with @Test or @CsvSource
- Gradlew version: 6.7

Thank for your answer
szpak commented 3 years ago

It should work. Have you tried with the junit-jupiter-params dependency added also in the Gradle project?

Update. I confused org.junit.jupiter:junit-jupiter-engine with org.junit.jupiter:junit-jupiter. The later pulls in also junit-jupiter-params (I wonder why you did it manually with Maven?).

szpak commented 3 years ago

In general thanks for the sample project which helps to reproduce the issues. With build.gradle (and Gradle wrapper) in place it would be even simpler, but I copy-pasted your content and it seems to work as expected:

$ ~/.gradle/wrapper/dists/gradle-6.3-bin/.../gradle-6.3/bin/gradle pitest
Starting a Gradle Daemon (subsequent builds will be faster)

> Task :pitest
10:09:54 PM PIT >> INFO : Verbose logging is disabled. If you encounter a problem, please enable it before reporting an issue.
10:09:54 PM PIT >> INFO : Sending 2 test classes to minion
10:09:54 PM PIT >> INFO : Sent tests to minion
10:09:54 PM PIT >> INFO : MINION : 10:09:54 PM PIT >> INFO : Checking environment

10:09:54 PM PIT >> INFO : MINION : 10:09:54 PM PIT >> INFO : Found  5 tests

10:09:54 PM PIT >> INFO : MINION : 10:09:54 PM PIT >> INFO : Dependency analysis reduced number of potential tests by 0
10:09:54 PM PIT >> INFO : 5 tests received

/10:09:54 PM PIT >> INFO : Calculated coverage in 0 seconds.
10:09:55 PM PIT >> INFO : Incremental analysis reduced number of mutations by 0
10:09:55 PM PIT >> INFO : Created  1 mutation test units
/10:09:55 PM PIT >> INFO : Completed in 1 seconds
================================================================================
- Mutators
================================================================================
> org.pitest.mutationtest.engine.gregor.mutators.MathMutator
>> Generated 1 Killed 1 (100%)
> KILLED 1 SURVIVED 0 TIMED_OUT 0 NON_VIABLE 0 
> MEMORY_ERROR 0 NOT_STARTED 0 STARTED 0 RUN_ERROR 0 
> NO_COVERAGE 0 
--------------------------------------------------------------------------------
> org.pitest.mutationtest.engine.gregor.mutators.PrimitiveReturnsMutator
>> Generated 1 Killed 1 (100%)
> KILLED 1 SURVIVED 0 TIMED_OUT 0 NON_VIABLE 0 
> MEMORY_ERROR 0 NOT_STARTED 0 STARTED 0 RUN_ERROR 0 
> NO_COVERAGE 0 
--------------------------------------------------------------------------------
================================================================================
- Timings
================================================================================
> scan classpath : < 1 second
> coverage and dependency analysis : < 1 second
> build mutation tests : < 1 second
> run mutation analysis : < 1 second
--------------------------------------------------------------------------------
> Total  : < 1 second
--------------------------------------------------------------------------------
================================================================================
- Statistics
================================================================================
>> Generated 2 mutations Killed 2 (100%)
>> Ran 2 tests (1 tests per mutation)

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.3/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 12s
3 actionable tasks: 3 executed

image

Update. The same result with Gradle 6.7

szpak commented 3 years ago

Btw2, you can remove:

    junit5PluginVersion = "0.12"
    pitestVersion = "1.5.2"

from your configuration. For the Gradle plugin 1.5.2 they are the default values.

szpak commented 2 years ago

@St4rG00se As I wasn't able to reproduce the problem with your project, I wonder if you're still facing that problem?

St4rG00se commented 2 years ago

I don t reproduce it again...

sorry and thank you for your time