locked
15. What are the differences between method marked with [ClassInitialize()], [TestInitialize()], [ClassCleanup()] and [TestCleanup()] in unit test?

    Question

  • 15.  What are the differences between method marked with [ClassInitialize()], [TestInitialize()], [ClassCleanup()] and [TestCleanup()] in unit test?

    Back to FAQ Home

    Wednesday, May 26, 2010 3:11 AM

Answers

  • ·           Use a method marked with [ClassInitialize()] to run code before running the first test in the class.

    ·           Use a method marked with [TestInitialize()] to run code before running each test, usually it is used to prepare aspects of the environment in which your unit test will run and to establish a known state for running your unit test.

    ·           Use a method marked with [ClassCleanup()] to run code after all tests in a class have run.

    ·           Use a method marked with [TestCleanup()] to run code after each test has run, usually it is used to return the environment to a known state after a test has run; this might mean deleting files in folders, or returning a database to a known state.

     

    • Marked as answer by MSDN FAQ Wednesday, May 26, 2010 3:12 AM
    Wednesday, May 26, 2010 3:12 AM