Swiftpack.co - justeat/Shock as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by justeat.
justeat/Shock 6.2.0
A HTTP mocking framework written in Swift.
⭐️ 90
🕓 1 year ago
.package(url: "https://github.com/justeat/Shock.git", from: "6.2.0")


An HTTP mocking framework written in Swift.


The DemoApp is a sample app that shows how to use the Shock framework.

  • Test Shock: will show how to emebed Shock in your app and how to use it to mock API calls.
  • Test ShockRecorder: will show how to use ShockRecorder to record API calls and how to use the recorded API calls to mock API calls during UI Tests.

Recording API calls with ShockRecorder

To record API calls during the demo app execution, enable the SAVE_API_RESPONSES_ON_DISK argument passed on launch in the DemoApp scheme.

Once the flag is enabled, the API responses will be saved in the data_responses folder, you can find the path in the console logs, e.g.

[ShockRecorder] filePath: file:///Users/user/Library/Developer/CoreSimulator/Devices/BE295F5C-5D11-4C70-A74E-52AF3389F0C9/data/Containers/Data/Application/A49E2BCB-1E12-4A34-8DE8-9262742BC564/Documents/data_responses/2023-09-23-16-23-31_001_GET_api_breeds_image_random.json

To record API calls during the UITests execution:

  • Uncomment the line app.launchArguments.append("SAVE_API_RESPONSES_ON_DISK")
  • Make sure that UI Test are not executed in parallel.
  • Run the UI Tests (They should fail as the API response changes every time)
  • Fix the UI Tests with the new API responses, if you want to adapt them the new responses.
  • Copy the new API responses from data_responses/UITests folder to Demo/UITests/Resources/RecordedMocks folder once you want to update the old API responses.


Stars: 90
Last commit: 5 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

1 year ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics