Writing unti test case for code coverage of method having events.

Answered Writing unti test case for code coverage of method having events.

  • quinta-feira, 16 de agosto de 2012 12:08
     
     

    private void GridViewColumnHeaderClickedHandler(object sender, RoutedEventArgs e)

    {

    GridViewColumnHeader headerClicked = e.OriginalSource as GridViewColumnHeader;

    ListSortDirection direction;

    if (headerClicked != null)

    {

    if (headerClicked.Role != GridViewColumnHeaderRole.Padding)

    {
    }
    }
    }

    I want to write a unit test case to cover this code.

    • Movido Annabella Luo quarta-feira, 22 de agosto de 2012 10:03 (From:Windows Presentation Foundation (WPF))
    •  

Todas as Respostas

  • segunda-feira, 20 de agosto de 2012 07:46
     
     

    Hi Devloper_1234,

    Thank you for your post.

    According to your description, I understand your issue is about Unit test, so I'm moving your thread to Unit Testing Forum so that you can get a better help.

    Thank you for your understanding and support.

    Have a nice day.


    Annabella Luo[MSFT]
    MSDN Community Support | Feedback to us

  • segunda-feira, 20 de agosto de 2012 08:45
    Moderador
     
     Respondido

    Hi Devloper_1234,

    Thank you for posting in the MSDN forum.

    Here is a help link about how to create and run a unit test:

    http://msdn.microsoft.com/en-us/library/ms182532.aspx

    For creating a unit test for a private method, please see here:

    http://msdn.microsoft.com/en-us/library/bb385974(v=vs.90).aspx

    You wrote “cover this code”, I can’t understand clearly.

    If you want to collect code coverage in Visual Studio 2010, the link below may help you:

    http://msdn.microsoft.com/en-us/library/dd504821(v=vs.100)

    The link below about analyzing code coverage results may help you:

    http://msdn.microsoft.com/en-us/library/dd286597(v=vs.100)

    If you are using Visual Studio2012 to view code coverage, please see it:

    http://msdn.microsoft.com/en-us/library/dd537628.aspx

    Note that you can only use code coverage when you run an automated test, and only from the computer that is running the test. Remote collection is not supported.

    I hope this will be helpful to you.

    Best regards,


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

  • quarta-feira, 22 de agosto de 2012 09:17
     
     

    Thanks for your reply, I am looking for a test case to cover events.In above method

    private void GridViewColumnHeaderClickedHandler(object sender, RoutedEventArgs e)

    here if i am sending accessor.GridViewColumnHeaderClickedHandler(null,null) than code coverage will not happen. The problem is how to send parameters for events like RoutedEventArgs.

  • quarta-feira, 22 de agosto de 2012 11:04
    Moderador
     
     

    Hi Devloper_1234,

    You are right that the code coverage will not happen when you set two parameters to null in GridViewColumnHeaderClickedHandlerTest() method. You need to initialize instances for Object and RoutedEventArgs class according to the actual situation. Then you can send them into target.GridViewColumnHeaderClickedHandler(sender, e) in unit test method.

    I hope this will be helpful to you.

    Best regards,



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