September 1st, 2016

Announcing MSTest V2 Framework support for .NET Core 1.0 RTM

Pratap Lakshman
Senior Program Manager

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Ā (see #10713), we are pleased to note.

This continues to be a preview release, and comes with following changes:

  1. dotnet-test-mstest is built against .NET Core 1.0 RTM.
  2. Deprecated support for netstandardapp1.5 moniker as announced here.
  3. Fixes for bugs reported by you:
    1. “the test suite returns an exit code of zero even when there are failing tests” (from a comment in our earlier post)
    2. “AssemblyCleanup throwing Exception in ASP.NET Core Project Targeting .NET 4.5.1” (from a comment on the forum)

Now letā€™s go through the same steps as enumerated in our earlier post.

Installing the SDK

Install the Visual Studio official MSI installer from https://www.microsoft.com/net/core.

Creating a class library project

Create a .NET Core Class Library application. Open Visual Studio, and choose File | New | Project:

NewProject

Adding references for MSTest

From nuget.org, install the MSTest.TestFramework package (shown below).

mstestfxNow, install the runnerĀ – look for the updated dotnet-test-mstest package, and install it:

dotnettestmstest

Open the project.json file in the solution. You will already see the packages you just installed mentioned under “dependencies”. Add the “testRunner” property and set that to “mstest”. To make it easier, just replace the content of the project.json file with the following (and note the differences in version numbers from our earlier post):

{
  "version": "1.0.0-*",

  "testRunner": "mstest",

  "dependencies": {
    "dotnet-test-mstest": "1.1.1-preview",
    "MSTest.TestFramework": "1.0.1-preview"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dnxcore50",
        "portable-net45+win8"
      ],
  
      "dependencies": {
        "Microsoft.NETCore.App": {
          "version": "1.0.0",
          "type": "platform"
        }
      }
    }
  }
}

Writing the tests

Visual Studio would have automatically created a file named Class1.cs. Open that file and replace its content with the following:

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace SampleNetCoreUnitTests
{
  [TestClass]
  public class TestClass
  {
    [TestMethod]
    public void TestMethodPassing()
    {
      Assert.IsTrue(true);
    }

    [TestMethod]
    public void TestMethodFailing()
    {
      Assert.IsTrue(false);
    }
  }
}

Testing using the Visual Studio IDE

Open the Test Explorer window (Test | Windows | Test Explorer in Visual Studio). Build the solution, and you should see the tests as follows:

TEDĀ Click on “Run All” to run the tests. TEE

Testing using the .NET CLI

Open a command prompt and navigate to the folder containing the solution, and type dotnet test to execute the tests:dotnettestUse the dotnet test --list command to discover tests. dotnettestlistUse the dotnet test --test to execute specific tests. dotnettesttest

Testing using vstest.console.exe

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: vstest.console.exe project.json /UseVsixExtensions:true vstestconsoleUse vstest.console.exe project.json /UseVsixExtensions:true /logger:trx to generate reports too.vstestconsolelogger

Testing using VSTS

To execute the tests in VSTS CI, check in the code and create a build definition with the following steps:

  1. a Command Line step that invokes theĀ dotnet restore (i.e. “Tool” set to dotnet and “Arguments” set to restore)
  2. a Visual Studio Build step with the default settings
  3. a Visual Studio Test step, with “TestAssembly” set to **project.json, and “Other console options” set to /UseVsixExtensions:true /logger:trx

Queue up the build, and you should see the following:

CI

Build completed, tests run (with one of the tests failing as expected), and test results published!

Feedback

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’s “Report a Problem”/”Provide a Suggestion” features,Ā or using connect, orĀ twitter.

Looking forwardĀ to hearing from you.

Author

Pratap Lakshman
Senior Program Manager

0 comments

Discussion are closed.