Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use mocks, stubs, or fakes to test a unit’s logic quickly and under controlled conditions; use focused integration tests with real dependencies to verify that your backend actually works with a database, filesystem, queue, or service. Most backend test suites need both. Choose based on the behavior the test must prove, not a fixed percentage of test types.

What question does each approach answer?

A test double stands in for a real collaborator during a test. The term covers several different tools, and the distinctions matter when deciding what a test can establish.

  • Mock: a substitute whose interactions can be verified, such as whether a method was called with expected arguments.
  • Stub: a substitute configured to return particular responses, including errors or edge cases.
  • Fake: a simplified working implementation that behaves like the dependency in some ways, but is not the real service. Because it is maintained separately, it can drift from the real implementation.

Google’s Testing on the Toilet article defines a test double as “an object that can stand in for a real object in a test, similar to how a stunt double stands in for an actor in a movie.” A double lets a unit test control a collaborator; it does not execute that collaborator’s real behavior.

Approach Question answered Strength Limit
Mock, stub, or fake Does this unit make the right decision with controlled inputs, or interact with a collaborator as required? Fast, isolated feedback; easy to exercise exceptional responses. Does not prove that the application can connect to or correctly use the real dependency.
Focused integration test with a real dependency Does this code work with the actual database, filesystem, queue, or service at this boundary? Exercises real behavior and can expose compatibility or integration problems at the tested boundary. Requires setup and runtime; does not replace fast tests of unit-level logic.

This is the distinction behind Martin Fowler’s warning about the confidence gap: if a test only covers a unit in isolation, “Unit tests can’t help you with that” when the question is whether the application works with the external parts it needs to talk to.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Should you mock the database in unit tests?

Yes, when the test is about application logic rather than database behavior. A service’s decision to reject an invalid request, choose a response based on a repository result, or handle a repository error can be tested with a controlled stub or mock. That keeps the test focused and makes unusual responses straightforward to exercise.

But a test using a mocked repository does not show that a SQL query is valid, a schema maps correctly, a transaction behaves as expected, or the application can connect to the database. Those are database-boundary questions. Cover them with focused integration tests against the real database when practical.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Prefer assertions on observable outcomes. Verify an interaction when the interaction itself is part of the requirement—for example, that a necessary side effect happens exactly once—rather than checking every internal call by default.

When should you use real dependencies in integration tests?

Use a real dependency when correctness depends on its actual behavior or on how your code communicates with it. The useful boundary is narrow: exercise the part of your application that reads and writes database data, accesses files, publishes to a queue, or calls an API. A targeted test can reveal incompatibilities a configured double cannot, without turning every unit test into a full-stack run.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
  • Use a real database to check data-access code against the database implementation and configuration the application relies on.
  • Use a real filesystem when path, permissions, or file-operation behavior is part of the risk being tested.
  • Use a real queue or service when the integration protocol, client configuration, or message exchange needs verification.

Run these tests against a local dependency or a dedicated, isolated test environment—not production. If the service cannot reasonably run locally, use a dedicated test instance where available. A fake can help with fast tests, but its behavior should be checked against the real implementation where feasible so that the substitute remains faithful.

Are mocks enough for backend testing?

No—not if you need confidence that the backend integrates correctly with its dependencies. Mocks can establish that a unit responds correctly to controlled inputs or makes an expected call. They cannot establish that the real database accepts the query, that the service endpoint and client agree, or that the queue interaction works as intended.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Mocks are still valuable: they support fast feedback, isolate the behavior under test, and let tests cover failures that may be difficult or expensive to trigger in a real service. The gap is not a flaw in mocks; it is a limit on the question they answer. Pair them with integration tests at boundaries where real behavior matters.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Can Testcontainers help run real dependencies?

Testcontainers can start disposable real services in Docker containers for integration tests. Its documented prerequisite is a Docker-API-compatible container runtime, so check that one is available in local development and CI before adopting it. Containerization can make dependency setup repeatable, but the tests still start and use a real service.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

For Java database tests, Testcontainers documents use with real MySQL, PostgreSQL, or Oracle instances and notes that this approach is slower than H2. Its guidance is to keep database-hitting tests few and use mocks for higher-level components where appropriate. In practice, keep container-backed tests focused, control their data and isolation, and account for startup time in the team’s environment.

How to choose the test boundary

  1. Identify the behavior. If the test concerns a unit’s decision logic, use a stub, mock, or maintained fake where it helps isolate the behavior.
  2. Identify the boundary risk. If the question is whether your code communicates correctly with a database, filesystem, queue, or API, include that real dependency in a focused integration test when practical.
  3. Choose an isolated environment. Run a local dependency or a dedicated test instance; never point automated tests at production.
  4. Handle impractical dependencies deliberately. Use a faithful fake or dedicated test instance, and check the fake against the real implementation where feasible.
  5. Keep feedback useful. Reserve real-dependency tests for meaningful boundaries and use doubles for faster, higher-level collaboration tests. There is no evidence-based universal ratio that fits every codebase.

For additional guidance, see Google’s overview of test doubles, Martin Fowler’s practical test pyramid, and the Testcontainers for Java database containers documentation.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.