'Generated test sources not getting invoked as part of the gradle build

  • Added Spring Cloud Contract plugin and configured it for baseClassMappings
  • Added Spring Cloud Contract verifier
  • Added required base classes for generated tests
  • Defined groovy contract
  • Using Test{useunitPlatform()} to identify and execute the JUnit tests

The contract tests are getting generated in the build/generated-test-sources but not being executed. I'm getting build successful without these contract tests being executed.

I'm using gradle 7.4 version and junit-jupiter-engine version 5.7.0.



Solution 1:[1]

I also had this problem in the past. I however solved it in maven since my project runs with that. There might be similar configuration properties in gradle. You can manually ride the configuration and in which files to look at.

<configuration>
<contractsRepositoryUrl>http://yourContractsRepositoryUrl.com</contractsRepositoryUrl>
<!-- We want to use the JAR with contracts with the following coordinates -->
<contractDependency>
    <groupId>org.example</groupId>
    <artifactId>example-artifact</artifactId>
    <classifier>stubs</classifier>
</contractDependency>
<!-- The JAR with contracts should be taken from Maven remote -->
<contractsMode>REMOTE</contractsMode>

<includedFiles>
    <includedFile>*filennameA*</includedFile>

    <includedFile>*filennameB*</includedFile>
</includedFiles>

<contractsPath>your.contracts.package.structure</contractsPath>
<baseClassForTests>

   org.someservice.contracts.ContractVerifierBase
</baseClassForTests>
<basePackageForTests>org.someservice.contracts
</basePackageForTests>
<testFramework>JUNIT5</testFramework>

I hope that there is an approach in there for you. It always unpleasant to get the contracts to run in my experience :(

Solution 2:[2]

This issue got resolved with these changes in my case:

  1. I added this dependency group: 'org.junit.platform', name:'junit-platform-runner', version: '1.7.0' inside testImplementation in rest/build.gradle.
  2. useJUnitPlatform() instead of useJUnit() in test section in rest/build.gradle
  3. Changed the @RunWith(SpringRunner.class), to @RunWith(JUnitPlatform.class) in all the BaseClasses
  4. Replaced the @Before with @BeforeEach in all the baseclasses.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 GJohannes
Solution 2 Nidhi S