{"id":25945,"date":"2016-11-29T20:27:27","date_gmt":"2016-11-30T03:27:27","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/?p=25945"},"modified":"2019-02-14T15:56:00","modified_gmt":"2019-02-14T23:56:00","slug":"evolving-the-test-platform-part-3-net-core-convergence-and-cross-plat","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/devops\/evolving-the-test-platform-part-3-net-core-convergence-and-cross-plat\/","title":{"rendered":"Evolving the Visual Studio Test Platform &#8211; Part 3: .NET Core, convergence, and cross-plat"},"content":{"rendered":"<p><em>[This is the 3rd post in the series on evolving the Visual Studio Test Platform. You can read the earlier posts here:<\/em>\n<em><a href=\"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/2016\/08\/05\/evolving-the-visual-studio-test-platform-part-2\/\">Evolving the Visual Studio Test Platform \u2013 Part 2<\/a>,<\/em>\n<em><a href=\"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/2016\/07\/25\/evolving-the-visual-studio-test-platform-part-1\/\">Evolving the Visual Studio Test Platform \u2013 Part 1<\/a>]<\/em><\/p>\n<p>As .NET Core draws an ever-growing community of developers with existing assets and experiences, it is essential to support a <a href=\"https:\/\/blogs.msdn.microsoft.com\/dotnet\/2016\/11\/16\/announcing-net-core-tools-msbuild-alpha\/\">consistent tools ecosystem<\/a>. Thus, the &#8220;alpha&#8221; release of the <a href=\"https:\/\/github.com\/dotnet\/core\/tree\/master\/release-notes\">MSBuild-based .NET Core Tools<\/a> shipping with <a href=\"https:\/\/www.visualstudio.com\/vs\/visual-studio-2017-rc\/\">Visual Studio 2017 RC<\/a> introduces support for the MSBuild build system and the .csproj project format &#8211; both familiar and key components of the .NET tools ecosystem. The need for a consistent testing experience follows naturally. Thus, the .NET Core testing experience\/ecosystem is now converged with the <a href=\"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/2016\/07\/25\/evolving-the-visual-studio-test-platform-part-1\/\">Visual Studio Test Platform<\/a>.<\/p>\n<p>Concretely, this means the following:\n<strong>(1)<\/strong> Evolved test platform: vstest is now fully cross-plat (Windows\/Linux\/Mac). <strong>dotnet test<\/strong> now leverages this evolved\u00a0Visual Studio Test Platform.\n<strong>(2)<\/strong> Converged adapters: Adapter writers can maintain a converged adapter that can serve Visual Studio, the vstest.console.exe CLI and the dotnet CLI.\n<strong>(3)<\/strong> Converged user experience: the experience of using vstest.console.exe (the same options and capabilities) on the .NET Framework will be available on .NET Core as well.<\/p>\n<p>Let\u2019s see how \u2026<\/p>\n<h3>Evolved test platform<\/h3>\n<p>The evolved vstest engine is presently named <strong>Microsoft.TestPlatform.V2<\/strong> and is packaged as a vsix extension. Launch <code>Tools | Extensions and Update\u2026<\/code> and you will notice that this is already bundled with Visual Studio.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/54.jpg\"><img decoding=\"async\" width=\"953\" height=\"470\" class=\"alignnone size-full wp-image-25955\" alt=\"5\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/11\/54.jpg\" \/><\/a>\n<code>C:Program Files (x86)Microsoft Visual Studio2017EnterpriseCommon7IDEExtensions<\/code> is the folder where extensions are installed.<\/p>\n<h3>Converged Test Adapter for .NET Framework and .NET Core<\/h3>\n<p>When we first introduced MSTest V2 support there were 2 adapters &#8211; <a href=\"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/2016\/05\/30\/announcing-mstest-framework-support-for-net-core-rc2-asp-net-core-rc2\/\">dotnet-test-mstest to target .NET Core<\/a>, and <a href=\"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/2016\/06\/17\/taking-the-mstest-framework-forward-with-mstest-v2\/\">MSTest.TestAdapter to target the .NET Framework<\/a>. The dotnet-test-mstest adapter understands the project.json based project format. With .NET Core now supporting .csproj, that adapter is no longer required! <strong>Instead, the MSTest.TestAdapter can be used!<\/strong><\/p>\n<p>Launch Visual Studio 2017 RC, and create a Unit Test Project (.NET Core). This creates an MSTest V2 based solution targeting .NET Core. Now, look at the references.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/111.jpg\"><img decoding=\"async\" width=\"1107\" height=\"313\" class=\"alignnone size-full wp-image-25965\" alt=\"1\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/11\/111.jpg\" \/><\/a><\/p>\n<p>The solution is self-contained &#8211; it refers the vstest engine, the MSTest V2 test framework, and the MSTest.TestAdapter to discover\/run such tests using the engine. And it is targeting .NET Core.<\/p>\n<div>\n<p>The same approach can be used by other test frameworks as well. For e.g., xUnit.net too has 2 adapters &#8211; dotnet-test-xunit to target .NET Core, and xunit.runner.visualstudio to target the .NET Framework, but with .NET Core now supporting .csproj, the dotnet-test-xunit is no longer required either. Instead, the xunit.runner.visualstudio adapter can be used. Here is a .NET Core unit test solution using the xUnit.net test framework:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/29.jpg\"><img decoding=\"async\" width=\"1103\" height=\"304\" class=\"alignnone size-full wp-image-25975\" alt=\"2\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/11\/29.jpg\" \/><\/a><\/p>\n<p>The solution is self-contained &#8211; it refers the vstest engine, the xUnit.net test framework, and the xunit.runner.visualstudio test adapter to discover\/run such tests using the engine. This same adapter is used when targeting both the .NET Framework and .NET Core.<\/p>\n<p><em>[Note: the evolved test platform has the notion of a translation layer that enables interfacing with IDEs to perform common tasks like discover tests, run tests, get the results to display, etc.\u00a0This will be released soon on NuGet. In the meantime, we worked closely with the xUnit.net team to implement this support using early bits. We look forward to working with the community to extend this support.]<\/em><\/p>\n<p>Let\u2019s continue with this solution in our brief tour of the functionality.<\/p>\n<\/div>\n<h3>Testing using the Visual Studio IDE<\/h3>\n<p>The below figure illustrates testing from within the Visual Studio IDE.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/34new.jpg\"><img decoding=\"async\" width=\"1195\" height=\"572\" class=\"alignnone size-full wp-image-25995\" alt=\"34new\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/11\/34new.jpg\" \/><\/a><\/p>\n<p>This is same experience provided in the case of tests targeting the.NET Framework.<\/p>\n<h3>Testing using vstest.console.exe<\/h3>\n<p><code>C:Program Files (x86)Microsoft Visual Studio2017EnterpriseCommon7IDEExtensions<\/code> is the folder where extensions are installed, remember? Locate <strong>vstest.console.exe<\/strong> under this folder.\nNavigate to the folder containing the xUnit.net test project, and use <strong>vstest.console.exe<\/strong> to run the tests as shown:<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/6new.jpg\"><img decoding=\"async\" width=\"1084\" height=\"556\" class=\"alignnone size-full wp-image-26075\" alt=\"6new\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/11\/6new.jpg\" \/><\/a>Notice that vstest.console.exe takes the DLL(s) as input \u2013 just like it does in the case of tests targeting the .NET Framework. Go ahead, try this out and see what other switches can be used!<\/p>\n<h3>Testing using the .NET Core CLI<\/h3>\n<p>You can try these steps with latest dotnet-cli builds, since a critical bug fix couldn\u2019t make it to RC release.\nInstall the latest .NET Code SDK Preview build from here:\u00a0 <a href=\"https:\/\/github.com\/dotnet\/core\/tree\/master\/release-notes\">https:\/\/github.com\/dotnet\/core\/tree\/master\/release-notes<\/a>. I downloaded it to the folder <code>D:tempdotnet<\/code> on my machine.\nUse <strong>dotnet test<\/strong> to run the tests as shown:<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/7new.jpg\"><img decoding=\"async\" width=\"1084\" height=\"700\" class=\"alignnone size-full wp-image-26085\" alt=\"7new\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/11\/7new.jpg\" \/><\/a>\nThe command automatically picks up the .csproj file(s) and discovers and runs the appropriate tests using the referenced xunit.runner.visualstudio adapter.<\/p>\n<h3>Testing using VSTS<\/h3>\n<p>To run the tests using VSTS, I setup a local build agent with Visual Studio 2017, and these same .NET Core SDK bits.\nHere is the build definition:<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/8new.jpg\"><img decoding=\"async\" width=\"858\" height=\"808\" class=\"alignnone size-full wp-image-26105\" alt=\"8new\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/11\/8new.jpg\" \/><\/a><\/p>\n<p>Queue up a build and\u00a0you should see the report.<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/9new.jpg\"><img decoding=\"async\" width=\"1308\" height=\"717\" class=\"alignnone size-full wp-image-26115\" alt=\"9new\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/11\/9new.jpg\" \/><\/a><\/p>\n<h3>Summary<\/h3>\n<p>The .NET Core testing experience\/ecosystem is now converged with the Visual Studio Test Platform. This is a huge benefit to everyone &#8211; same adapters, common invocation model, much broader feature set than CLI). As mentioned earlier, we will release the translation layer to NuGet soon, and look forward to working with you to get more adapters interfacing with the test platform.<\/p>\n<p>Stay tuned!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[This is the 3rd post in the series on evolving the Visual Studio Test Platform. You can read the earlier posts here: Evolving the Visual Studio Test Platform \u2013 Part 2, Evolving the Visual Studio Test Platform \u2013 Part 1] As .NET Core draws an ever-growing community of developers with existing assets and experiences, it [&hellip;]<\/p>\n","protected":false},"author":765,"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-25945","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ci","category-devops","category-testing"],"acf":[],"blog_post_summary":"<p>[This is the 3rd post in the series on evolving the Visual Studio Test Platform. You can read the earlier posts here: Evolving the Visual Studio Test Platform \u2013 Part 2, Evolving the Visual Studio Test Platform \u2013 Part 1] As .NET Core draws an ever-growing community of developers with existing assets and experiences, it [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/25945","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\/765"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/comments?post=25945"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/25945\/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=25945"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/categories?post=25945"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/tags?post=25945"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}