I am presently writing REST API tests using REST Client and Spock. I want to be able to run my tests on the different test environments. My test data varies between test environment, so need to use and specify different input data per environment. For a sample test below
class MathSpec extends Specification {
def "maximum of two numbers"() {
expect:
Math.max(a, b) == c
where:
a | b || c
1 | 3 || 3
}
}
Am I able to specify different data tables for each environment?
class MathSpec extends Specification {
def "maximum of two numbers"() {
expect:
Math.max(a, b) == c
where:
@TEST
a | b || c
1 | 3 || 3
@PROD
a | b || c
4 | 5 || 6
}
}
If not, what's the best way to approach this problem? Thanks.
Spock has Multi-Variable Data Pipes to handle this. You can move the "logic" to a data-driven method.
In your case, I would use an abstract
getData()
method.I would implement in
getData()
in two different classesMathProductionSpec
andMathStagingSpec
I would use spock annotations to execute according to your environment.
example: