locked
Running mutiple test in Mstest fails the test as method invoked through dispacher not invoked in class under test RRS feed

  • Question

  • Running mutiple test in Mstest fails the test as method invoked through dispacher not invoked in class under test

    here is the code snippet

    class cut

    {

    private void smmethod()

    {

    Dispacher.currentdispacher..BeginInvoke(System.Windows.Threading.DispatcherPriority.Input, new Action(
                       delegate()
                       {

    //some code

    }

    }

    in the test

     private static readonly DispatcherOperationCallback ExitFrameCallback = ExitFrame;

            public void testmethod()
            {

             smmethod();

              var nestedFrame = new DispatcherFrame();

                // Dispatch a callback to the current message queue, when getting called,
                // this callback will end the nested message loop.
                // note that the priority of this callback should be lower than the that of UI event messages.
                DispatcherOperation exitOperation = Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Normal, ExitFrameCallback, nestedFrame);

                // pump the nested message loop, the nested message loop will immediately
                // process the messages left inside the message queue.
                Dispatcher.PushFrame(nestedFrame);

                // If the "exitFrame" callback doesn't get finished, Abort it.
                if (exitOperation.Status != DispatcherOperationStatus.Completed)
                {
                    exitOperation.Abort();
                }

             }

    public static object ExitFrame(object state)
            {

              
                var frame = state as DispatcherFrame;
                if (frame == null)
                {
                    throw new ArgumentOutOfRangeException("state parameter is of the wrong type.");
                }

                // Exit the nested message loop.
                frame.Continue = false;
                return null;
            }

    it runs in isolation but as it is runs parellel to other having similar code its fails

    Any help greatly appreciated

    Regards

     

    Tuesday, August 14, 2012 10:12 AM

All replies

  • Hi Vivek,

    Thank you for posting in the MSDN forum.

    Do you mean that when you run this test in isolation it works fine and can be invoked in class under test, but running it with other tests having similar code in parallel in MSTest it fails? If so, you can try to run this test with other simple tests together in MSTest to check if it can succeed. Also you can select this test and other tests having similar code to run in Test View windows to check if it runs successfully. There may be some issues using MSTest as it does not completely isolate each test.

    Here is a help link about executing unit tests in parallel:

    http://blogs.msdn.com/b/vstsqualitytools/archive/2009/12/01/executing-unit-tests-in-parallel-on-a-multi-cpu-core-machine.aspx

    Thanks,


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

    Wednesday, August 15, 2012 4:07 AM
  • Hi Amanda,

              Thanks for your reply.But my issue is that when I run each test one by one the code inside dispatcher gets executed but when I run all the test cases in my test class, it fails to execute the code inside dispatcher for all the testcases except the first one.Some said its because Ms test launches each test in different thread.I am stuck.Please help

    Regards

    Thursday, August 16, 2012 5:04 AM
  • Hi Vivek,

    Based on your code above, I create a test project ,two similar test methods having dispatcher, and the test cases can pass successfully both in Visual Studio and MSTest. In order to repro your issue better, can you create a simple project including your source code and the test class code and send it to this mail box v-amanz@microsoft.com?

    Thank you for your understanding and support.

    Best regards,


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

    • Marked as answer by Amanda Zhu Thursday, August 30, 2012 4:10 AM
    • Unmarked as answer by Amanda Zhu Thursday, August 30, 2012 4:12 AM
    Friday, August 17, 2012 7:15 AM