developer747
developer747

Reputation: 15928

Gallio unit test startup code

This is going to be an amateur level question. Is there a way to add start up code to a test project that uses MBUnit 3.4.0.0? I tried adding [TestFixture] and [FixtureSetUp] attributes to code that I wanted to run first, but unfortunately that didnt help.

Upvotes: 0

Views: 1073

Answers (1)

MrKay
MrKay

Reputation: 13

The [FixtureSetUp] should be executed once before any test of the tests contained within the [TestFixture], but the two cannot be used interchangeably.

Here's a quick example. Admittedly the class doesn't have to be decorated with the [TestFixture] attribute, but it's good practice.

[TestFixture]
public class SimpelTest
{
    private string value = "1";

    [FixtureSetUp]
    public void FixtureSetUp()
    {
        // Will run once before any test case is executed.
        value = "2";
    }

    [SetUp]
    public void SetUp()
    {
        // Will run before each test
    }

    [Test]
    public void Test()
    {
        // Test code here
        Assert.AreEqual("2", value);
    }

    [TearDown]
    public void TearDown()
    {
        // Will run after the execution of each test
    }

    [FixtureTearDown]
    public void FixtureTearDown()
    {
        // Will run once after every test has been executed
    }
}

Upvotes: 1

Related Questions