Hello everybody, I was wondering if anyone has a g...
# general
e
Hello everybody, I was wondering if anyone has a general approach for how to handle writing the consumer test when the provider has regex requirements on part of the body that it expects. I could have the consumer generate a random string that satisfies a regex (using something like RxGen), but that seems to be creeping up on functional testing. Not to mention, if I generate a new string every time the consumer is run, the contract will change every time the test suite is run. Is this a sign that the provider is being tested at too low of a level or that such regex requirements should be moved to a lower level?
I did also notice that I can do something like:
Copy code
body.stringMatcher(
                "toolDockerImage", <regex-requirmement>, <Fixed example of passing string>);
it seems strange to have to port the provider’s regex over to the consumer, but maybe it’s just new to me. I am wondering if it is any better to do something like:
Copy code
body.stringType(
                "toolDockerImage", <Fixed example of passing string>);
That way you wouldn’t have to port over a potentially complex regex expression.
Do you do a similar thing when the provider has range requirements for a numeric input ?
body.numberType("age", 10))
In this case, the provider might have a range requirement of 0-130, but the statement above would specify the contract is only looking for a number. However, every time the contract is verified on the provider side, the value of 10 will be used to test. Am I understanding that correctly?
b
I think the simplest approach that gives significant coverage (and executable documentation) is to make one test for a matching value, and one for a bad value. (In the case of a number range, you might have 2 out-of-bounds tests)
But yeah, it is creeping into functional testing territory. One test per significant distinction is a good minimum, and pass/fail is significant, if the response is distinct.
The regex matcher is more for cases where the DSL doesn't have a specific matcher, but the field has a relatively-common type, like a GUID or ISO-8601 date (which now have matchers in the DSL, but didn't always).
e
Thanks @Boris! That’s great context. My organization (myself included) is still pretty new to contract testing, so your advice is valuable.