locked
Execution order of ClassCleanup when you have mutiple ClassCleanUps RRS feed

  • Question

  • Hi,

    I know the following is the order of execution when we have mutiple ClassCleanups:

    ClassInitialize1

        TestInitialize

        TestCleanup

    ClassInitialize2 

      TestInitialize   

       TestCleanup

    ClassCleanup1

    ClassCleanup2

    Do i have an alternative to run the tests which has following order?:

    ClassInitialize1

        TestInitialize

        TestCleanup

    ClassCleanup1

    ClassInitialize2 

      TestInitialize   

       TestCleanup

    ClassCleanup2

    This is very very important requirement for us to run mutiple ordered tests from visual studio only.

    Any help is highly appreciated.

    Regards

    -Babu

    Thursday, February 23, 2012 6:46 AM

Answers

  • Our functionality was like this:

    ClassA contains some data i.e DataA. This DataA can be accessed only in that class. We register this DataA in registry. This DataA is used during execution of test methods in that class.

    Similarly we have other classes like ClassB, ClassC having their own data DataB, DataC in their respective classes.

    When tests in ClassA are executed, at the end of ClasscCleanup in that class, we use DataA and do some functionality. As we don't goto ClassACleanup immediately after exeucting tests of ClassA, we go to ClassB, when it comes back to ClassACleanup, we will have the data of ClassB in registry, which is not expected.

    We modified the functionality to use data of ClassA, even though it goes to ClassB to execute its test methods and comes back.

    This solved our problem.

    This is not generic, but this serves purpose for our case.

    Regards

    -Babu

    Tuesday, February 28, 2012 9:01 AM

All replies

  • Hi Babu,

    Can you please explain why you want this order of execution to be changed? What is your final goal? What do you want to achieve by allowing this initialize/cleanup methods to execute in this fashion?

    -Tejas.

    Thursday, February 23, 2012 9:57 AM
  • Hi Tejas,

    We want to do some specific cleanup at the end of first ordered test before we move into next ordered test. This we are currently doing in ClassCleanup.

    Regards

    -Babu

    Thursday, February 23, 2012 10:17 AM
  • Hi Babu,

    Thank you for posting in the MSDN forum.

    If we have all the tests in a single class, ClassCleanup will be called only once for all test methods inside a class.

    So if you want to use the “ClassCleanup” in a specific method, just create a test method in a class.

    Best Regards,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us


    Friday, February 24, 2012 6:49 AM
    Moderator
  • I am not sure why the behavior is like this, but it is not consistent always.

    The behavior of class-cleanups is not same as test cleanups which is not convincing.

    We are proceeding with some other workarounds.

    Thanks

    -Babu

    Monday, February 27, 2012 5:25 AM
  • Hi Babu,

    Glad to receive your reply.

    Do you mean that you will use other workarounds to resolve this issue? If you have good workarounds, you can share your solutions & experience here. It will be very beneficial for other community members who have similar questions.

    But about this issue, the ClassCleanup will be called only once for all test methods inside a class. So if you want to use the “ClassCleanup” for every method, we can create a test method in a class. This is a workaround.

    Best Regards,



    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, February 28, 2012 5:06 AM
    Moderator
  • Our functionality was like this:

    ClassA contains some data i.e DataA. This DataA can be accessed only in that class. We register this DataA in registry. This DataA is used during execution of test methods in that class.

    Similarly we have other classes like ClassB, ClassC having their own data DataB, DataC in their respective classes.

    When tests in ClassA are executed, at the end of ClasscCleanup in that class, we use DataA and do some functionality. As we don't goto ClassACleanup immediately after exeucting tests of ClassA, we go to ClassB, when it comes back to ClassACleanup, we will have the data of ClassB in registry, which is not expected.

    We modified the functionality to use data of ClassA, even though it goes to ClassB to execute its test methods and comes back.

    This solved our problem.

    This is not generic, but this serves purpose for our case.

    Regards

    -Babu

    Tuesday, February 28, 2012 9:01 AM
  • Hi Babu,

    Glad to see this issue has been resolved and thank you for sharing your solutions & experience here. You are so friendly. I mark your reply as the answer.

    Have a nice day,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, February 28, 2012 9:11 AM
    Moderator
  • Thank you!
    Tuesday, March 6, 2012 9:18 AM