Spring-cloud-contract: ignoredFiles disable all tests when list matches at least one file name

Created on 18 Feb 2020  路  3Comments  路  Source: spring-cloud/spring-cloud-contract

Describe the bug
Version: Spring Cloud Contract 2.2.1.RELEASE

When ignoredFiles is specified in ContractVerifierExtension and that provided ant matcher matches at least one contract file name, all tests are disabled in the generated test class.\
Issue has been encountered on Junit4 and Junit5.

Sample
reproducer: https://github.com/fstaudt/scc-ignored-files

  • 2 contracts are defined in src/test/resources/contracts: contractToCheck.groovy and contractToIgnore.groovy
  • Contract verifier extension is configured in gradle build to ignore second contract:
configure<ContractVerifierExtension> {
    setIgnoredFiles(listOf("contractToIgnore.groovy"))
}
  • when gradle task generateContractTests is executed, the 2 test methods in generated test class ContractVerifierTest are marked as Ignored (or Disabled if extension is configured Junit5).

Expected behavior is that only method validate_contractToIgnore should be marked as Ignored.

bug

Most helpful comment

Sure, I can file provide a fix with unit tests for this issue on 2.2.x branch and file a pull request.

All 3 comments

I've debugged the generation of the test class and I believe the issue lies in classes:

  • org.springframework.cloud.contract.verifier.builder.JUnit4IgnoreMethodAnnotation
  • org.springframework.cloud.contract.verifier.builder.JUnit5IgnoreMethodAnnotation

In both these classes, the method accept should take into account the provided parameter.\
Instead of:

    public boolean accept(SingleContractMetadata singleContractMetadata) {
        return this.generatedClassMetaData.configProperties
                .getTestFramework() == TestFramework.JUNIT5
                && this.generatedClassMetaData.isAnyIgnored();
    }

we should have:

    public boolean accept(SingleContractMetadata singleContractMetadata) {
        return this.generatedClassMetaData.configProperties
                .getTestFramework() == TestFramework.JUNIT5
                && singleContractMetadata.contractMetadata.ignored;
    }

Hi! Thanks for the analysis. Do you want to file a pull request preferably with a test? If that's the case can you try doing it against the 2.2.x branch?

Sure, I can file provide a fix with unit tests for this issue on 2.2.x branch and file a pull request.

Was this page helpful?
0 / 5 - 0 ratings