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

后端 未结 1 385
有刺的猬
有刺的猬 2021-01-03 21:07

I\'ve used NUnit with VS2008, and now am adapting to MSTest on VS2010. I used to be able to create an object in TestSetup() and dispose of it in TestCleanup(), and have the

相关标签:
1条回答
  • 2021-01-03 21:45

    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();
        }
    }
    
    0 讨论(0)
提交回复
热议问题