ClassInitialize and TestMethod execution priorities RRS feed

  • Question

  • I'm using Visual Studio Test Automation to write few unit test cases to test my application. Basically, my application is editor kind of component in which I can add some UI elements and do some operation. In unit test, I want to add few elements into the editor and check the properties of those elements once it gets loaded. In order to do this In "ClassInitialize", I create new wpf window and load my editor as content to it. While running the test, I get the Window loaded event first followed  by my editor's loaded event. This is as expected and fine.

    In the test method, I add few elements into my editor and try to check few properties of the inserted elements. The properties which I want to test will get initialized only after the these elements get loaded. What I have observed is, the load event for newly added elements doesn't raise until the exection of Test method finishes. My understanding is once the elements got added and it's visible, loaded event for the elements should be raised. But in my case, loaded event for elements get raised only after the TestMethod execution finishes. Because of this, my test case fails to verify the results.

    One observation here is, if I add new elements to my editor in editor's loaded eventhandler then loaded event for newly added elements raised immediately.

    Can someone explain the above behavior? Is this a thread synchronization issue? If I need to raise the loaded event for the elements immediately after I add them how I should write my TestMethod and ClassInitialize? 

    Hope I have been able to explain my scenario above. Pls revert in case more clarification needed.

    Krunal C
    Tuesday, February 1, 2011 3:41 AM


All replies

  • Almost 24 hrs elapsed still no response. Is it like my question is too difficult to answer or my question is difficult to understand? Any pointers/help in this regard appreciated.

    Krunal C
    Wednesday, February 2, 2011 12:48 AM
  • Hi Krunal,

    Sorry for the late reply.

    Are you using Coded UI Test?

    Ruiz Yi [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, February 7, 2011 4:12 AM
  • Hi Ruiz,

    Thanks for your reply. As such I had already given up hope of getting any reply on this.

    I'm not using Coded UI test. Mine is simple Test project.

    Hope I'm clear with my explaination above. In case, if you have any doubts pls revert.


    Krunal C
    Monday, February 7, 2011 4:36 AM
  • Hi KrunalC,

    TestInitialize code is expected to run for every test method, ClassInitialize code will be executed once for all test methods inside a single Test class. Refer the following for more info:


    But about the question, I think Unit test is to test the class's methods. But you have use the wpf window and others, maybe I know little, about the question I can't understand it very clearly. But I think we can solved the question together!

    Hope it can help you!



    When you help others, it's help yourself!
    Tuesday, March 1, 2011 1:32 PM