The ModelJUnit Model-Based Testing Tool

Authors: Dr Mark Utting, Gian Perrone, Jerramy Winchester, Scott Thompson,
Rong Yang, Pele Douangsavanh, Celia Lai, Julian Utting.
From: Department of Computer Science, The University of Waikato, New Zealand.
Sourceforge Site:

ModelJUnit is a Java library that extends JUnit to support model-based testing. Models are extended finite state machines that are written in a familiar and expressive language: Java. ModelJUnit is an open source tool, released under the GNU GPL license.

ModelJUnit allows you to write simple finite state machine (FSM) models or extended finite state machine (EFSM) models as Java classes, then generate tests from those models and measure various model coverage metrics. The principles behind ModelJUnit are described in Sections 5.2 and 5.3 of our book, Practical Model-Based Testing.

Latest Version of ModelJUnit

The latest version of ModelJUnit is available for download from the Sourceforge development site.

Alternatively, you can check out the latest sources of ModelJUnit using the following SVN command. Then look in modeljunit/src/main/java/nz/ac/waikato/modeljunit/examples for examples of using ModelJUnit.

      svn checkout svn:// modeljunit-code

Documentation and Introductory Example

Version 1.0 of ModelJUnit was presented in a Google Tech Talk by Mark Utting in August 2007. The first 30 minutes of the talk are an introduction to model-based testing, ModelJUnit is discussed from 28:20 onwards and a more sophisticated commercial tool, LEIRIOS Test Designer (now called Smartesting CertifyIt), is discussed from 43:50 onwards.

Here is an example model,, which shows how you can write the following simple FSM model in the ModelJUnit style.

[FSM model with 3 states: s0, s1, s2]

We can easily generate some tests from this model, by executing the Java code:

    Tester tester = new RandomTester( new FSM() );
    tester.addListener("verbose"); // print the tests
    tester.generate(20); // generate a sequence of 20 random tests

The main method of the FSM class shows a more sophisticated version of this, which also measures the model coverage metrics of the generated test suite. It produces this output. You can run this main method as follows (you must have modeljunit.jar and junit.jar in your classpath):


This example just prints messages as the model is executed. The generated messages could be saved in a file and used as a test script for later test execution (offline testing). But we usually use ModelJUnit for online testing, where the tests are executed on the system under test (SUT) as they are generated.

To do online testing, the test generation code within the above main method is usually written within the TestXYZ() methods of your JUnit test classes, so that each time you run your JUnit test suite, you will generate a suite of tests from your FSM model. Also, the @Action... methods in your model class will include code to call the methods of your SUT, check their return value, and check the status of the SUT. In this way, every time you run your JUnit tests, the model is used to generate a sequence of @Action... calls and test your SUT.

A new and experimental feature of ModelJUnit is a GUI interface, which allows you to generate tests by pointing and clicking, or to generate the code that generates the tests. To run the GUI, you can just double-click on the Modeljunit.jar file, or put it in your CLASSPATH, then run:


Feedback welcome!

Related Work

Other similar open-source model-based testing tools include:
Last modified: Sat Oct 10 16:54:25 AEST 2015