7 Custom Test Capabilities With Table Tables - essenius/FitNesseFitSharpGameManagementDemo GitHub Wiki

We have now seen Script Tables, Query Tables, Decision Tables, and Scenario Tables. The Table table is the most flexible one of all. It works together with a fixture that accepts an arbitrary table and returns a table of results. Let’s show a simple example. Under GameManagementSuite, we create a new page OverviewPage with content:

| table:overview |

Save it, and make it a test page (Tools>Properties, Page type Test, Save Properties). This table definition expects a fixture with the name Overview. Such a fixture needs to implement a method DoTable that takes a list of lists of strings (rows of columns of text) and returns a similar table.

Let’s create that fixture. In the GameManagementFixtures project, create a new class Overview:

using System.Collections.Generic;

namespace GameManagementFixtures
{
    using TableList = List<List<string>>;

    public class Overview
    {
        Public static TableList DoTable(TableList table) => new TableList
        {
            new List<string>{ "report:Number of players", 
                              "pass:" + StaticGame.Players.Count }
        };
    }
}

The fixture simply reports back how many players there are (and marks it as passed), but it can become as complex as you want to make it. The only requirement is that the table returned is at least the size of the table that went in.

Table Table

Other things that you can pass back in table cells:

Cell value Behavior on original content
pass Marked passing (green)
pass:<message> Replaced with and marked passing
fail Marked failing (red)
fail:<message> Replaced with and marked failing
ignore Marked ignored
ignore:<message> Replaced with and marked ignored
report:<message> Replaced with without marking
<empty string> or no change Unchanged
error:<message> Marked as exception (yellow) with message
<anything else> Replaced with and marked failing

The Table Table documentation on the FitNesse wiki contains a demo that checks the validity of a scoring table for bowling. This uses Java based fixtures, but you could translate that quite easily to C#.

The flexibility of Table Tables comes at the cost of requiring more work from the fixture code. Most fixtures just return the actual values and let FitNesse take care of the pass/fail evaluation. That is not the case for a table table. Its fixture must implement its own test evaluation algorithm, and it will return the pass/fail result for each test. FitNesse will only register and display the results. This means that implementing such a fixture is typically more complex, requires more effort and has more chance of defects than implementing another fixture type. Therefore, you should carefully consider whether you really need a table table, or whether another type of test table would be more suitable.

We have now covered the main test tables that FitNesse has available and how you can create your own fixtures for them. There are a couple of features left to enable fixture function reuse and make the tests a bit cleaner.

⚠️ **GitHub.com Fallback** ⚠️