2 Creating Decision Table Fixtures - essenius/FitNesseFitSharpFibonacciDemo GitHub Wiki
This page covers the basics of creating Decision Table fixtures. It starts with examining the decision table fixture that was created for the FitNesse demo.
Examining the Fibonacci Demo
Have a look at the function that we are creating a fixture for: Functions.cs. This is a quite simple function that calculates the nth a Fibonacci number based on an input n. To make it a bit more interesting we also throw an exception if the input is negative, and we can also get an overflow. We use this function to show how to create a fixture for it.
That fixture can be seen in FibonacciFixture.cs. This is one of the simplest fixtures you can create, and it defines two members:
- A property called
InputValue
. This has a setter, so it can be used by Decision Tables to provide a column calledInput Value
as input. Since it also has a getter, it could also be used for returning the value should that be required. - A function called
Fibonacci
, taking no parameters and returning an object. This function just calls theFunctions.Fibonacci
function in the system under test with the value ofInputValue
as parameter. We use an object so we can return both the integer value that theFunctions.Fibonacci
function returns, as well as the name of the exception if one is raised.
Previously we disussed the FitSharp configuration config.xml.
In this case, the file tells FitSharp that we are going to use ExtendedMathFixtures.dll
, and that we want to use the namespace called ExtendedMathFixtures
in it. This sets the context for the pages in FitNesse.
Let's have a look at the FitNesse test page:
|Fibonacci Fixture |
|Input Value |Fibonacci? |#comment |
|0 |0 |by definition |
|1 |1 |by definition |
...
The name of the table refers to the fixture class name, in this case that is Fibonacci Fixture
. FitNesse will convert these names with spaces to PascalCase under the hood, so this asks FitSharp to setup an object of type FibonacciFixture
. Since FitSharp knows we are using the ExtendedMathFixtures
namespace, it will look in that namespace for the class, which it then instantiates.
Next, FitNesse analyzes the headers and determines the following:
- it needs a setter for
InputValue
- it needs a getter for
Fibonacci
(question marks at the end of a column name denote columns to be checked) - it can ignore the third column as it is a comment column (starts with
#
)
Then FitNesse starts the testing process.
- It asks FitSharp to set
InputValue
to0
. FitSharp finds a setter with that name and calls it with parameter0
. - It asks FitSharp to call the
Fibonacci
method and return the result. FitSharp finds that method in the fixture, executes it and hands the result0
back to FitNesse. - This is what was expected, so it passes the test (turns it green).
- It moves on to the next line. where it repeats the process until there are no more lines in the table.
More advanced features
You are not restricted to just one input or output value to be checked. If you are using more than one, then FitNesse will first set all the setters specified in the table, and only then call the getters, independent of how you order the columns. To provide more ways of handling these tables efficiently, there are a few optional methods that you can define in Decision Table fixtures:
void BeginTable()
- Setup and initialization, called once, before processing the rowsvoid EndTable()
- Cleanup and closedown, called once, after processing the last rowvoid Reset()
- Called once for each row, before any columns are processed. This can e.g. be used to cleanup row data.void Execute()
- Called once for each row, after all the set functions have been called, and before the first output function is called. This can e.g. be useful if there is one function to be executed which delivers multiple results which need to be individually checked.