Model-Based Testing (MBT) Using GraphWalker
A beginner-friendly guide to building your first test model
When my college professor assigned us to explore some software testing technique, I wasn’t sure what to pick. I wanted something practical, not just theory, so I decided to give Model-Based Testing a shot mainly because it sounded promising and a bit different from the usual.
As I started digging in, I realized MBT isn’t just another testing buzzword. It’s actually a smart way to save time and catch tricky bugs by modeling how your app behaves, then letting a tool do most of the test generation work for you.
So if you’re just getting started or looking for a simple explanation that actually makes sense, you’re in the right place. I’ve broken everything down as clearly as I wish someone had done for me when I first googled “Model-Based Testing explained like I’m five.”
What is Model-Based Testing (MBT)? Breaking It Down
Let’s say you have a web app or mobile app with screens, buttons, forms, error messages, and so on. Normally, testers write test cases by hand to cover all these features and user actions.
Model-Based Testing flips this around. Instead of writing each test, you first create a model — a kind of map or blueprint — that represents how your app works. This model describes:
- The states your app can be in (like “Login Screen”, “Dashboard”, “Error Page”)
- The actions or transitions that move the app from one state to another (like “User clicks login”, “User enters password”)
Once the model is ready, a tool automatically generates test sequences based on the possible paths through the model. This means your test cases are created from the model instead of being manually written.
Why Is This Useful?
Because writing test cases manually can get messy and repetitive. MBT helps by:
- Covering more scenarios: It explores all possible paths in your model, including edge cases you might miss.
- Saving time: Update your model once, and your tests update automatically — no need to rewrite dozens of test cases.
- Helping teams understand: Visual models give everyone a clear picture of how the system behaves.
- Finding bugs earlier: Because it tests all paths, it catches unexpected issues sooner.
So, Where Does GraphWalker Come In?
GraphWalker is a popular tool designed to help with MBT. It lets you:
- Create a model using graphs (nodes and edges) that represent your app’s states and transitions.
- Define testing goals, like “visit all states” or “cover all transitions.”
- Generate test paths that follow the rules you set.
- Run these paths as tests with popular automation frameworks (JUnit, Selenium, RestAssured, and more).
Real-World Example: Modeling a Simple Login Flow
Let’s make this real. Say you want to test the login functionality of your app.
You’d model it like this:
States:
- Start
- Login Screen
- Dashboard (after successful login)
- Error Message (if login fails)
Transitions:
- Open login page
- Enter username and password
- Click login button
- Display dashboard (if credentials are correct)
- Show error message (if credentials are wrong)
Instead of writing three or four different test cases, you model this once. GraphWalker then explores all the possible paths (valid and invalid logins) and runs tests automatically.
How to Set Up GraphWalker and Run Your First MBT Project
Now let’s go hands-on. Here’s how you can set up GraphWalker and run your first real MBT test from scratch.
What You’ll Need
- Java (JDK 11+)
- Maven
- yEd Graph Editor (for drawing models)
- A basic Java test setup (JUnit)
- GraphWalker CLI or Java dependency
Project Structure
mbt-login-example/
├── pom.xml
├── src/
│ └── test/
│ └── java/
│ └── LoginTest.java
├── models/
│ └── login.graphml
└── graphwalker.jsonStep 1: Install GraphWalker
Clone and build GraphWalker:
git clone https://github.com/GraphWalker/graphwalker-project.git
cd graphwalker-project
mvn clean installOr add it directly to your Maven project:
<dependency>
<groupId>org.graphwalker</groupId>
<artifactId>graphwalker</artifactId>
<version>4.3.1</version> <!-- Use latest -->
</dependency>Step 2: Create Your Model in yEd
Use yEd to draw your model:
- Use circles (nodes) for states:
v_LoginPage,v_Dashboard, etc. - Use arrows (edges) for actions:
e_EnterValidCredentials,e_RetryLogin
Add a name field to each node/edge using right-click → Properties.
Get Nehabimal’s stories in your inbox
Join Medium for free to get updates from this writer.
Save your model as login.graphml inside the models/ folder.
Create a graphwalker.json in your project root:
{
"model": "models/login.graphml",
"pathGenerator": "random(edge_coverage(100))",
"startElement": "v_LoginPage"
}This tells GraphWalker to explore all transitions starting from the login page.
Step 4: Write the Java Test Logic
Here’s a basic test class that matches your model:
import org.graphwalker.java.annotation.*;
import org.graphwalker.java.test.Result;
import org.graphwalker.java.test.TestExecutor;
import static org.junit.Assert.assertTrue;
public class LoginTest {
@BeforeExecution
public void setup() {
System.out.println("Starting test...");
}
@Edge()
public void e_OpenLoginPage() {
System.out.println("Opening login page...");
}
@Edge()
public void e_LoginWithValidCredentials() {
System.out.println("Logging in with valid credentials.");
}
@Edge()
public void e_LoginWithInvalidCredentials() {
System.out.println("Logging in with invalid credentials.");
}
@Vertex()
public void v_LoginPage() {
System.out.println("On login page.");
}
@Vertex()
public void v_Dashboard() {
System.out.println("Reached dashboard.");
}
@Vertex()
public void v_ErrorMessage() {
System.out.println("Error message displayed.");
}
@Test
public void runTest() {
Result result = new TestExecutor()
.addPathGenerator("random(edge_coverage(100))")
.addModel(LoginTest.class)
.execute();
assertTrue(result.hasPassed());
}
}Each method name matches a node (v_) or edge (e_) in your model.
Step 5: Run It!
Now just run your tests:
mvn testYou’ll see a sequence of steps executed based on your model.
GraphWalker handles the path generation and calls the appropriate methods for you!
Pros and Cons of Using GraphWalker and MBT
What I Loved
- Models are reusable and easy to understand.
- Test coverage is better and less error-prone.
- Automation-ready and scalable.
- Open source and free.
What Was a Bit Tricky
- Slight learning curve in the beginning.
- Models can get complex for big systems.
- Docs could be more beginner-friendly.
When Should You Try Model-Based Testing?
Use MBT if:
- Your app has many user flows and decision points.
- You want to automate regression and edge-case testing.
- You need better coverage without writing tons of test scripts.
Maybe skip it if:
- Your project is tiny and only has a few flows.
- You don’t have automation in place yet.
Example usecases:
- Web & Mobile Workflows
- API Testing
- Embedded Systems or IoT Devices
- Banking or Insurance Software
- Regression Testing in Agile/CI Pipelines
- UI/UX Testing
Final Thoughts
Model-Based Testing with GraphWalker turned out to be an eye-opener for me. It’s a practical, structured way to handle complex testing scenarios without drowning in manual test cases.
If you want to get better coverage, save time, and understand your app’s behavior more clearly, MBT is definitely worth a try. Once it clicks, it feels like having a testing assistant who never sleeps!




