Latest / Software Testing with Fexingo: QA, Automation, and Reliable Software Engineering / How Model-Based Testing Catches Edge Cases Manual Scripts Miss
Transcript
- Lucas: So Luna, have you ever had that sinking feeling after a release, when a user reports a bug that seems obvious in hindsight, but none of your test scripts caught it? Luna: Oh, absolutely. I still remember a time we rolled out a new checkout flow, and someone clicked 'back' then 'submit' at just the wrong moment, and the order went through twice. Our manual scripts had like twenty scenarios, but none combined navigation back and resubmission. Lucas: Right. That's exactly where model-based testing can help. Instead of writing individual test scripts, you build a model of how the system is supposed to behave — its states and transitions — and then let a tool generate test cases from that model. It automatically explores edge combinations humans tend to miss. Luna: And we're able to talk about approaches like this because our show is listener-supported and ad-free. If you find value in these practical deep dives, you can support us at buy me a coffee dot com slash fexingo. It keeps the content independent and focused on what matters. Lucas: Exactly. Anyway, let's get into how model-based testing actually works with a concrete example. Imagine you're testing a simple vending machine. It starts in an idle state, you insert coins, you select a product, it dispenses, and you get change. That's a finite state machine. Luna: A classic. You might test happy path: insert correct coins, select item, get drink. But what about inserting coins, then pressing the coin return, then selecting an item? Or inserting coins, selecting an item that's out of stock, then selecting another? Lucas: Exactly. A model captures all states and all transitions. You define the rules: 'if state = idle and event = insertCoin, go to state hasCredit', and so on. Then a model-based testing tool like GraphWalker or Spec Explorer can traverse that model and generate test sequences that cover every possible path, or every pair of transitions. Luna: And it automatically includes those sequences you'd never think to write by hand. How do you even start building a model? Do you need a formal specification? Lucas: Not necessarily. You can start with a simple state diagram — drawn on a whiteboard or in a tool like PlantUML. The key is to identify the meaningful states and the events that cause transitions. Then you write the model in a language like YAML or a dedicated DSL, depending on the tool. GraphWalker, for example, uses a simple notation. Luna: Okay, so you've got a model. Then what? The tool spits out a bunch of test cases. But how do you turn those into executable tests? Lucas: The generated sequences are abstract — sequences like 'insertCoin, selectItem, dispense, takeChange'. You map those to actual test code: each abstract action becomes a function call. So you write a small adapter layer that glues the model to your system under test. The tool then runs all generated sequences, checks that the system's actual state matches the model's expected state after each transition. Luna: That sounds like a lot of upfront work. When does it pay off? Lucas: It pays off when your system has many states or complex business rules — think payment processing, order workflows, IoT device control. A banking client of mine used model-based testing for their fund transfer module. They had twenty-five states and fifty transitions. Manual maintenance of test scripts was taking days per release. With the model, they generated over three thousand unique test sequences in minutes, including sequences where a user started a transfer, then cancelled, then tried again before the cancellation completed. Luna: That double-submission bug again. I bet that sequence would never have been in their manual regression suite. Lucas: Exactly. And it didn't just catch ordering bugs. The model also revealed impossible sequences — like trying to confirm a transfer that was already cancelled. That forced the team to realize their model was missing a state, which meant the real system had an undefined behavior. They fixed it before release. Luna: So model-based testing also helps you validate your understanding of the system. If you can't model it cleanly, you probably don't understand it well enough. Lucas: Precisely. The model becomes a shared artifact between developers, testers, and product owners. Everyone can review it. And because it's executable, you get immediate feedback on consistency. There's no ambiguity. Luna: What about limitations? It can't be a silver bullet. Lucas: It's not. First, you need a system with a clear state machine. Not everything fits — heavy data processing pipelines, for instance, are better served by property-based testing. Second, the model is an abstraction; it might miss details like timing or concurrency. And third, building and maintaining a model requires discipline. If the model drifts from the implementation, your generated tests become misleading. Luna: So you need to treat the model as live documentation, updating it alongside code. Lucas: Exactly. But when you do that, it becomes a powerful force multiplier. It's not about replacing all manual testing — it's about covering the combinatorial explosion that humans can't. In that banking case, they estimated that model-based testing increased coverage of state transitions from 40% to 92%, with a fraction of the maintenance effort. Luna: That's a compelling number. For a listener starting out, which tool would you recommend? Lucas: GraphWalker is a good starting point — it's open source, has a simple model language, and integrates with Java and.NET. If you're in a Microsoft shop, Spec Explorer is powerful but has a steeper learning curve. There's also NModel for.NET, and fsm2 for Python. Start with a small, well-understood module, maybe a login flow or a shopping cart, and see how it feels. Luna: And if someone is convinced, what's the first step after choosing a tool? Lucas: Draw the state diagram on paper. Identify all states and all events. Then write the model in the tool's format, even if it's just three states and four transitions. Get it generating tests. Then wire up the adapter to your system. By the time you have five states, you'll already be generating dozens of test sequences you never wrote by hand. Luna: So it's incremental. You don't need to model the whole universe on day one. Lucas: Exactly. Start small, prove the value, then expand. Over time, you'll build a library of models that cover your critical business logic. And when the next release adds a new state, you update the model and rerun — the tool handles the rest. Luna: I think I'll try modeling our cart state machine next sprint. Thanks for digging into this, Lucas. Lucas: You're welcome, Luna. And for listeners — next time you face a complex workflow bug, consider whether a model might have caught it. The upfront investment usually pays for itself the first time it finds a corner case that would have hit production.