Friday, August 19, 2011

setup and teardown for testing

namespace MyApp.Data.Tests

{

   [TestClass]

   public class MyTest

   {

      public Foo foo;

      

      [TestInitialize]

      public void TestSetup()

      {

         foo = new Foo();

         foo.Name = "Bar";

         FooRepository.Save(foo);

      }

      

      [TestMethod]

      public void Test()

      {

         Assert.AreEqual(foo.Name,"Bar");

      }

      

      [TestCleanup]

      public void TestTeardown()

      {

         FooRepository.Delete(foo);

      }

   }

}

No comments:

Post a Comment