How to maintain state in Fitnesse tests with c# Fitnesse+Slim

470 Views Asked by At

How do I specify data to be used in each of my test cases?

i.e. I wish to use one table to setup some data and then run a bunch of tests against that data.

Thanks

1

There are 1 best solutions below

0
On

I've been looking at Gojko and their suggestion is to create a singleton that you invoke at the beginning of your test page. Here's an example of the FitNesse edit:

!|import         |
|Demo1.Containers|
|Demo1.Fixtures  |

!|SUT         |
|Get Practice?|
|$practice=   |

And my C# code (SUT -> System Under Test is a basic Singleton:

public class SUT
{
    private static Practice _practice = null;
    public static Practice getPractice()
    {
        if (_practice == null)
        {
            _practice = new Practice();
        }
        return _practice;
    }
}

My other classes that I'm testing use that singleton to get their data.

    public class AddDoctorToPractice
    {
        private Practice practice = SUT.getPractice();
        ...

I hope that helps.