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

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

Closed
St4rG00se opened this issue Jan 18, 2021 · 5 comments
Closed

Comments

@St4rG00se
Copy link

St4rG00se commented Jan 18, 2021

@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:

  • UPDATE pitest version (pitest-maven: 1.6.2 / pitest-junit5-plugin: 0.12)
  • Run mvn clean package org.pitest:pitest-maven:mutationCoverage
  • IT WORKS (See: 'Tests examined' in 'Calculator.java.html' is filled)

Gradle check

  • Insert the following build.gradle file to the project :
plugins {
    id 'java'
    id 'info.solidsoft.pitest' version '1.5.2'
}

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

@St4rG00se St4rG00se changed the title @ParameterizedTest doesn't work with gradle plugin @ParameterizedTest with @MethodSource doesn't work with gradle plugin Jan 18, 2021
@szpak
Copy link
Owner

szpak commented Jan 18, 2021

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
Copy link
Owner

szpak commented Jan 18, 2021

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
Copy link
Owner

szpak commented Jan 18, 2021

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
Copy link
Owner

szpak commented Sep 13, 2021

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

@St4rG00se
Copy link
Author

I don t reproduce it again...

sorry and thank you for your time

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

No branches or pull requests

2 participants