{"id":257145,"date":"2026-09-15T09:00:21","date_gmt":"2026-09-15T16:00:21","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/visualstudio\/?p=257145"},"modified":"2026-08-27T18:24:08","modified_gmt":"2026-08-28T01:24:08","slug":"today-i-will-improve-test-coverage","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/visualstudio\/today-i-will-improve-test-coverage\/","title":{"rendered":"Today I will&#8230; improve test coverage"},"content":{"rendered":"<p>Today I want to look at how we can improve on the test coverage that we have in the <a href=\"https:\/\/github.com\/Azure-Samples\/interview-coach-agent-framework\">Interview Coach application<\/a>. This application has some unit tests in it already, but I&#8217;m sure there is room for improvement.<\/p>\n<h2>Defining our baseline<\/h2>\n<p>Before we start writing tests, it&#8217;s a good idea to have a baseline of what our coverage is so that we can find out where the gaps are, rather than just writing tests &#8220;for the sake of writing tests&#8221;.<\/p>\n<p>We can do this using the Analyze Code Coverage for All Tests, from either the Command Palette (CTRL + SHIFT + P) or the Tests menu.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2026\/08\/Image-6.webp\"><img decoding=\"async\" width=\"1920\" height=\"1080\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2026\/08\/Image-6.webp\" alt=\"Feature Search for test coverage\" class=\"alignnone size-medium wp-image-257146\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2026\/08\/Image-6.webp 1920w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2026\/08\/Image-6-300x169.webp 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2026\/08\/Image-6-1024x576.webp 1024w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2026\/08\/Image-6-768x432.webp 768w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2026\/08\/Image-6-1536x864.webp 1536w\" sizes=\"(max-width: 1920px) 100vw, 1920px\" \/><\/a><\/p>\n<p>Running the analyzer, we can see where our coverage is sitting:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2026\/08\/Image-1-1.webp\"><img decoding=\"async\" width=\"793\" height=\"194\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2026\/08\/Image-1-1.webp\" alt=\"Test Coverage results\" class=\"alignnone size-medium wp-image-257147\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2026\/08\/Image-1-1.webp 793w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2026\/08\/Image-1-1-300x73.webp 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2026\/08\/Image-1-1-768x188.webp 768w\" sizes=\"(max-width: 793px) 100vw, 793px\" \/><\/a><\/p>\n<p>It looks like our coverage isn&#8217;t great, there&#8217;s a lot of gaps in the <code>InterviewCoach.Agent<\/code> project, and then other projects, such as <code>InterviewCoach.Mcp.InterviewData<\/code>, which doesn&#8217;t even have any tests. Let&#8217;s start with some tests for the <code>InterviewSessionTool<\/code> class within that project.<\/p>\n<h2>Writing tests with Copilot<\/h2>\n<p>The class we&#8217;re going to write tests for is a simple class, it takes an interface of our repository, so we can mock the database calls, and the methods receive a payload to work with the repository.<\/p>\n<p>To speed things along, we&#8217;re going to use the <a href=\"https:\/\/aka.ms\/githubcopilot-testing\">Test Agent<\/a> from GitHub Copilot and provide it with the file we want the tests written for.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2026\/08\/Image-2-1.webp\"><img decoding=\"async\" width=\"341\" height=\"130\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2026\/08\/Image-2-1.webp\" alt=\"Test Agent usage\" class=\"alignnone size-medium wp-image-257148\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2026\/08\/Image-2-1.webp 341w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2026\/08\/Image-2-1-300x114.webp 300w\" sizes=\"(max-width: 341px) 100vw, 341px\" \/><\/a><\/p>\n<p>The agent will analyse the class, then the solution to find the right approach to writing tests. Since we don&#8217;t have a test class for the project yet, it&#8217;ll generate one, add the references, and then write our test cases.<\/p>\n<p>After a few minutes the agent is done.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2026\/08\/Image-3-1.webp\"><img decoding=\"async\" width=\"525\" height=\"957\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2026\/08\/Image-3-1.webp\" alt=\"Test Agent output in Copilot Chat\" class=\"alignnone size-medium wp-image-257149\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2026\/08\/Image-3-1.webp 525w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2026\/08\/Image-3-1-165x300.webp 165w\" sizes=\"(max-width: 525px) 100vw, 525px\" \/><\/a><\/p>\n<p>It gives a nice summary of what&#8217;s been completed, we have 8 new tests added, along with a new test project. The tests were run, and it&#8217;s suggesting we run the coverage report again.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2026\/08\/Image-4-1.webp\"><img decoding=\"async\" width=\"760\" height=\"185\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2026\/08\/Image-4-1.webp\" alt=\"Updated coverage report\" class=\"alignnone size-medium wp-image-257150\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2026\/08\/Image-4-1.webp 760w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2026\/08\/Image-4-1-300x73.webp 300w\" sizes=\"(max-width: 760px) 100vw, 760px\" \/><\/a><\/p>\n<p>This is a considerable improvement on where we were at beforehand.<\/p>\n<h2>Full solution test analysis<\/h2>\n<p>The Test agent has done a great job at building out the tests for our class, but there&#8217;s still a lot of the codebase that doesn&#8217;t have tests, and we can use the Test agent to help with that because we can tell it to run across the whole solution and analyze our gaps:<\/p>\n<pre><code>@test #solution\n<\/code><\/pre>\n<p>This time, we&#8217;re using the <code>#solution<\/code> context for Copilot, and now the Test agent will analyze all projects and code paths. After a few minutes, Copilot has come back to me with tests covering the repository, the <code>DbContext<\/code>, our extension methods, as well as more tests in the <code>InterviewCoach.Agent<\/code> project. It also identified that there was no value in writing tests for files such as <code>AgentMode.cs<\/code> since it just contains an enum, thus there&#8217;s nothing to test.<\/p>\n<p>With this, our coverage is up to 81%, up from 37% to start with, and includes three projects we originally didn&#8217;t have tests for at all.<\/p>\n<h2>Wrap-up<\/h2>\n<p>While we know the value of writing tests, knowing where we should invest that effort is something that is often overlooked. Using the Code Coverage analysis in Visual Studio gives us that overview, so we can identify the gaps in our testing, then combining that with the Test agent, we can build out targeted tests for a single class or perform a solution-wide analysis and uplift.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today I want to look at how we can improve on the test coverage that we have in the Interview Coach application. This application has some unit tests in it already, but I&#8217;m sure there is room for improvement. Defining our baseline Before we start writing tests, it&#8217;s a good idea to have a baseline [&hellip;]<\/p>\n","protected":false},"author":40333,"featured_media":257206,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[6936,6888,6963],"tags":[1666],"class_list":["post-257145","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-code-coverage","category-copilot","category-productivity","tag-testing"],"acf":[],"blog_post_summary":"<p>Today I want to look at how we can improve on the test coverage that we have in the Interview Coach application. This application has some unit tests in it already, but I&#8217;m sure there is room for improvement. Defining our baseline Before we start writing tests, it&#8217;s a good idea to have a baseline [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/257145","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/users\/40333"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/comments?post=257145"}],"version-history":[{"count":2,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/257145\/revisions"}],"predecessor-version":[{"id":257154,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/257145\/revisions\/257154"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media\/257206"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media?parent=257145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/categories?post=257145"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/tags?post=257145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}