πŸ§ͺMocking Network Data

Closed Beta: Network Traffic Interception & Stubbing is currently under development and only available to a selected group of companies on paid plans.

1. Feature Overview

Network Traffic Interception & Stubbing enables you to capture, observe, and modify network calls within your mobile application. By defining rules for specific endpoints, you can replace real responses with locally hosted or predefined data, helping create stable and predictable testing scenarios.

Key Benefits

  • Predictable Testing Environments: Bypass external services and return consistent data for repeated tests.

  • Faster Debugging: Isolate and troubleshoot issues without relying on live backend availability.

  • Flexible Response Modification: Apply partial or full stubsβ€”e.g., fully replacing responses or editing certain fields.


2. Supported Use Cases

2a. Predefined Mock Responses

  • Static Templates: Serve a locally stored JSON or other data format for a targeted endpoint.

  • Full or Partial Replacement: Either completely override the response or alter specific data fields (e.g., status code, headers, JSON content).

2b. Editable Local Responses

  • Local Editing: Prepare a template (e.g., JSON) that you can modify directly on your machine.

  • Immediate Testing: Observe how the mobile app behaves with updated content without waiting for backend changes.

2c. Replay of Recorded Network Sessions

  • Recorded Traffic: Capture real requests and responses, then store them for future playback.

  • Consistent Reproduction: Ideal for reproducing issues reported by QA or users under exact conditions.


3. Step-by-Step Setup and Usage

  1. Install or Enable the Interceptor: Ensure your development/testing environment is configured to allow traffic interception. Some tools require a mobile proxy app or a library in your project.

  2. Define Interception Rules: Specify conditions under which requests should be intercepted (e.g., matching a URL like https://api.example.com/* or the HTTP method).

  3. Create a Mock Response: Sample Mock File (JSON) Store this file (e.g., home_feed_mock.json) in your project:

{
  "status": 200,
  "headers": {
    "Content-Type": "application/json"
  },
  "body": {
    "title": "Mocked Homepage",
    "description": "This is a mocked response used for testing.",
    "items": [
      {
        "id": 1,
        "headline": "Mocked Headline 1",
        "content": "Sample content for item 1"
      },
      {
        "id": 2,
        "headline": "Mocked Headline 2",
        "content": "Sample content for item 2"
      }
    ]
  }
}

Note on Editing: Adjust fields (e.g., title or items) to reflect the data you need to test.

  1. Apply the Mock

  • Map the interception rule (from Step 2) to your local mock file.

  • If your tool allows partial stubs, specify only the fields you want to modify; otherwise, provide the entire replacement response as seen above.

  1. Test in Your Mobile App

  • Run your app on a device or emulator connected to the intercepting environment.

  • Trigger the network request. The app should now receive your stubbed response instead of the real server response.

  1. Validate & Iterate

  • Inspect the app’s behavior to ensure it matches your expectations.

  • Adjust your mock data as needed, re-run tests, and monitor logs to confirm proper interception.


4. Best Practices

  • Maintain a Clear Naming Convention: Label each mock file or rule clearly (e.g., home_feed_mock.json).

  • Disable Caching: Clear or disable caching on the test device to ensure new mock data is always fetched.

  • Version Control Your Mocks: Track changes to mock files in source control so that teams can revert or compare versions easily.

  • Limit Production Usage: Reserve interception for testing and development environments; bypassing real server logic in production is discouraged for security and data integrity reasons.

Last updated