{"id":4783,"date":"2012-06-19T10:45:00","date_gmt":"2012-06-19T10:45:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/2012\/06\/19\/visual-studio-2012-rc-whats-new-in-code-coverage\/"},"modified":"2022-07-25T05:21:24","modified_gmt":"2022-07-25T13:21:24","slug":"visual-studio-2012-rc-whats-new-in-code-coverage","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/devops\/visual-studio-2012-rc-whats-new-in-code-coverage\/","title":{"rendered":"Visual Studio 2012 RC \u2013 What\u2019s new in Code Coverage"},"content":{"rendered":"<p align=\"justify\">\n  \u00a0\n<\/p>\n<p>As product development adapts to the demands of continuous delivery models and agile methodologies, the developer is being entrusted with bringing in product changes with a higher quality bar. Besides strengthening processes to include quality checkpoints like gated check-ins, rolling builds and other regression checks, the developer can provide a higher degree of confidence in their code by ensuring that all product code changes are accompanied by a strong suite of unit tests. Test Driven Development (TDD) is one excellent step towards this. Since unit tests are owned and maintained by the developers, they can ensure that these tests are healthy and at a 100% pass rate prior to any code being committed to source control. This helps to maintain the basic sanity of product code.<\/p>\n<p>Code coverage has been a very useful metric in detecting the efficacy of your unit tests. Using code coverage numbers you can decide if your product code is being adequately exercised via your tests or if you need to work on adding some more of them into your solution. In fact some teams like to set a high code coverage percentage as a target and maintain this throughout the development lifecycle.<\/p>\n<p>Keeping these current development practices in mind the code coverage tool has been seamlessly integrated into the Unit Testing experience, making it easier to use for the developer. This has been achieved by moving from a static, post-compile instrumentation model to a dynamic, runtime instrumentation model. Those details deserve a blog post of their own though.<\/p>\n<p>\u00a0<\/p>\n<p>Today let me take you through the list of \u201cvisible\u201d changes that we trust will make your experience with code coverage a whole lot simpler.<\/p>\n<p><span style=\"color: #000000\"><span style=\"font-size: small\">1. <strong>No .testsettings overheads for code coverage<\/strong><\/span><\/span><\/p>\n<p>VS 2012 introduces a new and simplified code coverage experience. Now we instrument native and managed binaries (DLLs\/EXEs) as they are loaded at runtime as long as these binaries are a part of your solution, and get called by any of your test cases under execution. In contrast, you had to specify your target dlls in your .testsettings file in VS 2010.<\/p>\n<p>For advanced users we allow customization of our selection logic using the .runsettings file. For mode details see our blog post \u201c<a href=\"http:\/\/blogs.msdn.com\/b\/sudhakan\/archive\/2012\/05\/11\/customizing-code-coverage-in-visual-studio-11.aspx\">Customizing Code Coverage in Visual Studio 11<\/a>\u201d<\/p>\n<p>\u00a0<\/p>\n<p><span style=\"font-size: small\">2. <strong>Support in Visual Studio\u2019s Test Explorer window<\/strong><\/span><\/p>\n<p>With this prominent menu item in your Test Explorer window you can now run your tests and get code coverage data all at once, by just clicking the \u201cAnalyze Code Coverage for All Tests\u201d instead of the \u201cRun All\u201d item. With minimal execution time overhead this will run all your tests and display the code coverage results immediately after the run is completed.<\/p>\n<p><img decoding=\"async\" style=\"padding-left: 0px;padding-right: 0px;float: none;margin-left: auto;margin-right: auto;padding-top: 0px;border-width: 0px\" title=\"clip_image001\" border=\"0\" alt=\"clip_image001\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/06\/1200.clip_image001_thumb_3E76B2A8.png\" width=\"244\" height=\"181\" \/><\/p>\n<p>You get a similar menu item for code coverage when you select and run a subset of your unit tests from the Test Explorer window.<\/p>\n<p>\u00a0<\/p>\n<p><span style=\"font-size: small\">3. <strong>Native is a first class citizen<\/strong><\/span><\/p>\n<p>Yay! With the introduction of the Native Unit Test project in VS 2012 we have enabled code coverage for native code as well. Now you no longer need to move to the command line when you want coverage data for native applications. The experience remains exactly the same whether you are working with managed code or native code. What\u2019s more &#8211; mixed solutions work just as well.<\/p>\n<p>\u00a0<\/p>\n<p><span style=\"font-size: small\">4. <strong>The .coverage file is leaner and meaner<\/strong><\/span><\/p>\n<p>You want to share your .coverage file? Go ahead and share the file \u2013 and only the .coverage file. In VS 2012 the .coverage file is self-contained and we have tried to ensure that we keep the size to the very bare minimum even with this additional data. So no more copying of instrumented binaries with the .coverage file for it to open up in Visual Studio.<\/p>\n<p>\u00a0<\/p>\n<p><span style=\"font-size: small\">5. <strong>Support in the new test executor command line<\/strong><\/span><\/p>\n<p>The new unit test executor vstest.console.exe supports code coverage with a simple addition of the \u201c\/enablecodecoverage\u201d switch. Append this switch to the command line arguments used for your test run and you get code coverage data as well.<\/p>\n<p>\u00a0<\/p>\n<p><span style=\"font-size: small\">6. <strong>Support in Team Build<\/strong><\/span><\/p>\n<p>Enabling code coverage on your build definition is as simple as selecting the \u201cEnable Code Coverage\u201d item in the options combo box when you specify your test dll to be run. And yes, this works on your Team Foundation Service too.<\/p>\n<p><img decoding=\"async\" style=\"padding-left: 0px;padding-right: 0px;float: none;margin-left: auto;margin-right: auto;padding-top: 0px;border-width: 0px\" title=\"clip_image002\" border=\"0\" alt=\"clip_image002\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/06\/0218.clip_image002_thumb_40EFBE99.png\" width=\"208\" height=\"244\" \/><\/p>\n<p><em>Note: This is available only when you select the \u201cVisual Studio Test Runner\u201d<\/em><\/p>\n<p><span style=\"font-size: small\">7. <strong>Support for .net\/cpp custom unit test adapters<\/strong><\/span><\/p>\n<p>As you all know the unit testing framework is now extensible and supports custom test adapters. The xunit, nunit folks have their adapters available via the Visual Studio Extensions gallery already and code coverage is functional on these test adapters. We would work for any custom adapter that deals with .net (managed) or cpp (native) code. Caveat: If the adapter is doing any runtime magic e.g. using the .net profiler interfaces for some reason, code coverage would not be supported.<\/p>\n<p><em>Note: Other languages are not supported for code coverage<\/em><\/p>\n<p>\u00a0<\/p>\n<p>While making all the above changes we have ensured that your interaction with the .coverage file is exactly the same as VS 2010 &#8211; through the Code Coverage Results window. We continue to report block and line coverage data.<\/p>\n<p>We surely hope that the above changes have helped alleviate the pains of getting started and working with code coverage in this Agile world.<\/p>\n<p>\u00a0<\/p>\n<p>Resources:<\/p>\n<p>a) MSDN: <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/dd537628(VS.110).aspx\">Using Code Coverage to Determine How Much Code is being Tested<\/a><\/p>\n<p>b) <a href=\"http:\/\/blogs.msdn.com\/b\/allendm\/archive\/2012\/06\/05\/troubleshooting-missing-data-in-code-coverage-results.aspx\">Troubleshooting missing data in Code Coverage Results<\/a><\/p>\n<p>c) <a href=\"http:\/\/visualstudio.uservoice.com\/forums\/121579-visual-studio\">Visual Studio UserVoice<\/a><\/p>\n<p>d) <a href=\"http:\/\/social.msdn.microsoft.com\/Forums\/en-US\/vstest\/threads\">MSDN Forums<\/a><\/p>\n<p>e) <a href=\"http:\/\/connect.microsoft.com\/VisualStudio\">Microsoft Connect<\/a><\/p>\n<p>\u00a0<\/p>\n<p>Code Coverage is available in Visual Studio 2012 RC Premium and Ultimate editions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 As product development adapts to the demands of continuous delivery models and agile methodologies, the developer is being entrusted with bringing in product changes with a higher quality bar. Besides strengthening processes to include quality checkpoints like gated check-ins, rolling builds and other regression checks, the developer can provide a higher degree of confidence [&hellip;]<\/p>\n","protected":false},"author":77,"featured_media":45953,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[226,1],"tags":[],"class_list":["post-4783","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ci","category-devops"],"acf":[],"blog_post_summary":"<p>\u00a0 As product development adapts to the demands of continuous delivery models and agile methodologies, the developer is being entrusted with bringing in product changes with a higher quality bar. Besides strengthening processes to include quality checkpoints like gated check-ins, rolling builds and other regression checks, the developer can provide a higher degree of confidence [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/4783","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/users\/77"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/comments?post=4783"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/4783\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media\/45953"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media?parent=4783"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/categories?post=4783"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/tags?post=4783"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}