Hi - Question about provider states. If have a sta...
# general
p
Hi - Question about provider states. If have a state that requires a test user and some other data record associated with that test user to be created, is it better to achieve this via one single provider state, or two? For example, I could have just one state: “A thing exists for a user” For example, I could have two states: 1. “A user exists with username foo” 2. “A thing exists for user with username foo” It seems that having multiple states could be preferable for reasons of modularity and reusability, i.e. each state has fewer responsibilities and could be reused in multiple tests. However, the potential concern I see is it requires hard-coding some sort of shared data into the test, e.g. a username. And under some scenarios (e.g. tests running concurrently or test data not cleaned up correctly) this could potentially cause problems.
m
I think the best practice would be to set them up as two independent states
However, the potential concern I see is it requires hard-coding some sort of shared data into the test,
this can actually be mitigated (to an extent) by using the value from provider state feature (see https://pactflow.io/blog/injecting-values-from-provider-states/). We really need general docs on this.
And under some scenarios (e.g. tests running concurrently or test data not cleaned up correctly) this could potentially cause problems.
that could still be a problem, even if you combine states. For instance “User A with thing X” and “No things exist”.
t
Tests shouldn’t run concurrently in Pact- each test needs to be independent
m
On the provider side, yes, good point