locked
ClassCleanup executed at the end of each test case RRS feed

  • Question

  • Hi,

    I have used the Class Initialize and Class Cleanup in my Codedui script and Class Initialize is worked as expected i.e.Class Initialize is executed at once before my test method but ClassCleanup is executed at the end of each test case which is actually an unexpected behavior and it should be executed only once i.e.,it should be executed at the end of executing all test cases.

        
            static private UIMap uimap = new UIMap();

            [ClassInitialize]
            static public void ClassInit(TestContext context)
            {
                Playback.Initialize();
                try
                {
                    uimap.openProlaw();

                }
                finally
                {
                    Playback.Cleanup();
                }

            }

            [ClassCleanup]
            static public void ClassCleanup()
            {
                uimap.closeProLaw();
               
            }

    Please guide me if my coding is wrong in this case.

    Thanks in Advance

    Regards

    Selvaraj C



    Selvaraj

    Thursday, November 22, 2012 9:40 AM

Answers

  • I have tried ClassInitialize and ClassCleanup in a test project and ClassCleanup is only called once, not multiple times as you describe. Is it possible that some other piece of your solution is calling the ClassCleanup code?

    For code that is to be executed only once before or after all test cases look at the AssemblyInitialise and AssemblyCleanup attributes.

    Looking at the code you write I wonder why you call Playback.Initialize and Playback.Cleanup? I have not used them. If you know you need to call them, then fine. If you are just starting with Coded UI then I suggest creating a very simple test (eg just run a standard Windows program and click its Exit button) using the Coded UI test recorder. Then studying the code that is generated to see how little needs to be hand coded.

    Regards

    Adrian

    Thursday, November 22, 2012 12:57 PM
  • You might run you test under the debugger and set a breakpoint at the start of the ClassCleanup code. Each time it breaks in that mehod you can examine the call stack window to see where it was called from.

    ClassInitialize and ClassCleanup are not generated by the Coded UI test recorder, they are added by the test developer.

    Regards

    Adrian

    Thursday, November 22, 2012 5:04 PM

All replies

  • I have tried ClassInitialize and ClassCleanup in a test project and ClassCleanup is only called once, not multiple times as you describe. Is it possible that some other piece of your solution is calling the ClassCleanup code?

    For code that is to be executed only once before or after all test cases look at the AssemblyInitialise and AssemblyCleanup attributes.

    Looking at the code you write I wonder why you call Playback.Initialize and Playback.Cleanup? I have not used them. If you know you need to call them, then fine. If you are just starting with Coded UI then I suggest creating a very simple test (eg just run a standard Windows program and click its Exit button) using the Coded UI test recorder. Then studying the code that is generated to see how little needs to be hand coded.

    Regards

    Adrian

    Thursday, November 22, 2012 12:57 PM
  • Hi,

    I am not sure whether my solution is calling ClassCleaup method and can you please tell me how we find that the solution is calling ClassCleanup somewhere other than end of the class.

    I tried to do recording a simple Window program and click its exists but i am not able to find ClassInitialize and ClassCleanup method in Codedui Script.

    Thanks

    Selvaraj C


    Selvaraj

    Thursday, November 22, 2012 4:23 PM
  • You might run you test under the debugger and set a breakpoint at the start of the ClassCleanup code. Each time it breaks in that mehod you can examine the call stack window to see where it was called from.

    ClassInitialize and ClassCleanup are not generated by the Coded UI test recorder, they are added by the test developer.

    Regards

    Adrian

    Thursday, November 22, 2012 5:04 PM
  • Hello Selvaraj,

    Have you resolved this issue? Could you get useful information from Adrian's reply?

    If you have resolved it, please mark the helpful reply as answer.

    If not, please let us know the latest news about this issue and the result of our suggestion.

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us

    Monday, November 26, 2012 12:51 AM
    Moderator