Hi team, I’m trying to write some pact test in Swi...
# pact-swift
m
Hi team, I’m trying to write some pact test in Swift and I can’t find where the pact file is generated. I can see the test has failed (which I expected) but I expected to see some pact json file somewhere.
Copy code
failed - Failed to verify Pact! Actual request does not match expected interactions...

Reason:
	Missing request

Expected:
	GET /products
I tried setting the PACT_OUTPUT_DIR without much success (not sure where I’m setting it and what I’m supposed to set it to) and also tried setting it in the property of MockService without much success either.
I also see this popup continuously every time I run the test despite me clicking the Allow every time. It makes me think something is not setup properly.
m
if the test fails it won’t create a pact file
m
so… how do I make the test pass? is it related to the network connection prompt?
maybe I’m not understanding this correctly. Is the error message telling me the request is not being sent at all?
☝️ 1
m
The error message says that you expected your app to make a
GET
request to
/products
on the pact mock server, but it did not receive one
that means your client code is not pointed at the mock server and sending the request in your unit test
m
Gah I found the problem. I wasn’t using the url from the mock service correctly. 🤐
Now the test is passing and I can see the generated pact file 🎉
👏 1
m
🙌
s
I'm running into the same issue while writing my pact test. Just curious how you went about resolving this issue?
m
Did your pact test suite finish successfully? @Sarah Stenhouse if the test run fails then the file is not (over)written. The default for iOS projects is
/tmp/pacts
If you set up a
PACT_OUTPUT_DIR
environment variable (in Run > Arguments tab of your scheme) then it should be written in that folder. I normally set it to
$(PROJECT_DIR)/tmp/pacts
If testing a macOS project, then pact files are written into
Documents
folder of your app's sandbox. If testing a non-Xcode project (Linux), set the env var
PACT_OUTPUT_DIR
to where you want the file to be written. https://github.com/surpher/PactSwiftToolbox/blob/main/Sources/PactSwiftToolbox/PactFileManager.swift
There is also a convenience
init
on
MockService
class that allows you to pass in a
URL
of your directory. Have you tried that? https://github.com/surpher/PactSwift/blob/6c9c3a1b9142e353781e5f589bcb9db8895ca38d/Sources/MockService.swift#L62
s
@Marko (IttyBittyApps / pact-swift) It has never passed successfully, I keep getting this error:
Copy code
failed - Failed to verify Pact! Actual request does not match expected interactions...

Reason:
	Missing request

Expected:
	GET /products
When I run the test, I see that the base url has been replaced by the mock server url so I'm not sure why it wouldn't be communicating with the pact server.
m
Is your API client implementation triggering the request? Can you verify/debug it?
m
Can you share your code so we can take a peek?