A framework to make writing UI tests a breeze!
- Allows you to record and serve up canned responses! 🥫
- No reliance on a server; making the UI tests deterministic and run super fast! 🏃♂️🚀
- Allows for serving up mocks curated to the test case scenario currently running! 👩🍳
- Enables running tests in parallel speeding up pipeline runs without any extra effort! 👯♀️
- Add
Wiretapp
as a swift package to your project and in the target modal addWiretapp
to your app target andwiretappTest
to your UI Test target
- Next, click on the scheme drop down and select
Edit Scheme
for your main app target - In the
Environment Variables
add the following variableswiretappResponses
with the path set to where you want the mock responses to be stored and read from (eg;$(SOURCE_ROOT)/MockResponses/
)wiretappRecording
with the value set totrue
orfalse
, which signifies wether record mode is turned on or off (can also be set totrue
and the variable can be checked/unchecked instead)
- Add the
MockResponses
folder to your project as areference folder
(blue folder icon)- Do
Add Files to [project]
, selecting the folder you want to add and making sure theCreate folder references
radio button is checked
- Do
And thats it, you're all set! 🎉🥳
- In your app code
- Import
Wiretapp
- call
Wiretapp.registerSharedSession()
(Wiretapp.register(configuration:)
if you're using a custom implementation ofURLSession
orAlamofire
) before your app starts making Network requests
- Import
- Run your app through the scenario you'll be writing the UI test for
- You should start seeing the JSON responses start appearing under the
recorded
folder 🤗
- You should start seeing the JSON responses start appearing under the
- In your UITest target
- Import
WiretappTest
- Inherit your XCUITest with
WiretappBaseTestCase
- Import
- Drag and drop the responses inside your
-recorded
folder under a new directory structure insideMockResponses
a directory named according to your test scenario- Example for a test case
test_LoginSuccessful
insideLoginTests
, the directory would beMockResponses/LoginTests/LoginSuccessful
- Example for a test case
Run the test case and it should be running off of the mock JSON responses inside the mock responses folder! 🍾
You can tweak the status
code and modify the response
data in the JSON files to simulate different scenarios ( error cases ie. 404 / 400 / etc ) for your tests!