{"id":245230,"date":"2023-09-20T10:00:02","date_gmt":"2023-09-20T17:00:02","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/visualstudio\/?p=245230"},"modified":"2023-09-20T06:45:06","modified_gmt":"2023-09-20T13:45:06","slug":"intellitest-simplifies-writing-and-maintaining-unit-tests","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/visualstudio\/intellitest-simplifies-writing-and-maintaining-unit-tests\/","title":{"rendered":"IntelliTest simplifies writing and maintaining unit tests"},"content":{"rendered":"<p>Writing a suite of unit tests that exhaustively exercise and validate the logic of the code is not easy. It can even be considered too expensive to do at all. Fortunately, <a href=\"https:\/\/learn.microsoft.com\/en-us\/visualstudio\/test\/intellitest-manual\/?view=vs-2022\">IntelliTest <\/a>addresses both concerns: it helps you achieve high code coverage at a fraction of the cost, and now in Preview, this Enterprise feature supports projects that target .NET6 and will run on x64.<\/p>\n<p>When you run on your .NET code, it generates test cases by dynamically analyzing the code. For every statement in the code, it crafts an input that will reach that statement, doing a case analysis for every conditional branch\u2014if statements, assertions, and all operations that can throw exceptions\u2014much like white box testing. The goal is to generate a test suite covering all branches of your code, and so every time it crafts an input that increases coverage, it emits that concrete value as a test case using C# and MSTest (xUnit and NUnit\u00a0 to come) as the test framework. The result is a compact suite of tests with high coverage that you didn\u2019t have to write from scratch.<\/p>\n<p>This updated version of IntelliTest is powered by the latest version of the and it generates a varied set of inputs (scoped to those that improve code coverage) that are then plugged into what we call parameterized unit tests for each of your methods. When you Generate Tests, you can select which tests you\u2019d like to preserve into a test project that can serve as your regression suite. As your code is updated, you can rerun IntelliTest to keep the generated tests in sync with your code.<\/p>\n<p>Previous implementations of this Enterprise Edition feature only supported code targeting .NET Framework and did not support x64 configuration. This updated version includes the following:<\/p>\n<ul>\n<li><a href=\"https:\/\/developercommunity.visualstudio.com\/t\/add-intellitest-support-for-net-corestandard\/359250\">Add IntelliTest support for .NET Core\/Standard \u2013 Developer Community (visualstudio.com)<\/a><\/li>\n<li><a href=\"https:\/\/developercommunity.visualstudio.com\/t\/Add-IntelliTest-support-for-x64\/501088?q=intellitest+x64\">Add IntelliTest support for x64 \u2013 Developer Community (visualstudio.com)<\/a><\/li>\n<\/ul>\n<p>Give it a try on your projects today by enabling the feature through Tools &gt; Manage Preview Features and selecting IntelliTest support for NetFx and Net6 using Z3 v4 (requires restart).<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2023\/09\/IntelliTestSetting.png\"><img decoding=\"async\" class=\"aligncenter wp-image-245231 size-full\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2023\/09\/IntelliTestSetting.png\" alt=\"Screenshot of setting in Visual Studio to turn on IntelliTest\" width=\"859\" height=\"100\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2023\/09\/IntelliTestSetting.png 859w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2023\/09\/IntelliTestSetting-300x35.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2023\/09\/IntelliTestSetting-768x89.png 768w\" sizes=\"(max-width: 859px) 100vw, 859px\" \/><\/a><\/p>\n<p>Then in your code, right click within a method and select IntelliTest (Preview) and either Create Project to create a project where your tests can be saved or Generate Tests to generate a set of tests to review and decide which ones to keep.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2023\/09\/IntelliTestFlow.png\"><img decoding=\"async\" class=\"size-large wp-image-245232 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2023\/09\/IntelliTestFlow-1024x600.png\" alt=\"1 Edit Code; Invoke IntelliTest - 2 Inspect input\/output behavior with test outcomes - 3 Save as regular unit tests\" width=\"640\" height=\"375\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2023\/09\/IntelliTestFlow-1024x600.png 1024w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2023\/09\/IntelliTestFlow-300x176.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2023\/09\/IntelliTestFlow-768x450.png 768w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2023\/09\/IntelliTestFlow.png 1457w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>Whether you are evolving existing\/legacy code and try out IntelliTest to generate a safety net of test before beginning refactoring or exploring existing\/new code and use IntelliTest to understand the input\/output behavior of the code against various data values, try the updated IntelliTest today!<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Writing a suite of unit tests that exhaustively exercise and validate the logic of the code is not easy. It can even be considered too expensive to do at all. Fortunately, IntelliTest addresses both concerns: it helps you achieve high code coverage at a fraction of the cost, and now in Preview, this Enterprise feature [&hellip;]<\/p>\n","protected":false},"author":97078,"featured_media":244816,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[155],"tags":[332,1666],"class_list":["post-245230","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-visual-studio","tag-intellitest","tag-testing"],"acf":[],"blog_post_summary":"<p>Writing a suite of unit tests that exhaustively exercise and validate the logic of the code is not easy. It can even be considered too expensive to do at all. Fortunately, IntelliTest addresses both concerns: it helps you achieve high code coverage at a fraction of the cost, and now in Preview, this Enterprise feature [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/245230","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\/97078"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/comments?post=245230"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/245230\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media\/244816"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media?parent=245230"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/categories?post=245230"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/tags?post=245230"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}