locked
Not Getting Unit Test Code Coverage.. RRS feed

  • Question

  • Hi,

    I have written a business components assembly  in c# which has contains around 30 methods.  These business components were exposed as WCF services and hosted in IIS.   By using svcutil i have created the proxy. 

    I have created a unit test project  and added the proxy to this project and performing unit testing over proxy.  In the code coverage (.testrunconfig), i have added the assbemly reference by pointing to the inetpub\wwwroot\<webapplication>\bin\businesscomponents.dll... directory.   The test is executing successfully and i also getting the code coverage results, where as when i see details, it says my code is not 100% covered.  It strange!!! . I tried to debug the test, it working perfectly and covering the code where ever required.

    Could you please guide me, what i am doing here? 

    which is the best way to conduct unit test for wcf?   

     



     

    Friday, October 10, 2008 3:02 PM

Answers

  •   

    Code coverage works by checking IL instructions. If an IL instruction is not executed, Visual Studio will report that it's not uncovered. When we view code coverage data, we might want to switch to the source code. There maybe cases that not every IL instruction can be mapped back to source code. It could also be that one C# statement is compiled into multiple IL instructions, part of those instructions are executed while others are not. In both scenarios, you may noticed that every line of source code are covered, while the Visual Studio reports that there are uncovered code.


    Please mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Bill.Wang Thursday, October 16, 2008 6:43 AM
    Tuesday, October 14, 2008 5:39 AM
  • We have a document about testing web service. It should apply to web services implemented by WCF. And if you have plan to load test WCF web services, try WCF Load Test. It will make the work very easy.


    Please mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Bill.Wang Thursday, October 16, 2008 6:43 AM
    Wednesday, October 15, 2008 7:50 AM

All replies

  • Hello,

    Can you see the parts that your unit test didn't cover?
    Sunday, October 12, 2008 7:44 PM
  • Yes, when i double click (after selecting the required componenets) of my code coverage results window , i am able to see the code parts of my unit test didn't cover.  It says it didn't covered any thing.  Actually, it covers and does the required processing and the test case got pass.  I manually verified this by crossing the record in the database and everythings looks perfect to me!!.

    If i include the wcf host project in the unit test solution, and use the cassini development web server to host the wcf (rather than IIS), i am able to get the code coverage results.  where as if i use IIS, i am not abe to get this. 

    My problem of using cassini development server is, i have to integrated my unit test case in the nighlity VSTS build in order to generate the required reports, which i prefer IIS rather the personal development server.

    Any thoughts/ideas to over come this?



    Monday, October 13, 2008 7:55 AM
  •   

    Code coverage works by checking IL instructions. If an IL instruction is not executed, Visual Studio will report that it's not uncovered. When we view code coverage data, we might want to switch to the source code. There maybe cases that not every IL instruction can be mapped back to source code. It could also be that one C# statement is compiled into multiple IL instructions, part of those instructions are executed while others are not. In both scenarios, you may noticed that every line of source code are covered, while the Visual Studio reports that there are uncovered code.


    Please mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Bill.Wang Thursday, October 16, 2008 6:43 AM
    Tuesday, October 14, 2008 5:39 AM
  • Ok.  What's the preferred approach to conduct unit test WCF components that are deployed over in IIS?

    Tuesday, October 14, 2008 12:40 PM
  • We have a document about testing web service. It should apply to web services implemented by WCF. And if you have plan to load test WCF web services, try WCF Load Test. It will make the work very easy.


    Please mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Bill.Wang Thursday, October 16, 2008 6:43 AM
    Wednesday, October 15, 2008 7:50 AM