{"id":21026,"date":"2016-09-01T09:09:05","date_gmt":"2016-09-01T16:09:05","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/?p=21026"},"modified":"2019-02-14T17:33:39","modified_gmt":"2019-02-15T01:33:39","slug":"announcing-mstest-v2-framework-support-for-net-core-1-0-rtm","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/devops\/announcing-mstest-v2-framework-support-for-net-core-1-0-rtm\/","title":{"rendered":"Announcing MSTest V2 Framework support for .NET Core 1.0 RTM"},"content":{"rendered":"<p>MSTest V2 is now supported on .NET Core 1.0 RTM. API changes in .NET Core 1.0 leading up to RTM (see <a href=\"https:\/\/github.com\/dotnet\/corefx\/issues\/7754\">#7754<\/a>), were blocking users of the MSTest V2 packages we had released for .NET Core 1.0 RC2. Not any more\u00a0(see <a href=\"https:\/\/github.com\/dotnet\/corefx\/issues\/10713\">#10713<\/a>), we are pleased to note.<\/p>\n<p>This continues to be a preview release, and comes with following changes:<\/p>\n<ol>\n<li>dotnet-test-mstest is built against .NET Core 1.0 RTM.<\/li>\n<li>Deprecated support for netstandardapp1.5 moniker as announced <a href=\"https:\/\/github.com\/dotnet\/corefx\/blob\/master\/Documentation\/architecture\/net-platform-standard.md#deprecated-monikers\">here<\/a>.<\/li>\n<li>Fixes for bugs reported by you:\n<ol>\n<li>&#8220;the test suite returns an exit code of zero even when there are failing tests&#8221; (from a comment in our <a href=\"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/2016\/05\/30\/announcing-mstest-framework-support-for-net-core-rc2-asp-net-core-rc2\/\">earlier post<\/a>)<\/li>\n<li>&#8220;AssemblyCleanup throwing Exception in ASP.NET Core Project Targeting .NET 4.5.1&#8221; (from a comment on the <a href=\"https:\/\/social.msdn.microsoft.com\/Forums\/vstudio\/en-US\/0c393e18-f80e-4f6d-b645-1b7b44080384\/assemblycleanup-throwing-exception-in-aspnet-core-project-targeting-net-451?forum=vsunittest\">forum<\/a>)<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>Now let\u2019s go through the same steps as enumerated in our <a href=\"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/2016\/05\/30\/announcing-mstest-framework-support-for-net-core-rc2-asp-net-core-rc2\/\">earlier post<\/a>.<\/p>\n<h3>Installing the SDK<\/h3>\n<p>Install the Visual Studio official MSI installer from <a href=\"https:\/\/www.microsoft.com\/net\/core\">https:\/\/www.microsoft.com\/net\/core<\/a>.<\/p>\n<h3>Creating a class library project<\/h3>\n<p>Create a .NET Core Class Library application. Open Visual Studio, and choose File | New | Project:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/NewProject.jpg\"><img decoding=\"async\" width=\"956\" height=\"582\" class=\"alignnone size-full wp-image-21135\" alt=\"NewProject\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/09\/NewProject.jpg\" \/><\/a><\/p>\n<h3>Adding references for MSTest<\/h3>\n<p>From nuget.org, install the MSTest.TestFramework package (shown below).<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/mstestfx.jpg\"><img decoding=\"async\" width=\"465\" height=\"74\" class=\"alignnone size-full wp-image-21145\" alt=\"mstestfx\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/09\/mstestfx.jpg\" \/><\/a>Now, install the runner\u00a0&#8211; look for the updated dotnet-test-mstest package, and install it:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/dotnettestmstest.jpg\"><img decoding=\"async\" width=\"467\" height=\"73\" class=\"alignnone size-full wp-image-21155\" alt=\"dotnettestmstest\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/09\/dotnettestmstest.jpg\" \/><\/a><\/p>\n<p>Open the <code>project.json<\/code> file in the solution. You will already see the packages you just installed mentioned under &#8220;dependencies&#8221;. Add the &#8220;testRunner&#8221; property and set that to &#8220;mstest&#8221;. To make it easier, just replace the content of the <code>project.json<\/code> file with the following (and note the differences in version numbers from our <a href=\"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/2016\/05\/30\/announcing-mstest-framework-support-for-net-core-rc2-asp-net-core-rc2\/\">earlier post<\/a>):<\/p>\n<pre><code>{\n  <span style=\"color: #3366ff\">\"version\"<\/span>: <span style=\"color: #ff0000\">\"1.0.0-*\"<\/span>,\n\n  <span style=\"color: #3366ff\">\"testRunner\"<\/span>: <span style=\"color: #ff0000\">\"mstest\"<\/span>,\n\n  <span style=\"color: #3366ff\">\"dependencies\"<\/span>: {\n    <span style=\"color: #3366ff\">\"dotnet-test-mstest\"<\/span>: <span style=\"color: #ff0000\">\"1.1.1-preview\"<\/span>,\n    <span style=\"color: #3366ff\">\"MSTest.TestFramework\"<\/span>: <span style=\"color: #ff0000\">\"1.0.1-preview\"<\/span>\n  },\n\n  <span style=\"color: #3366ff\">\"frameworks\"<\/span>: {\n    <span style=\"color: #3366ff\">\"netcoreapp1.0\"<\/span>: {\n      <span style=\"color: #3366ff\">\"imports\"<\/span>: [\n        <span style=\"color: #ff0000\">\"dnxcore50\"<\/span>,\n        <span style=\"color: #ff0000\">\"portable-net45+win8\"<\/span>\n      ],\n  \n      <span style=\"color: #3366ff\">\"dependencies\"<\/span>: {\n        <span style=\"color: #3366ff\">\"Microsoft.NETCore.App\"<\/span>: {\n          <span style=\"color: #3366ff\">\"version\"<\/span>: <span style=\"color: #ff0000\">\"1.0.0\"<\/span>,\n          <span style=\"color: #3366ff\">\"type\"<\/span>: <span style=\"color: #ff0000\">\"platform\"<\/span>\n        }\n      }\n    }\n  }\n}\n<\/code><\/pre>\n<h3>Writing the tests<\/h3>\n<p>Visual Studio would have automatically created a file named <code>Class1.cs<\/code>. Open that file and replace its content with the following:<\/p>\n<pre><code><span style=\"color: #0000ff\">using<\/span> Microsoft.VisualStudio.TestTools.UnitTesting;\n\n<span style=\"color: #0000ff\">namespace<\/span> SampleNetCoreUnitTests\n{\n  [<span style=\"color: #33cccc\">TestClass<\/span>]\n  <span style=\"color: #0000ff\">public class<\/span> <span style=\"color: #33cccc\">TestClass<\/span>\n  {\n    [<span style=\"color: #33cccc\">TestMethod<\/span>]\n    <span style=\"color: #0000ff\">public void<\/span> TestMethodPassing()\n    {\n      <span style=\"color: #33cccc\">Assert<\/span>.IsTrue(<span style=\"color: #0000ff\">true<\/span>);\n    }\n\n    [<span style=\"color: #33cccc\">TestMethod<\/span>]\n    <span style=\"color: #0000ff\">public void<\/span> TestMethodFailing()\n    {\n      <span style=\"color: #33cccc\">Assert<\/span>.IsTrue(<span style=\"color: #0000ff\">false<\/span>);\n    }\n  }\n}\n<\/code><\/pre>\n<h3>Testing using the Visual Studio IDE<\/h3>\n<p>Open the Test Explorer window (Test | Windows | Test Explorer in Visual Studio).\nBuild the solution, and you should see the tests as follows:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/TED.jpg\"><img decoding=\"async\" width=\"269\" height=\"190\" class=\"alignnone size-full wp-image-21165\" alt=\"TED\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/09\/TED.jpg\" \/><\/a>\u00a0Click on &#8220;Run All&#8221; to run the tests.\n<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/TEE.jpg\"><img decoding=\"async\" width=\"273\" height=\"381\" class=\"alignnone size-full wp-image-21175\" alt=\"TEE\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/09\/TEE.jpg\" \/><\/a><\/p>\n<h3>Testing using the .NET CLI<\/h3>\n<p>Open a command prompt and navigate to the folder containing the solution, and type <code><strong>dotnet test<\/strong><\/code> to execute the tests:<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/dotnettest.jpg\"><img decoding=\"async\" width=\"1068\" height=\"336\" class=\"alignnone size-full wp-image-21185\" alt=\"dotnettest\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/09\/dotnettest.jpg\" \/><\/a>Use the <code><strong>dotnet test --list<\/strong><\/code> command to discover tests.\n<img decoding=\"async\" width=\"1068\" height=\"198\" class=\"alignnone size-full wp-image-21195\" alt=\"dotnettestlist\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/09\/dotnettestlist.jpg\" \/>Use the <code><strong>dotnet test --test<\/strong><\/code> to execute specific tests.\n<img decoding=\"async\" width=\"1068\" height=\"251\" class=\"alignnone size-full wp-image-21205\" alt=\"dotnettesttest\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/09\/dotnettesttest.jpg\" \/><\/p>\n<h3>Testing using vstest.console.exe<\/h3>\n<p>The venerable vstest.console.exe may be used as well to run tests. Open a Developer Command Prompt, and just point vstest to the project.json file using the built-in Vsix based adapter to execute the tests:\n<code><strong>vstest.console.exe project.json \/UseVsixExtensions:true<\/strong><\/code>\n<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/vstestconsole.jpg\"><img decoding=\"async\" width=\"1068\" height=\"436\" class=\"alignnone size-full wp-image-21215\" alt=\"vstestconsole\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/09\/vstestconsole.jpg\" \/><\/a>Use <code><strong>vstest.console.exe project.json \/UseVsixExtensions:true \/logger:trx<\/strong><\/code> to generate reports too.<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/vstestconsolelogger.jpg\"><img decoding=\"async\" width=\"1068\" height=\"436\" class=\"alignnone size-full wp-image-21225\" alt=\"vstestconsolelogger\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/09\/vstestconsolelogger.jpg\" \/><\/a><\/p>\n<h3>Testing using VSTS<\/h3>\n<p>To execute the tests in VSTS CI, check in the code and create a build definition with the following steps:<\/p>\n<ol>\n<li>a Command Line step that invokes the\u00a0<code>dotnet restore<\/code> (i.e. &#8220;Tool&#8221; set to <code>dotnet<\/code> and &#8220;Arguments&#8221; set to <code>restore<\/code>)<\/li>\n<li>a Visual Studio Build step with the default settings<\/li>\n<li>a Visual Studio Test step, with &#8220;TestAssembly&#8221; set to <code>**project.json<\/code>, and &#8220;Other console options&#8221; set to <code>\/UseVsixExtensions:true \/logger:trx<\/code><\/li>\n<\/ol>\n<p>Queue up the build, and you should see the following:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/CI.jpg\"><img decoding=\"async\" width=\"2560\" height=\"1259\" class=\"alignnone size-full wp-image-21245\" alt=\"CI\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2016\/09\/CI.jpg\" \/><\/a><\/p>\n<p>Build completed, tests run (with one of the tests failing as expected), and test results published!<\/p>\n<h3>Feedback<\/h3>\n<p>Thank you for the feedback you have given us till now. Not all the bugs\/issues you reported may be fixed yet, but our endeavor is to address them in subsequent drops. In the meanwhile, please continue to send us your feedback as comments on this post, or using Visual Studio&#8217;s &#8220;Report a Problem&#8221;\/&#8221;Provide a Suggestion&#8221; features,\u00a0or using <a href=\"https:\/\/connect.microsoft.com\/\">connect<\/a>, or\u00a0<a href=\"https:\/\/twitter.com\/pvlakshm\">twitter<\/a>.<\/p>\n<p>Looking forward\u00a0to hearing from you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MSTest V2 is now supported on .NET Core 1.0 RTM. API changes in .NET Core 1.0 leading up to RTM (see #7754), were blocking users of the MSTest V2 packages we had released for .NET Core 1.0 RC2. Not any more\u00a0(see #10713), we are pleased to note. This continues to be a preview release, and [&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-21026","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ci","category-devops","category-testing"],"acf":[],"blog_post_summary":"<p>MSTest V2 is now supported on .NET Core 1.0 RTM. API changes in .NET Core 1.0 leading up to RTM (see #7754), were blocking users of the MSTest V2 packages we had released for .NET Core 1.0 RC2. Not any more\u00a0(see #10713), we are pleased to note. This continues to be a preview release, and [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/21026","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=21026"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/21026\/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=21026"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/categories?post=21026"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/tags?post=21026"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}