{"id":237177,"date":"2022-03-16T11:00:32","date_gmt":"2022-03-16T18:00:32","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/visualstudio\/?p=237177"},"modified":"2022-07-29T04:23:25","modified_gmt":"2022-07-29T11:23:25","slug":"live-unit-testing-preview-better-and-faster","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/visualstudio\/live-unit-testing-preview-better-and-faster\/","title":{"rendered":"Live Unit Testing Preview: Better and Faster"},"content":{"rendered":"<p>Live Unit Testing is the automatic test running feature in Visual Studio Enterprise. As you make code changes, Live Unit Testing detects what tests are impacted and runs them in the background. This way you always know if the tests covering a certain line of code are passing or failing. You can see what your code coverage is for each line of your product code at a glance. You get instant feedback in the editor with pass\/fail icons in the margin and you can easily run or debug the impacted tests from the Live Unit Testing icons. Live Unit Testing will help you catch if new code changes cause tests to fail as you develop so you won\u2019t forget to do a test run before pushing changes ever again.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/live-unit-testing-gif-trim.gif\"><img decoding=\"async\" class=\"alignnone wp-image-237203 size-full\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/live-unit-testing-gif-trim.gif\" alt=\"gif of live unit testing running.\" width=\"1780\" height=\"654\" \/><\/a><\/p>\n<p>Live Unit Testing involves building impacted projects in order to run tests. A ton of the work in this update was focused on making those builds scoped to only what is needed, build projects in parallel, and scale better.<\/p>\n<p>&nbsp;<\/p>\n<h2>What&#8217;s new and how can I get it?<\/h2>\n<p>In Visual Studio Enterprise 2022 version 17.2 Preview 2 and later, you can enable the new Live Unit Testing experience in <strong>Tools &gt; Options &gt; Preview Features<\/strong>. Enable the option <strong>New build experience for Live Unit Testing (requires restart)<\/strong>. If you have any issues with the new experience you can disable this option, but please <a href=\"https:\/\/docs.microsoft.com\/visualstudio\/ide\/how-to-report-a-problem-with-visual-studio?view=vs-2022\">report it<\/a> so we can make the experience better.<\/p>\n<p><strong>Note: In Visual Studio Enterprise 2022 version 17.3 and later, there is no need to click the checkbox as this is out of preview and is the default experience.<\/strong><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/word-image.png\"><img decoding=\"async\" class=\"alignnone wp-image-237179 size-full\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/word-image.png\" alt=\"Live Unit Testing preview feature option\" width=\"1037\" height=\"717\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/word-image.png 1037w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/word-image-300x207.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/word-image-1024x708.png 1024w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/word-image-768x531.png 768w\" sizes=\"(max-width: 1037px) 100vw, 1037px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h2>Performance<\/h2>\n<h4>Faster scoped builds<\/h4>\n<p>Live Unit Testing now only builds projects that are relevant to the edits you make and that match the tests that you have included in Live Unit Testing.<\/p>\n<h4>Parallel builds<\/h4>\n<p>Live Unit Testing can now build projects in parallel, further speeding up your test runs as you make edits.<\/p>\n<h2>Scalability<\/h2>\n<h4>Better default behavior<\/h4>\n<p>For large solutions, we encourage users to select only a subset of tests in Live Unit Testing. This leads to a shorter build time, less memory footprint, and a shorter test run and coverage analysis time. Live Unit Testing has also been optimized now to only build and run the tests that you have included.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/playlist.gif\"><img decoding=\"async\" class=\"alignnone wp-image-237167 size-full\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/playlist.gif\" alt=\"gif of Live Unit Testing playlist being used\" width=\"1179\" height=\"634\" \/><\/a><\/p>\n<h4>Large solution support<\/h4>\n<p>With all the improvements made, Live Unit Testing can now work against larger solutions.\nFor example, Live Unit Testing now works on the C# Compilers.sln. In the gif below, tests from one class have been included in Live Unit Testing.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/compilers-sln-1.gif\"><img decoding=\"async\" class=\"alignnone wp-image-237200 size-full\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/compilers-sln-1.gif\" alt=\"gif of Live Unit Testing working on the C# Compilers\" width=\"2297\" height=\"1545\" \/><\/a><\/p>\n<h2>Reliability<\/h2>\n<h4>More dependable builds<\/h4>\n<p>The build mechanism that Live Unit Testing now uses is closer to how you would use msbuild on the command-line.<\/p>\n<h4>Wider solution support<\/h4>\n<p>With dependable builds and support for large solutions, Live Unit Testing now supports a wide variety of solutions out of the box.<\/p>\n<h2>User experience<\/h2>\n<h4>Configuration and setup<\/h4>\n<p>We now offer a configuration experience for Live Unit Testing through a wizard. When you start Live Unit Testing for the first time in a solution, you will see the below wizard UI.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/graphical-user-interface-text-application-email-1.png\"><img decoding=\"async\" class=\"alignnone wp-image-237190 size-full\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/graphical-user-interface-text-application-email-1.png\" alt=\"Live Unit Testing wizard UI\" width=\"1197\" height=\"841\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/graphical-user-interface-text-application-email-1.png 1197w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/graphical-user-interface-text-application-email-1-300x211.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/graphical-user-interface-text-application-email-1-1024x719.png 1024w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/graphical-user-interface-text-application-email-1-768x540.png 768w\" sizes=\"(max-width: 1197px) 100vw, 1197px\" \/><\/a><\/p>\n<p><strong>Note: In Visual Studio Enterprise 2022 version 17.3 and later, the option to generate PDBs is enabled by default and no longer configurable in the Live Unit Testing configuration wizard.<\/strong><\/p>\n<p>Live Unit Testing needs to instrument your projects on building to determine test coverage so that when you make an edit in a file, it knows which tests to run. To ensure that your regular dev workflow remains unaffected, Live Unit Testing operates on a duplicate private workspace. Live Unit Testing utilizes the Windows Projected File System optional Windows feature to maintain this private workspace.<\/p>\n<p>Note: Windows Projected File System should be enabled automatically when Visual Studio is installed. But in case it happens to be disabled, you can enable it via the \u201cTurn Windows features on or off\u201d dialog or using PowerShell. See <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/projfs\/enabling-windows-projected-file-system\">docs<\/a>.<\/p>\n<p>Live Unit Testing now supports a .lutignore file (similar to a .gitignore) which you can use to indicate the set of files that need to be synchronized from the repository root to the Live Unit Testing\u2019s private workspace. The main purpose of the .lutignore file is to ensure that build artifacts from your regular build output folders are excluded from this synchronization (so that the private workspace folder will only contain build artifacts that have been instrumented for Live Unit Testing).<\/p>\n<p>You have the option to use your repository\u2019s existing gitignore file for this. Alternatively, if you select the \u201cCommon artifacts eg. bin\/, obj\/, *.dll, *.obj\u201d or \u201cCustom\u201d option in the dropdown shown below, Live Unit Testing will create one for you.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/graphical-user-interface-text-description-automa-1.png\"><img decoding=\"async\" class=\"alignnone wp-image-237192 size-full\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/graphical-user-interface-text-description-automa-1.png\" alt=\"Live Unit Testing dropdown for lutignore\" width=\"643\" height=\"177\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/graphical-user-interface-text-description-automa-1.png 643w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/graphical-user-interface-text-description-automa-1-300x83.png 300w\" sizes=\"(max-width: 643px) 100vw, 643px\" \/><\/a><\/p>\n<p>To access the wizard again, you can go to <strong>Test -&gt; Live Unit Testing -&gt; Configure Live Unit Testing for solution<\/strong>. (You will need to stop Live Unit Testing to enable this command.)<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/graphical-user-interface-application-word-descr.png\"><img decoding=\"async\" class=\"alignnone wp-image-237188 size-full\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/graphical-user-interface-application-word-descr.png\" alt=\"editor right click menu for configuring Live Unit Testing\" width=\"1054\" height=\"298\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/graphical-user-interface-application-word-descr.png 1054w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/graphical-user-interface-application-word-descr-300x85.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/graphical-user-interface-application-word-descr-1024x290.png 1024w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/graphical-user-interface-application-word-descr-768x217.png 768w\" sizes=\"(max-width: 1054px) 100vw, 1054px\" \/><\/a><\/p>\n<p>Note: The settings configured above are persisted in a file with extension .lutconfig that is placed next to your solution. Both the .lutconfig file as well as the .lutignore file can be checked in into your repository.<\/p>\n<h4>Cancellation<\/h4>\n<p>Previously, if you had a test that was hanging or timing out, you would have to wait for the default timeout time until your new edits could be tested. Live Unit Testing now offers a way to cancel the in-progress test run if you have made newer code edits. This makes it easier for you to get feedback on your latest code change if your tests take a long time to run.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/cancel-ui-gif.gif\"><img decoding=\"async\" class=\"alignnone wp-image-237169 size-full\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/cancel-ui-gif.gif\" alt=\"gif of Live UNit Testing cancellation UI being used.\" width=\"1227\" height=\"483\" \/><\/a><\/p>\n<p>Live Unit Testing also offers a way to cancel previous test runs on File Save. The Option can be found in <strong>Tools -&gt; Options -&gt; Live Unit Testing -&gt; \u201cRestart test run on document save\u201d<\/strong><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/restart-on-save.png\"><img decoding=\"async\" class=\"alignnone wp-image-237174 size-full\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/restart-on-save.png\" alt=\"Live Unit Testing tools option menu\" width=\"1234\" height=\"784\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/restart-on-save.png 1234w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/restart-on-save-300x191.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/restart-on-save-1024x651.png 1024w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/restart-on-save-768x488.png 768w\" sizes=\"(max-width: 1234px) 100vw, 1234px\" \/><\/a><\/p>\n<h3>Special mentions<\/h3>\n<p>The Live Unit Testing window now indicates running tests with a spinner, similar to the Test Explorer window.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/graphical-user-interface-text-application-descr-1.gif\"><img decoding=\"async\" class=\"alignnone wp-image-237198 size-full\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/graphical-user-interface-text-application-descr-1.gif\" alt=\"gif of Live Unit Testing spinners in window.\" width=\"1897\" height=\"1066\" \/><\/a><\/p>\n<p>Live Unit Testing also has new keyboard shortcuts to include tests from the editor (e.g., Ctrl + R, I will include the test selected in the editor).<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/righ-click-include.png\"><img decoding=\"async\" class=\"alignnone wp-image-237171 size-full\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/righ-click-include.png\" alt=\"editor right click menu to include test in Live Unit Testing\" width=\"1174\" height=\"304\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/righ-click-include.png 1174w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/righ-click-include-300x78.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/righ-click-include-1024x265.png 1024w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/03\/righ-click-include-768x199.png 768w\" sizes=\"(max-width: 1174px) 100vw, 1174px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h2>Thanks for trying it out and filing bugs!<\/h2>\n<p>Please try out Live Unit Testing and file feedback with the built-in <a href=\"https:\/\/docs.microsoft.com\/visualstudio\/ide\/how-to-report-a-problem-with-visual-studio?view=vs-2022\">Report a Problem<\/a> tool in Visual Studio. Note, this feature is only available in Visual Studio Enterprise. Documentation on the new Live Unit Testing experience will be coming soon.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Live Unit Testing is the automatic test running feature in Visual Studio Enterprise. As you make code changes, Live Unit Testing detects what tests are impacted and runs them in the background. This way you always know if the tests covering a certain line of code are passing or failing. You can see what your [&hellip;]<\/p>\n","protected":false},"author":86375,"featured_media":237183,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[155],"tags":[237,361,3,5,6845,1402,6844,53,6843,1666,6846,12],"class_list":["post-237177","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-visual-studio","tag-net","tag-net-core","tag-net-framework","tag-csharp","tag-dotnet","tag-enterprise","tag-live-unit-testing","tag-performance","tag-test","tag-testing","tag-vb","tag-visual-studio"],"acf":[],"blog_post_summary":"<p>Live Unit Testing is the automatic test running feature in Visual Studio Enterprise. As you make code changes, Live Unit Testing detects what tests are impacted and runs them in the background. This way you always know if the tests covering a certain line of code are passing or failing. You can see what your [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/237177","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\/86375"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/comments?post=237177"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/237177\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media\/237183"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media?parent=237177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/categories?post=237177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/tags?post=237177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}