Search code examples
spring-cloud-contract

Running Spring cloud contract test in separate gradle task


I want to run spring cloud contract test cases as part of seperate gradle task named as "asyncContractTestCases" I have configured contract task as below :

contracts { 
       generatedTestSourcesDir = project.file('src/contracttest/async/provider/java')
       basePackageForTests='com.test.producer'
       baseClassForTests="com.test.producer.MessagingContractTests"
   }

and created a seperate gradle task to execute these test cases but still these test cases execute with gradle test ( as part of JUNITS). how not to run spring cloud contract test cases as part of junits ?


Solution

  • You can change the configuration of Gradle's test execution. You can exclude the contract tests by default and include them in your task

    test {
        description = "Task to run unit and integration tests"
        testLogging {
            exceptionFormat = 'full'
        }
        exclude '**/producer/**'
    }
    
    task asyncContractTestCases(type: Test) {
        description = "Task to run contract tests"
        testLogging {
            exceptionFormat = 'full'
        }
        include '**/producer/**'
    }