Sample Code for Model-based Software Testing and Analysis with C#

ALL OF THE SOFTWARE LINKED TO THIS PAGE IS NOW INCLUDED IN THE SAMPLES PROVIDED AT THE NMODEL SITE.
The NModel site provides more samples as well. You should obtain the samples there. This page is here merely to prevent broken links.

This page provides instructions and links for sample models and other code from the book, Model-based Software Testing and Analysis with C#. It also provides some advice about developing your own model programs using the NModel framework.

Prerequisites   Sample code   Developing model programs   More information


Prerequisites

To run these samples or to develop your own, you must have .NET and NModel. You do not need Visual Studio.

.NET

Obtain .NET from Microsoft. You only need the redistributable package, not the SDK. The latest version is 3.5. If you already have version 2 or 3, they work too. You may already have .NET; it is included with Vista and with Visual Studio.

The build scripts for the sample code (discussed below) require that the Path environment variable includes the path to the C# compiler, usually C:\Windows\Microsoft.NET\Frameworks\v2.0.50727. This path should be defined in the Visual Studio Command Prompt, if you have it. Otherwise, check for it by typing the command echo %Path%. If it is not included, you must add it.

For example, on Vista use Control Panel -> System and Maintenance -> System -> Advanced system settings (menu at left) -> Environment Variables (button) -> System variables (scrolling list, scroll down) -> Path (click to select) -> Edit... (button), Variable Value: (click in text box, press end key on keyboard then type semicolon followed by path), OK (button on System Variable), OK (button on Environment Variables).

NModel

Obtain NModel from Codeplex:   http://www.codeplex.com/NModel/.   Follow the installation instructions there.

Directions for running the sample code (below) assume that the Path environment variable includes the path to the NModel programs, C:\Program Files\NModel\bin. The .msi file does not do this, so you should add it yourself (see directions above about the path to the C# compiler).

The NModel release also provides Samples.zip. That is another collection of samples, different from the ones offered at this site. You do not need them to run the samples offered here.

The NModel site also provides source code for the tools, the modeling library, and the samples in Samples.zip. You do not need that source code to run the samples offered here, or to develop your own. The basic NModel installation includes prebuilt binaries for the tools and the modeling library.

Sample code

ALL OF THE SOFTWARE LINKED TO THIS PAGE IS NOW INCLUDED IN THE SAMPLES PROVIDED AT THE NMODEL SITE.
The NModel site provides more samples as well. You should obtain the samples there. This page is here merely to prevent broken links.

Browse the sample code here. Most directories contain a README.txt file but for some reason the browser may not show it in the directory listing. You can still display its contents in the browser by appending README.txt to the directory URL in the address bar.

To obtain the sample code, download this zip archive:   mbta-samples.zip   or this tar archive:   mbta-samples.tar.

Unpacking the archive creates an mbta-samples directory in the current directory, with a subdirectory for each sample.

Each sample subdirectory contains a file README.txt that explains how to build and run the samples in that directory, and relates the programs and commands in that directory to particular sections and figures in the book. The subdirectories also contain C# source code for models and other programs (.cs), build scripts and other commands (.bat), response files that contain command options (.txt), and finite state machines that represent scenarios (.txt).

Here is a summary of all the README files: Build and run the samples at the command line. To build a sample, go the sample directory and type the command build. Then you can type other commands to demonstrate it. All these commands have the form cmd @responsefile.txt (notice the space before @). Here cmd is one of the three NModel commands mpv (model program viewer), otg (offline test generator), or ct (conformance tester), and responsefile.txt is the name of a response file.

Developing and using model programs

If you have .NET and NModel, you have everything you need to write your own model programs, analyze them, and do model-based testing. Many basic facts about model programs will be clear from these samples, for example:

A model program uses the NModel namespaces and references NModel.dll.

A model program has its own namespace. The state variables of the model program are the static fields and instance fields declared in its namespace, and the actions of the model program are the static methods and instance methods in its namespace that are labeled with the [Action] attribute.

You must use the NModel collection types Set, Sequence, Map, not the usual .NET collection types such as ArrayList.

A model program is a library: it compiles to a .dll, not an .exe.

To analyze a model program and visualize its behavior, use mpv; to generate test suites, use otg; to execute test suites or generate and execute tests on-the-fly use ct.

More information

The most complete explanations appear in the book. Here are some other sources of information:

The NModel library and commands are documented in the NModel Reference, available from the NModel site.

The NModel library is also documented in the online help:
Start Menu -> All programs -> NModel -> NModel documentation

ALL OF THE SOFTWARE LINKED TO THIS PAGE IS NOW INCLUDED IN THE SAMPLES PROVIDED AT THE NMODEL SITE.
The NModel site provides more samples as well. You should obtain the samples there. This page is here merely to prevent broken links.


Jonathan Jacky, University of Washington.   Revised 2 Nov 2008 for NModel 1.0.21029.0