{"id":8373,"date":"2015-03-06T11:13:00","date_gmt":"2015-03-06T16:13:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/2015\/03\/06\/creating-unit-test-method-stubs-with-create-unit-tests\/"},"modified":"2022-07-28T00:45:58","modified_gmt":"2022-07-28T08:45:58","slug":"creating-unit-test-method-stubs-with-create-unit-tests","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/devops\/creating-unit-test-method-stubs-with-create-unit-tests\/","title":{"rendered":"Creating unit test method stubs with &#8220;Create Unit Tests&#8221;"},"content":{"rendered":"<p>In <a href=\"https:\/\/www.visualstudio.com\/downloads\/visual-studio-2015-ctp-vs\">Visual Studio 2015 CTP 6<\/a> we are introducing the &#8220;Create Unit Tests&#8221; feature that provides the ability to create unit test method stubs. The feature allows easy configuration of a\u00a0test project, and the test class and the test method stub therein. It is conveniently available as a context menu item, and can be invoked on product code at the scope of a method, a type, or a namespace. It launches a fairly self-explanatory dialog that surfaces the options that can be configured (does the look and feel\u00a0seem familiar to you?). Support is presently for C# and the MSTest framework but enhancements are in the pipeline.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2015\/03\/0842.CreateUnitTest.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p>This addresses a\u00a0popular \u201cask\u201d on <a href=\"http:\/\/visualstudio.uservoice.com\/forums\/121579-visual-studio\/suggestions\/2748862-add-create-unit-tests-menu-option-back\">user voice<\/a> from the community.<\/p>\n<p>If we take a step back and look at the purpose that a unit test serves, then this \u201cask\u201d underscores\u00a0the diversity of unit testing approaches. A unit test serves as an executable specification representing the intended behaviour of the code, for some chosen test values. When such a test fails it means that the code does not do what it\u2019s supposed to do. Some testing practices grow the code by building such a specification ground up, starting from a failing test case. A practitioner might approach this situation by choosing to start from the unit test template available through the Visual Studio project system.<\/p>\n<p>But there are situations that may not readily afford this practice. Consider existing code with very little to no test coverage, and no documentation either\u00a0&#8211; i.e. where there is limited or non-existent specifications. Here, fully baked code serves as the starting point, and the tests need to be built ground up. For this situation, an approach might be to bring to bear the intelligence of <a href=\"http:\/\/blogs.msdn.com\/b\/visualstudioalm\/archive\/2014\/11\/19\/introducing-smart-unit-tests.aspx\">Smart Unit Tests<\/a> and have it generate a suite of tests characterizing the observed behaviour of the code.<\/p>\n<p>Then there is the situation where the developer starts by writing some code, and uses that to boot strap the unit testing discipline. Within the flow of coding, the developer might want to quickly create a unit test method stub (with a suitable test class, and a suitable test project) for a particular piece of code. The use of the &#8220;Create Unit Tests&#8221; feature might be the approach in this situation.<\/p>\n<p>Much as with coding, there are different approaches to unit testing as well &#8211; varying from that of the purist to that of the pragmatist &#8211; from \u201ctest first\u201d to \u201ccode first\u201d to those\u00a0who might want the flexibility to start in either of the ways. We see &#8220;Create Unit Tests&#8221; as an important addition to the complement of features we have for supporting these various approaches. We hope you find this feature, and indeed the other features you are seeing us introduce in the unit testing space, to your liking.<\/p>\n<p>As ever, please submit bugs through <span style=\"text-decoration: underline\"><a href=\"https:\/\/connect.microsoft.com\/visualstudio\">Connect<\/a><\/span>, suggestions on <a href=\"http:\/\/visualstudio.uservoice.com\/forums\/121579-visual-studio\">Uservoice<\/a>,\u00a0and quick thoughts via <a href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkId=517102\">Send-a-Smile<\/a>\u00a0in the Visual Studio IDE. We look forward to your feedback.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Visual Studio 2015 CTP 6 we are introducing the &#8220;Create Unit Tests&#8221; feature that provides the ability to create unit test method stubs. The feature allows easy configuration of a\u00a0test project, and the test class and the test method stub therein. It is conveniently available as a context menu item, and can be invoked [&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,252],"tags":[],"class_list":["post-8373","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ci","category-devops","category-testing"],"acf":[],"blog_post_summary":"<p>In Visual Studio 2015 CTP 6 we are introducing the &#8220;Create Unit Tests&#8221; feature that provides the ability to create unit test method stubs. The feature allows easy configuration of a\u00a0test project, and the test class and the test method stub therein. It is conveniently available as a context menu item, and can be invoked [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/8373","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=8373"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/8373\/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=8373"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/categories?post=8373"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/tags?post=8373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}