ModelJUnit 1.0

ModelJUnit is a Java library that extends JUnit to support model-based testing.

  Add it to your Download Basket!

 Add it to your Watch List!


Rate it!
send us
an update
GPL (GNU General Public License) 
3.7/5 21
Mark Utting
ROOT \ Programming \ Quality Assurance and Testing
ModelJUnit is a Java library that extends JUnit to support model-based testing. The library is an open source tool, released under the GNU GPL license.

ModelJUnit allows you to write simple FSM or 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.

Here is a release 1.0 of ModelJUnit. Note that it uses the annotations feature of Java 5.0, so requires JDK 1.5 or higher to run.

This version 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, is discussed from 43:50 onwards.

The ModelJUnit.jar file, which you need to use the tool. (this was compiled with JDK 1.6)

Online Javadoc documentation for ModelJUnit (start by reading the Description of the modeljunit package).

A downloadable version of the documentation.
The source code of is part of the CZT project. The development sources of ModelJUnit can be checked out using these two commands:

svn co modeljunit
svn co pom.xml

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

Tester tester = new RandomTester( new FSM() );
new VerboseListener(tester.getModel())); // print the tests
tester.generate(20); // generate tests randomly

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 and use Java 1.6):

java net.sourceforge.czt.modeljunit.examples.FSM

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, put modeljunit.jar and junit.jar in your classpath, then run:

java net.sourceforge.czt.modeljunit.gui.Main

Last updated on September 18th, 2007

#Java library #Model-based testing #EFSM models #Java #library #FSM #EFSM

Add your review!