The Fixture Gallery is also available as a PDF document and a live FitNesse wiki. See http://gojko.net/fitnesse/fixturegallery for more information.
Previous page: DoFixture Next page: ArrayFixture Parent page: FitLibrary Fixtures

SequenceFixture

SequenceFixture is very similar to DoFixture and has almost the same features -- in fact the only difference between those two is the naming convention for methods. Instead of using odd cells to construct a method name, SequenceFixture takes the first cell in each row as the method name, and all other cells as arguments (if there are no keywords to modify the row functionality). All DoFixture keywords are supported in SequenceFixture too, as well as the flow mode (see Flow Mode ) and domain object wrapping (see System under test).

Table Format

The table format is the same as for DoFixture (see DoFixture), with the difference in method naming.

!|SequenceFixtureTest|
|fill|10|x|
|check|char at|4|x|
|set list|A,B,C,D|
|check|char at|2|C|

Fixture class

The fixture class should extend fitlibrary.SequenceFixture. Declare public methods for all verifications and actions by taking the first cells as the method name, and using all other cells as arguments.

Java Source Code

package info.fitnesse.fixturegallery;
import java.util.Arrays;
import fitlibrary.SequenceFixture;

public class SequenceFixtureTest extends SequenceFixture{
	public String letters;
	public void fill(int count,char c){
		char[] arr=new char[count];
		Arrays.fill(arr,c);
		letters=new String(arr);
	}
	public void setList(char[] array){
		letters=new String(array);
	}
	public char charAt(int position){
		return letters.charAt(position);
	}	
}

.NET Source Code

using System;

namespace info.fitnesse.fixturegallery
{
    public class SequenceFixtureTest : fitlibrary.SequenceFixture
    {
        private String contents;
        public void Fill(int howmany, String what)
        {
            contents = "";
            for (int i = 0; i < howmany; i++)
            {
                contents = contents + what;
            }
        }
        public void SetList(String[] strings)
        {
            contents = "";
            foreach (String s in strings)
            {
                contents = contents + s;
            }
        }
        public char CharAt(int index)
        {
            return contents[index];
        }
    }
}

Python Source Code

from fitLib.SequenceFixture import SequenceFixture
from info.fitnesse.fixturegallery.typeadapter import buildListTypeAdapterFor

class SequenceFixtureTest(SequenceFixture):
    _typeDict = {}

    def __init__(self):
        self.letters = ""

    _typeDict["fill.types"] = [ None, "Integer", "Char" ]
    def fill(self, count, c):
        self.letters = c * count    #< FILL: Repeact char count times.

    # JAVA: public void setList(char[] array){
    ARRAY_OF_CHAR_TYPE_ADAPTER = buildListTypeAdapterFor("Char")
    _typeDict["setList.types"] = [ None, ARRAY_OF_CHAR_TYPE_ADAPTER ]
    def setList(self, array):
        self.letters = "".join(array)   #< Concatenate array of chars to string.

    _typeDict["charAt.types"] = [ "Char", "Integer" ]
    def charAt(self, position):
        return self.letters[position]

Smalltalk Source Code

'From VisualWorks®, 7.6 of March 3, 2008 on June 27, 2008 at 3:36:43 pm'!


Info.Fitnesse.Fixturegallery defineClass: #SequenceFixtureTest
	superclass: #{Fitlibrary.SequenceFixture}
	indexedType: #none
	private: false
	instanceVariableNames: 'letters '
	classInstanceVariableNames: ''
	imports: ''
	category: ''!

!Info.Fitnesse.Fixturegallery.SequenceFixtureTest methodsFor: 'accessing'!

charAt: anInteger
	^letters at: anInteger + 1! !

!Info.Fitnesse.Fixturegallery.SequenceFixtureTest methodsFor: 'actions'!

fill: anInteger _: aCharacter
	letters := String new: anInteger withAll: aCharacter!

setList: anArray
	letters := String withAll: anArray! !

!Info.Fitnesse.Fixturegallery.SequenceFixtureTest methodsFor: 'type access'!

signatureFor: aSymbol
	aSymbol == #fill:_:
		ifTrue: [^MethodSignature with: Integer with: Character].
	aSymbol == #charAt:
		ifTrue: [^MethodSignature with: Integer returning: Character].
	aSymbol == #setList:
		ifTrue: [^MethodSignature with: (Array with: Character)]! !

Usage

SequenceFixture has all the flexibility and power of DoFixture, but without the silly method names. It is most useful for more technical workflow tests, especially to directly map FitNesse tables to existing business domain services (see System under test).

In Smalltalk, SequenceFixture method names are the silly ones. Use _: for any arguments after the first. DoFixture typically produces much more readable Smalltalk method names.

Previous page: DoFixture Next page: ArrayFixture Parent page: FitLibrary Fixtures


Personal Tools