Model-based testing with Spec# and Spec Explorer

Jon Jacky, University of Washington
jon@u.washington.edu

Introduction
Theme
Spec Explorer tool
Concepts and vocabulary
Spec# language
   Concepts
   Features
Modeling
   Abstraction
   Coding
Exploration
   Algorithm
   Configuration
   Properties and state groupings
   Scenario control
   Methodology
   vs. model checking
Test case generation
Conformance testing
Testing nondeterministic systems
On-the-fly testing
Integration with other test tools


Introduction

top


Theme

Spec# "model program" (executable specification) serves as

top


Spec Explorer tool

Supports specification and testing

Supports different ways of testing

top


Concepts and vocabulary

State-based worldview as in Z, VDM, TLA, ...

State
Information stored in a system (in a program, state variables)
Action
Unit of behavior, may change state (but need not, could be a function)
Scenario
Sample of behavior, sequence of actions
Level of abstraction
Choice of variables and granularity of actions to test
(for example: actions are API method calls, state is certain static variables)
Specification
Represents all allowed scenarios (at chosen level of abtract.)
Test case
A particular scenario (could be one action, usually more)
Test suite
Collection of test cases

top


Spec# language concepts

Extends C#, the production programming language

History: based on AsmL compiler, provides most AsmL features with C# syntax

Contract: (Part of) specification expressed in the programming language

Declarative contract: pre, post, invariant

Model program: method bodies

top


Spec# language features

Declarative contracts

Model programs

top


Modeling: Abstraction

Write minimum code needed to generate scenarios of interest --- no need to be comprehensive

Choose level of abstraction (state variables, actions in IUT to test)

Be careful with objects (no isomorph elimination), maybe use value types instead

Model introduces another state space, reconcile with IUT during conformance test

top


Modeling: Coding

To code each action

Distinguish top level [Action] methods from helper methods

Possibly write Main method(s) to simulate scenario(s)

top


Test design

Generating test suites from Spec# model

Rationale: there must be equivalence classes. We don't need exhaustive testing.

Different fault models call for different kinds of test suites:

Wrong logic/wrong expression:
Complete but minimal coverage over small domains
Problem scaling up data structures (like hash table resize, editor buffer gap):
Vary a few properties over large ranges
Unreliable infrastucture, hidden state leaks out:
Long test cases, revisit the same (model) states

top


Exploration

Exploration is the primary technique for analyzing model programs.

Exploration generates a Finite State Machine (FSM) from the model program for ---

Exploration executes the model program in special environment, building the FSM as it goes.

Generated FSM is usually an underapproximation of model program.

Generated FSM can be nondeterministic.

top


Exploration algorithm

Exploration treats model program state as first class.

top


Exploration configuration

Model program defines all scenarios
Test tool configuration defines scenarios for a particular test suite

Make the FSM finite

Control exploration order (when sampling)

top


Exploration with properties and state groupings

State groupings (sampling based on properties)

For exploration or visualization

top


Exploration scenario control

Scenario control - for this we sometimes have to alter model

top


Exploration methodology

Achieve understanding, check properties, scale up, repeat ...

top


Exploration vs. model checking

Complete exploration over small domains is like concrete state model checking
BUT we have no temporal logic formula to check against

Two temporal logic formulas are "baked in"

Exploration with sampling is quite different philosophy:
incomplete, use judgment and heuristics to sample from presumed equivalence classes

top


Test case generation

Offline test case generation: traverse FSM generated by exploration

Tool can store test suite internally for subsequent conformance test
OR tool can write out test suite as C# program

top


Conformance testing

top


Testing nondeterministic systems

top


On-the-fly testing

top


Integration with other test tools

top