简体   繁体   中英

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

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

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

Thanks

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM