locked
Add property to TestContext from ClassInitialize() RRS feed

  • Question

  • I am writing unit test cases for my project where-in I wish to add a couple of properties to the TestContext. These values should persists till all my tests run. I know TestContext is non-static and so we cannot add properties to it from ClassInitialize. Is there any other way we can do that or else I will have to take static variables and assign those from ClassInit.
    Friday, July 17, 2009 5:38 AM

Answers

  • Hello,

    It is by design that TestContext is lost at each test. They are different for each test method, with no sharing between test methods.

    As a result of the operation mode, using a static variable would be right. You also could make the TestContext static to keep the value among the tests.

    You could refer to this article for the operation mode of unit test.
    http://blogs.msdn.com/nnaderi/archive/2007/02/17/explaining-execution-order.aspx

    If there are any questions, please feel free to let me know.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Send us any feedback you have about the help from MSFT at fbmsdn@microsoft.com.
    Wednesday, July 22, 2009 8:34 AM
    Moderator