Thomas K
12/04/2022, 2:32 PMmockServer
and instead using something like MockK
? I have tried but get PactMismatchesException
saying the request was not receivedThomas K
12/04/2022, 4:50 PMmockServer
Matt (pactflow.io / pact-js / pact-go)
Timothy Jones
12/05/2022, 2:43 AMTimothy Jones
12/05/2022, 2:46 AMThis means the mock server did not receive the request …. which isn’t surprising. The pact mock server is the thing that checks that your request looks like you said it would. It looks like the lastminute example is mocking out the repository layer of the service during pact verification - which is normal.PactMismatchesException
Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
MockK
but with the benefits of contract testing.Matt (pactflow.io / pact-js / pact-go)
Timothy Jones
12/05/2022, 2:56 AMTimothy Jones
12/05/2022, 2:57 AMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Timothy Jones
12/05/2022, 2:58 AMTimothy Jones
12/05/2022, 2:59 AMThat could be done of course🤔 …but then you lose the advantage of Pact, which is to check that you actually are sending the thing.
Timothy Jones
12/05/2022, 2:59 AMMatt (pactflow.io / pact-js / pact-go)
Oh, right - but, that doesn’t make senseYes. Sort of. Obviously, the code should execute. In the sense that it needs to actually go through the whole network cycle is a separate thing. e.g.
nock
mocks the network layer and can do it in a way that’s pretty safe.
The related thing is that you don’t need to configure your API client to point at the mock server, because the runtime can intercept it etc.Timothy Jones
12/05/2022, 3:00 AMMatt (pactflow.io / pact-js / pact-go)
Timothy Jones
12/05/2022, 3:01 AMTimothy Jones
12/05/2022, 3:01 AMTimothy Jones
12/05/2022, 3:02 AMTimothy Jones
12/05/2022, 3:02 AMMatt (pactflow.io / pact-js / pact-go)
Thomas K
12/05/2022, 8:31 AMmockServer
for now, which is ok for our needs.Thomas K
12/05/2022, 8:31 AMMockK
instead so thought it would’ve been nice if I can simply use MockK
and still get the consumer expectations generatedTimothy Jones
12/05/2022, 8:32 AMThomas K
12/05/2022, 8:32 AMTimothy Jones
12/05/2022, 8:32 AMTimothy Jones
12/05/2022, 8:33 AMThomas K
12/05/2022, 8:33 AMTimothy Jones
12/05/2022, 8:33 AMThomas K
12/05/2022, 8:33 AMTimothy Jones
12/05/2022, 8:33 AMTimothy Jones
12/05/2022, 8:34 AMTimothy Jones
12/05/2022, 8:34 AMTimothy Jones
12/05/2022, 8:34 AMTimothy Jones
12/05/2022, 8:35 AMTimothy Jones
12/05/2022, 8:35 AMapi.getUser(userId)
Timothy Jones
12/05/2022, 8:36 AMval testUser = User(...some details here..)
api.getUser(1) <-- mock this to return testUser
Timothy Jones
12/05/2022, 8:36 AMTimothy Jones
12/05/2022, 8:37 AMapi.getUser(1)
fires the request that I am expecting, and I would confirm that the object that I get back is indeed the same as testUser
Thomas K
12/05/2022, 8:38 AMThomas K
12/05/2022, 8:38 AMTimothy Jones
12/05/2022, 8:38 AMTimothy Jones
12/05/2022, 8:38 AMTimothy Jones
12/05/2022, 8:39 AMTimothy Jones
12/05/2022, 8:39 AMThomas K
12/05/2022, 8:41 AMThomas K
12/05/2022, 8:41 AMMockK
as we already have very similar unit tests, I would group it more with thatTimothy Jones
12/05/2022, 8:42 AMThomas K
12/05/2022, 8:42 AMTimothy Jones
12/05/2022, 8:42 AMSo right now I have a separate pact test class to the unit test class mainly due to using slightly different things like mockServer etcThis sounds normal to me
Timothy Jones
12/05/2022, 8:43 AMTimothy Jones
12/05/2022, 8:44 AMThomas K
12/05/2022, 8:45 AMTimothy Jones
12/05/2022, 8:45 AMTimothy Jones
12/05/2022, 8:46 AMTimothy Jones
12/05/2022, 8:48 AMThomas K
12/05/2022, 8:49 AMThomas K
12/05/2022, 8:49 AMThomas K
12/05/2022, 8:49 AMTimothy Jones
12/05/2022, 8:50 AMThomas K
12/05/2022, 8:50 AMThomas K
12/05/2022, 8:50 AMTimothy Jones
12/05/2022, 8:51 AMTimothy Jones
12/05/2022, 8:51 AMThomas K
12/05/2022, 8:51 AMTimothy Jones
12/05/2022, 8:51 AMTimothy Jones
12/05/2022, 8:52 AMThomas K
12/05/2022, 8:52 AM