This page provides documentation for the VOKMockUrlProtocol framework, which is used for testing network connections and responses in iOS applications.

Getting Started

To get started with VOKMockUrlProtocol, follow the steps below:

  1. Install VOKMockUrlProtocol via CocoaPods or manually by adding the framework to your project.
  2. Import the framework in your test class: import VOKMockUrlProtocol.
  3. To enable VOKMockUrlProtocol, add the following code in your test setup:

func setUp() {
// Enable VOKMockUrlProtocol
VOKMockUrlProtocol.mockResponses = [
// Define mock responses here

Mocking Network Responses

VOKMockUrlProtocol allows you to simulate network responses for specific URLs in your test environment. To mock a network response, use the VOKMockUrlProtocol.mockResponses property as shown below:

VOKMockUrlProtocol.mockResponses = [
VOKMockUrlResponse(urlRegex: “https://api.example.com/posts”, jsonString: “{ \”title\”: \”Test Post\” }”, statusCode: 200),
VOKMockUrlResponse(url: “https://api.example.com/comments”, jsonData: jsonData, statusCode: 201, headers: [“Content-Type”: “application/json”])

You can specify multiple responses for different URLs by providing an array of VOKMockUrlResponse objects. Each VOKMockUrlResponse object represents a single mock response and accepts the following parameters:

  • urlRegex (String): A regular expression pattern to match URLs that should receive this mock response.
  • url (String): An exact URL that should receive this mock response.
  • jsonString (String): A JSON string to be returned as the response body.
  • jsonData (Data): The raw JSON data to be returned as the response body.
  • statusCode (Int): The HTTP status code to be returned.
  • headers (Dictionary): Additional HTTP headers to be included in the response.

Resetting Mocks

To reset the mocked responses and revert to the default networking behavior, call the VOKMockUrlProtocol.reset() method. It is recommended to call this in your test teardown:

func tearDown() {
// Reset mock responses

Additional Functions

Function 1

Description of function 1.

Function 2

Description of function 2.

Function 3

Description of function 3.


VOKMockUrlProtocol simplifies network testing by allowing you to mock network responses in your iOS applications’ test environment. By following the instructions and using the provided functions, you can effectively simulate various network scenarios and test your app’s behavior accordingly.