Effective Strategies for Writing Unit Tests with External Dependencies like Databases and APIs

This page summarizes the projects mentioned and recommended in the original post on dev.to

Stream - Scalable APIs for Chat, Feeds, Moderation, & Video.
Stream helps developers build engaging apps that scale to millions with performant and flexible Chat, Feeds, Moderation, and Video APIs and SDKs powered by a global edge network and enterprise-grade infrastructure.
getstream.io
featured
InfluxDB – Built for High-Performance Time Series Workloads
InfluxDB 3 OSS is now GA. Transform, enrich, and act on time series data directly in the database. Automate critical tasks and eliminate the need to move data externally. Download now.
www.influxdata.com
featured
  1. Nock

    HTTP server mocking and expectations library for Node.js

    For testing third-party API calls, you can use libraries such as WireMock or Nock. These tools allow you to simulate HTTP requests and responses, helping you test how your application behaves when interacting with an external service. For example, you can mock successful responses, simulate errors, or test timeouts, all without making real HTTP requests.

  2. Stream

    Stream - Scalable APIs for Chat, Feeds, Moderation, & Video. Stream helps developers build engaging apps that scale to millions with performant and flexible Chat, Feeds, Moderation, and Video APIs and SDKs powered by a global edge network and enterprise-grade infrastructure.

    Stream logo
  3. WireMock

    A tool for mocking HTTP services

    For testing third-party API calls, you can use libraries such as WireMock or Nock. These tools allow you to simulate HTTP requests and responses, helping you test how your application behaves when interacting with an external service. For example, you can mock successful responses, simulate errors, or test timeouts, all without making real HTTP requests.

  4. pact-js

    JS version of Pact. Pact is a contract testing framework for HTTP APIs and non-HTTP asynchronous messaging systems.

    Tools like Pact enable contract-driven development by defining a contract between the API consumer (your application) and the provider (the external API). This contract specifies the expected requests and responses, and you can then use tools like Pact to ensure that both parties adhere to this contract.

  5. Bogus

    :card_index: A simple fake data generator for C#, F#, and VB.NET. Based on and ported from the famed faker.js.

    Sometimes, especially when testing data-driven applications, it is important to simulate a wide variety of inputs and conditions. One of the best ways to achieve this is by using fake data generators. Tools like Faker (Python) or Bogus (C#) allow you to generate large volumes of realistic but random data. This is particularly useful when you need to test how your code handles various types of data (such as user information, addresses, or product details) without relying on real data.

  6. TimeMock

    Discontinued [GET https://api.github.com/repos/pieceofsummer/TimeMock: 404 - Not Found // See: https://docs.github.com/rest/repos/repos#get-a-repository]

    For time-dependent logic, libraries such as time-machine (JavaScript) or TimeMock (Python) can help you mock the system clock, allowing you to simulate different times and scenarios without actually waiting for real time to pass. This is particularly useful for testing timeouts, scheduled tasks, and date-based logic.

  7. vcr

    Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests.

    For network-dependent code, libraries like nock (JavaScript) or VCR (Ruby) allow you to record and replay network interactions. This ensures that tests are repeatable and do not require real network calls, while still testing how your code behaves when interacting with external services.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts

  • Good Postman Alternatives? Here're My Top 15

    2 projects | dev.to | 9 May 2025
  • 3 Types of Chaos Experiments and How To Run Them

    6 projects | dev.to | 24 Apr 2025
  • How to Run Tests in Visual Studio Code: A Complete Guide

    4 projects | dev.to | 6 Mar 2025
  • Testing

    2 projects | dev.to | 12 Nov 2024
  • How to Shift Testing Left: 4 Tactical Models

    1 project | dev.to | 29 Oct 2024

Did you know that Ruby is
the 12th most popular programming language
based on number of references?