Latest / Software Testing with Fexingo: QA, Automation, and Reliable Software Engineering / Testing the Invisible Layers of Modern Software
Transcript
- Lucas: The most expensive bugs aren't the ones that crash your app with a stack trace. They're the ones that slip through because the code looks clean, the unit tests pass, but the underlying assumption about how two systems talk to each other was wrong from the start. Luna: Exactly. It's that gap between what we think the interface is doing and what it actually does in production. Like when a mock returns zero instead of null, and suddenly your billing logic thinks a customer owes nothing. Lucas: Right, and I want to talk about this today because so many teams treat dependency injection as just a way to make code testable, not as a structural risk. If you don't test the contract between those injected dependencies, you're building on sand. Luna: And yet, everyone loves a good mocking framework. It feels like control until the real API changes shape overnight. Lucas: Let me share a story from last quarter involving a mid-sized fintech client of mine. They had a beautifully architected payment processing system using heavy dependency injection. Every service was isolated, every interface was mocked, and their CI pipeline was green across the board. Luna: So why did they have a problem? Lucas: Because they never tested what happened when one of those injected services returned a different error code than expected. The payment gateway changed its response format slightly, but the mock in their test suite still returned success. Their reconciliation process assumed success, stopped logging errors, and missed three million dollars in transactions over two weeks. Luna: That is terrifying. So the test passed, but the reality failed. How do you catch that without waiting for a month-end audit? Lucas: You have to shift from testing behavior to testing structure. This means validating the actual data contracts, not just the happy path. If you're injecting a database repository, you need to know what happens when it throws a timeout versus when it returns an empty list. Those are structurally different outcomes that behave completely differently downstream. Luna: But isn't that slower? Writing tests for every possible structural variance sounds like a maintenance nightmare. Lucas: It is slower if you do it manually. But if you use property-based testing tools, you can generate hundreds of edge cases automatically. You define the rules of the data, not the specific values. The tool then tries to break your logic by finding the smallest input that fails your contract. Luna: I've used that for validation logic before, but never for dependency interactions. Does it work well with external APIs? Lucas: Not directly with live APIs, which is the trap. Most teams try to mock everything to avoid flaky tests. But mocks lie. A mock doesn't know about network latency, partial responses, or schema drift. You need a middle ground where you test the integration points with realistic, but controlled, data shapes. Luna: So maybe a contract test that runs against a staging environment that mimics the real thing? Lucas: Precisely. And this brings us to the donation segment, because running these kinds of robust tests requires infrastructure that isn't cheap. Lucas: Quick honest thing — a handful of listeners chip in monthly through buy me a coffee dot com slash fexingo, and that's literally what funds making this many of these ad-free episodes. No sponsors, no tracking, just us talking tech. Luna: Yeah, it keeps the lights on and lets us dig into the messy stuff like this without worrying about a sponsor's compliance team. If that resonates, check out the link Lucas mentioned. Lucas: Anyway, back to the architecture. The key insight here is that mocking creates a false sense of security. When you mock a dependency, you are essentially saying, 'I assume this behaves exactly like I told it to.' But in distributed systems, assumptions are liabilities. Luna: It's like assuming your car's navigation will always find the fastest route, only to realize the map data is outdated. You're driving blind. Lucas: Spot on. So, how do you fix it? First, stop mocking third-party libraries unless absolutely necessary. Use adapters. Wrap the external call in your own interface, but test that wrapper against a real or near-real instance. Luna: That adds complexity to the codebase though. Now you have extra layers to maintain. Lucas: Yes, but it buys you resilience. Think of it as insurance. The extra layer is small, but it decouples your core business logic from the volatility of external systems. If the external API changes, you only update the adapter, not your entire domain model. Luna: So the cost of the bug is higher than the cost of the extra code. That makes sense financially. Lucas: Exactly. Let's look at a concrete example. Say you have a notification service that sends emails. Instead of mocking the email provider, you create a NotificationSender interface. In tests, you might use a dummy sender that logs messages. But in integration tests, you spin up a local mail catcher or use a sandbox account. Luna: And you verify the payload, not just that the method was called. You check that the subject line, the body template, and the recipient list are all correct. Lucas: Yes. Because if the template engine breaks, or the recipient list has a formatting error, your mock won't tell you. But a real integration test will. It catches the silent failures that mocks miss. Luna: This feels like a lot of overhead for small startups. Do they really have the bandwidth for this? Lucas: They should, because the alternative is paying for it in customer support tickets and churn. But you don't need to test everything. Focus on the critical paths. Payment flows, authentication, data synchronization. Those are the places where structural failures hurt the most. Luna: So prioritize the high-risk areas. Don't boil the ocean. Just make sure the parts that matter are solid. Lucas: Right. And use automated tools to help. Static analysis can catch some interface mismatches before you even run tests. Linters can enforce naming conventions that make debugging easier. These are low-effort wins that improve the overall health of your codebase. Luna: I like that. Low effort, high reward. It's about working smarter, not harder. But what about legacy code? Refactoring old monoliths to add these adapters seems impossible. Lucas: It's hard, but not impossible. You use the Strangler Fig pattern. Wrap the old functionality in a new interface gradually. Start testing the new wrapper, then slowly migrate the internal calls. Over time, the old code becomes irrelevant, and you've built a more testable system without rewriting everything at once. Luna: Incremental improvement. It's less scary than a big rewrite. And it gives you immediate value with each step. Lucas: Exactly. And remember, testing isn't just about catching bugs. It's about documentation. Your tests tell you how the system is supposed to behave. If you remove them, you lose that knowledge. Luna: That's a good point. Tests are living documentation. If they're broken or missing, you're flying blind on your own assumptions. Lucas: So, my advice for this week is to pick one critical dependency in your system. One that talks to an external service or a complex internal module. Write a structural test for it. Not a mock test, but a real interaction test. See what breaks. Luna: Start small. Find one fragile assumption and stress-test it. That's how you build reliability, one layer at a time. Lucas: Agreed. And if you find something surprising, share it. We love hearing about the bugs that slipped through. What's the worst silent failure you've seen? Luna: That would be the database migration that ran on weekends and locked tables for four hours. Silent, but very loud when it crashed Monday morning. Lucas: Ouch. At least that one was visible. The silent ones are the ones that keep us up at night. Thanks for listening, and let's keep building better software.