Using MS Test ClassInitialize() and TestInitialize() in VS2010 as opposed to NUnit

Here is a simple example using TestInitialize and TestCleanup.

[TestClass]
public class UnitTest1
{
    private NorthwindEntities context;

    [TestInitialize]
    public void TestInitialize()
    {
        this.context = new NorthwindEntities();
    }

    [TestMethod]
    public void TestMethod1()
    {
        Assert.AreEqual(92, this.context.Customers.Count());
    }

    [TestCleanup]
    public void TestCleanup()
    {
        this.context.Dispose();
    }
}

Leave a Comment

tech