channingwalton / AllThing

A testing framework

Introduction

The goal of AllThing is to allow a declarative style of automated software tests that resemble specifications. It is primarily aimed at functional / system level testing rather than unit testing.

There are two basic premises for AllThing. The first is that we often need a system to be in a given state in order that we may execute some actions and verify that the results are as expected. The second is that it is precisely the resulting state of one or more tests that provides the given state of another.

Rather than writing tests that are required to run in a certain order, something that is generally regarded as a bad thing, AllThing searches for a suitable run order.

Example

The following two specifications demonstrate the essence of The AllThing.

The first specification creates a stack, makes sure that everything is as expected and makes the stack available as an 'artifact':

package allthing.stack;

import java.util.Stack;

import allthing.annotation.Action;
import allthing.annotation.Artifact;
import allthing.annotation.Result;
import allthing.annotation.Specification;

@Specification
public class StackCreationSpecification {
    private Stack<Object> stack;

    @Action
    public void createAStack() {
        stack = new Stack<Object>();
    }
        
    @Result
    public void theStackIsEmpty() {
        assert stack.isEmpty();
    }
    
    @Result
    public void theSizeOfTheStackIsZero() {
        assert stack.size() == 0;
    }
    
    @Artifact
    public Stack<Object> anEmptyStack() {
        return stack;
    }
}

The second specification requires an empty stack, but does not care where it comes from. It then pushes an item onto the stack and makes sure that everything is as expected:

package allthing.stack;

import java.util.Stack;

import allthing.annotation.Action;
import allthing.annotation.Given;
import allthing.annotation.Result;
import allthing.annotation.Specification;
import allthing.annotation.Given.Effect;

@Specification
public class StackPushOneSpecification {
    private Stack<Object> stack;
    private Object object = new Object();
    
    @Given(Effect.UPDATE)
    public boolean anEmptyStack(Stack<Object> stack) {
        this.stack = stack;
        return stack.isEmpty();
    }
    
    @Action
    public void pushAnObjectOntoTheStack() {
        stack.push(object);
    }
    
    @Result
    public void peekReturnsThePushedObject() {
        assert stack.peek() == object;
    }
    
    @Result
    public void theStackContainsOneElement() {
        assert stack.size() == 1;
    }
    
    @Result
    public void theStackIsNotEmpty() {
        assert !stack.isEmpty();
    }
}

The AllThing will determine that it can verify these two specifications by running them in the order presented here. The 'artifact' from the first specification will be passed to the second as its 'given'.

Download

To find out more, please the distribution from http://www.stateofflow.com/projects/82/allthing-specification-framework and look at the contained documentation.


This revision is from 2009-03-28 22:10