Spring-cloud-contract: Skip test on specific contract

Created on 31 May 2017  路  6Comments  路  Source: spring-cloud/spring-cloud-contract

I have some contracts defined and set up a base class for tests:

    // In this section you define all Spring Cloud Contract Verifier Gradle Plugin properties
    contracts {
        baseClassForTests = 'abc.test.contract.AbstractVerfierTest'
        contractsDslDir = project.file("${project.rootDir}/abc-webservice/src/test/resources/contracts")
        //stubsOutputDir = project.file("${project.buildDir}/stubsdir")
    }

Now i need to skip some test generated (not all).
There is a way to do it?

Thanks in advance.

question

All 6 comments

In the contract you can call the ignore() method. Then the test and the stub will not be generated

And if i want to generate the stub skipping the test?

That's violating the concept behind the framework but I assume that you know what you're doing. Just call ./gradlew clean build -x generateContractTests and then you won't generate any tests.

Yes is a particular case. For this i want to skip just for a single endpoint contract and not to all.
./gradlew clean build -x generateContractTests
Your code skip all tests.

So you can keep that one contract in a different folder than the rest and configure your contracts extension that contracts are taken from some other directory (e.g. build/contracts). Before you execute any of contract's task you'd need to copy the contracts from src/test/resources/contracts over there. Then create a new task createStubsInAHackyWay or sth. That task can copy that additional contract to build/contracts after the tests got generated and before the stubs were created (the task name is generateClientStubs) . That way for all the contracts from src/test/resources/contracts you'll generate both tests and stubs. For those hacked ones you'll generate stubs only. But this is a hack that overrides the very essence of Spring Cloud Contract and Contract Testing - I hope you understand that. I don't know if it won't be easier for you to create a fake implementation of the controller to just make the tests pass.

Thanks so much for your support. I will try this solution.

Was this page helpful?
0 / 5 - 0 ratings