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

I can't seem to get Pitest to work with a multi-module project with cucumber tests that are in a separate module #1368

Open
danielgerritsen-sqills opened this issue Dec 12, 2024 · 1 comment

Comments

@danielgerritsen-sqills
Copy link

I have this approximate project structure:

project/
├── module-with-java-code/
│   ├── main
│   ├── test
│   └── build.gradle
├── module-with-cucumber-features/
│   ├── features [test]/
│   │   ├── feature-test-folder-1/
│   │   │   ├── test-1.feature
│   │   │   └── -...
│   │   └── ...
│   ├── test/
│   │   ├── glue/
│   │   │   └── glues...
│   │   ├── TestNgCucumberTest for feature-test-folder-1
│   │   └── ...
│   └── build.gradle
├── way more more modules...
└── build.gradle

I want to execute Pitest on code in module-with-java-code but i want to run it with tests inside its own module and the feature tests from module-with-cucumber-features.

The versions i am using:

  • gradle: 8.11.1
  • pitest-gradle-plugin: 'info.solidsoft.pitest' version '1.15.0'
  • pitest-testng-plugin: 'org.pitest:pitest-testng-plugin:1.0.0'
  • pitest-junit5-plugin: 'org.pitest:pitest-junit5-plugin:1.2.1'
  • cucumber
    • 'io.cucumber:cucumber-jvm-deps:1.0.6',
    • 'io.cucumber:cucumber-picocontainer:7.20.1',
    • 'io.cucumber:cucumber-java:7.20.1',
    • 'io.cucumber:cucumber-testng:7.20.1',
    • 'me.jvt.cucumber:reporting-plugin:7.11.0'

I have tried to follow the documentation on gradle-pitest-plugin together with the multi-module example

What i was expecting was that it would recognize the cucumber tests (e.g. TestNgCucumberTest) and for each mutation execute the cucumber tests and the unit tests.

However i am running into some problems with the configuration:
I tried to configure it in the module-with-cucumber-features
Here it give an error: No mutations found

configure(project(':module-with-cucumber-features')) {
    apply plugin: 'info.solidsoft.pitest'
    dependencies {
        implementation project(':module-with-java-code')
    }

    configurations { mutableCodeBase { transitive false } }
    dependencies { mutableCodeBase project(':module-with-java-code') }
    pitest {
        mutators = ["ALL"]
        mainSourceSets = [project(':module-with-java-code').sourceSets.main]
        testSourceSets = [sourceSets.test]
        targetTests = ['com.example.TestNgCucumberTest']
        additionalMutableCodePaths = [configurations.mutableCodeBase.singleFile]
    }
}

I tried to configure it in the root project
Here it give an error: "Could not get unknown property 'implementation' for configuration container for project ':module-with-java-code' of type org.gradle.api.internal.artifacts.configurations.DefaultConfigurationContainer"

configure(project(':module-with-cucumber-features')) {
    apply plugin: 'info.solidsoft.pitest'
    apply plugin: 'java'

    dependencies {
        implementation project(':module-with-java-code')
    }

    //Additional configuration to resolve :module-with-java-code project JAR as mutable code path for PIT
    configurations {
        mutableCodeBase { transitive false }
        dependencies {
            mutableCodeBase.extendsFrom(project(':module-with-java-code').configurations.implementation)
        }
    }
    pitest {
        timestampedReports = false
        mainSourceSets = [project.sourceSets.main, project(':module-with-java-code').sourceSets.main]
        //Generates deprecation warning in Gradle 5.6+
        //Asked for recommendation: https://discuss.gradle.org/t/accessing-other-module-dependency-files-without-mutable-project-state-warnings/35048
        additionalMutableCodePaths = configurations.mutableCodeBase.files
//        additionalMutableCodePaths = project(':module-with-java-code').jar.outputs.files.getFiles()  //Workaround
    }
}
@szpak
Copy link
Contributor

szpak commented Dec 12, 2024

I tried to configure it in the root project
Here it give an error: "Could not get unknown property 'implementation' for configuration container for project ':module-with-java-code' of type org.gradle.api.internal.artifacts.configurations.DefaultConfigurationContainer"

The root project doesn't seem to be Java project, so implementation configuration might not be available.

The code in README you leveraged should reflect a test case which is executed in the functional test:
https://github.com/szpak/gradle-pitest-plugin/blob/master/src/funcTest/groovy/info/solidsoft/gradle/pitest/functional/AcceptanceTestsInSeparateSubprojectFunctionalSpec.groovy#L14

The caveat might be that due to the CD infrastructure legacy, the project itself is built only with Gradle 6.9. There might the some incompatible changes in Gradle 7 or 8. In addition, there might be a problem with the cucumber configuration and it might be hard to find it.

I propose you to first try to have executing - regular - JUnit tests executed from the other module with Gradle 8. If successful, then I would recommend adding there cucumber.

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

2 participants