locked
Specify different initialze method for different unit test RRS feed

  • Question

  • Hi,

    In visual studio, we can use TestInitialize attributes to make a method run before each unit tests. Now I wonder if there is a attribute to make unit test specify their initialize method. For example, I have 2 unit test: UnitTest1, UnitTest2 and 2 initialize method: Initialize1 and Initialize2. Now I want UnitTest1 use Initalize1 and UnitTest2 use Initialize2 for initialization, is this possible?

    Wednesday, February 16, 2011 3:24 AM

All replies

  • Hi,

    I dont think there is a built in way to do that.

    However to achieve your goal, you can create a common function and all it in your tests. Other way would be to add some attributes to the tests and then use reflection in the TestInitialize method to do specific actions depending upon the value of the attribute.

    The disadvantage these two options would bring is that you would have to add something to every test method.

    Thanks,

    Anuj

    Wednesday, February 16, 2011 11:07 PM