Why does TestInitialize get fired for every test in my Visual Studio unit tests?

后端 未结 4 1657
礼貌的吻别
礼貌的吻别 2020-12-02 06:50

I\'m using Visual Studio 2010 Beta 2. I\'ve got a single [TestClass], which has a [TestInitialize], [TestCleanup] and a few [Tes

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 07:16

    Methods that are marked with [TestInitialize()] attribute are used to prepare aspects of the environment in which your unit test will run. The purpose of this is to establish a known state for running your unit test. You may use the [TestInitialize()] method to copy, alter, or create certain data files that your test will use.

    Create methods that are marked with [TestCleanUp{}] attribute to return the environment to a known state after a test has run. This might mean the deletion of files in folders or the return of a database to a known state. An example of this is to reset an inventory database to an initial state after testing a method that is used in an order-entry application.

    For more information please refer : http://msdn.microsoft.com/en-us/library/ms182517%28v=vs.100%29.aspx

提交回复
热议问题