Hi guys, sorry if this is not the right channel - ...
# pact-jvm
r
Hi guys, sorry if this is not the right channel - Is there a best practice/formal way to test provider states? I mean the state functions themselves, that receive input and set up the required data. Thanks!
m
Are you asking how to test the provider states or best practice using them?
r
@Matt (pactflow.io / pact-js / pact-go) Hi, yes I am asking how to test them, meaning without going through a full cycle of developing a consumer that will use and send pacts with these states.
m
That's a good question. I mean, one strategy is to have the provider define the states they support and then the consumer can use them.
b
Wouldn’t this be covered by the tests that the provider runs on their implementation anyway? I mean, your provider is testing their implementation, right? Right? Example: if a specific provider state requires a data entity (an order, an address, whatever) to be present in the database, I’m hoping that there’s already: • a method or route in the provider implementation that takes care of this • at least one test that verifies that this method or route actually does what it says on the tin If you then call that method or invoke that route in your provider state method, does it really need additional testing? Or am I thinking too simple / missing something here?
m
> Wouldn’t this be covered by the tests that the provider runs on their implementation anyway? I mean, your provider is testing their implementation, right? Right? 😆 I hope so! I was confused by the question also. My suspicion is that the issue is that a consumer can come along and define a new state the provider hasn’t seen before, and Ran is looking for a better way to approach this to avoid the additional communication overhead. That’s an issue we are looking to improve (e.g. via https://pact.canny.io/feature-requests/p/list-provider-states-for-a-provider) There is no real need to test a provider state though - the end goal is to have the provider test work, it’s somewhat irrelevant if the provider state handlers themselves work or not
r
Thanks for the reply guys. I really did not explain myself properly 🙂 My goal is to run verification tests, locally - one of the reasons is I want any function with @State to be tested. If I can run my verification tests locally, I could provide pacts and catch any logical mistakes I might have there. My question is - using your libraries, given a static pact file and a running service (locally), is there a way I could load the pact and manually trigger verification tests using this pact?
m
Yes, you can pass a file to a local verification
> • have the broker trigger the provider > the broker (running in the cloud or somewhere else) is not going to trigger the verification on your machine, no
r
> Yes, you can pass a file to a local verification How?
m
Have you read the docs for verification?
(I have shared the JUnit ones, but perhaps you need another)
r
will read again, thanks!
👍 1