Need simple example of FitNesse SetUpFixture under .NET

2k views Asked by At

I've been trying to implement FitNesse tests for our C# application. I'm using the latest FitNesse jar and the fitSharp .NET 2.2 4.0 libraries.

I have been able to successfully use scenarios using Slim. However, in the interests of making tests that are more legible to a non-technical audience, I'm interested in implementing DoFixtures, and I surmise I'll need SetUpFixtures to create common data conditions for tests.

I can't seem to get the data I set up into the DoFixture instance, though. I've looked at several resources (Gojko's book chief among them), but none seem to talk about this concept in isolation. Attaching Visual Studio as a debugger to test runs hasn't yielded any insight. I could really use a trivial example to analyze and build upon.

Would someone be willing to share an example that includes just:

  • A SetUpFixture class that sets up some data
  • A DoFixture class that uses the data from the SetUpFixture
  • Wiki syntax to invoke them?
2

There are 2 answers

2
GSerjo On BEST ANSWER

Looks like SetUp was not called. Use Debugger.Launch() for debug

Update:

!|BirdCall|
|birdName|noise|
|duck|quack|

public class SkylarkBunting : fitlibrary.DoFixture
{
    public BirdCall BirdCall;

    public SkylarkBunting(BirdCall birdCall)
    {
        BirdCall = birdCall;
    }

    public string GetCall()
    {
        return BirdCall.Noise;
    }

    public string GetName()
    {
        return BirdCall.BirdName;
    }
}
1
neontapir On

I've got a partial answer.

Using these classes:

public class BirdCall : fitlibrary.SetUpFixture
{
    public void BirdNameNoise(string birdName, string noise)
    {
        BirdName = birdName;
        Noise = noise;
    }

    public string BirdName; 
    public string Noise;

    public override string ToString()
    {
        return string.Format("BirdCall: {0}, {1}", BirdName, Noise);
    }
}

public class SkylarkBunting : fitlibrary.DoFixture
{
    public BirdCall BirdCall;
    public string Call;

    public Fixture CryOut()
    {
        BirdCall = new BirdCall();
        Call = BirdCall.Noise;
        return BirdCall;
    }

    public string GetCall()
    {
        return BirdCall.Noise;
    }

    public string GetName()
    {
        return BirdCall.BirdName;
    }
}

and this Wiki markup:

!define TEST_RUNNER {C:\temp\fitsharp\Runner.exe}
!define COMMAND_PATTERN {%m -r fitnesse.fitserver.FitServer,c:\temp\fitsharp\fit.dll %p}
!path C:\temp\FitNesseIntegration\bin\Debug\FitnesseIntegration.dll

!|import|
|FitnesseIntegration|

!|FitNesseIntegration.Skylark.SkylarkBunting|

!3 Testing getting data from a setup fixture into a do fixture

!|cry out|
|bird name|noise|
|Tweetie|Caw!|

|check|call||
|check|get call||
|check|get name||
|check|bird call||

I get:

|check|call|null|
|check|get call|Caw!|
|check|get name|Tweetie|
|check|bird call|BirdCall: Tweetie, Caw!|

This is good, I have variables in the DoFixture that were populated by executing the SetUpFixture with values injected by FitNesse via the page.

I'd still like to know why Call returns null, though.