SwiftNIOMock

screenshot of SwiftNIOMock

A web server based on SwiftNIO designed to be used as a mock server in UI automation tests

Overview

SwiftNIOMock is a lightweight yet powerful web server designed specifically for use as a mock server in UI automation tests, built on the robust SwiftNIO framework. This tool addresses various challenges developers encounter when running UI tests against real servers, such as network instability, fluctuating content, and the inherent delays caused by network calls. Instead of relying on a real server during testing, SwiftNIOMock allows developers to simulate responses locally, greatly improving the stability and speed of UI tests.

The server offers flexibility and control, enabling developers to manipulate its state directly from their test scenarios. This level of control not only streamlines the testing process but also ensures that tests are reliable and reproducible, regardless of changes in external systems or networks.

Features

  • Redirect Middleware: Enables developers to redirect requests to real services while logging network activity, making debugging easier with all outputs consolidated in the test runner's console.

  • Router Middleware: Grants the ability to mock specific endpoints completely, allowing finer control over the server's state and responses, essential for simulating external system interactions.

  • Record & Replay Functionality: Utilizes URLSession to record network calls and replay them in subsequent test runs, ensuring consistent behavior and guarding against unforeseen changes in external services.

  • Custom Middleware Support: Developers can create their own middleware to tailor the server to their specific testing needs, enhancing the flexibility of the testing environment.

  • Asynchronous Response Handling: The middleware functions can call the next closure asynchronously, ensuring non-blocking operations and improved efficiency during testing.

  • Lightweight Setup: Simple integration process that requires starting an instance of the server in the setUp method and stopping it in tearDown, making it easy to implement in existing test frameworks.

  • Built-in Examples: Includes example UI tests that showcase how to implement and utilize various middleware options effectively, providing a practical guide for users.