Our Blogs

Working with MSTest Framework support for .NET and ASP.NET Core RC2

June 08, 2016
1640 Views
Microsoft has added MSTest Framework support for .NET Core RC2 and ASP.NET Core RC2, which was released just few weeks back. Although this is a preview release, Microsoft internal product team is looking for feedback from developers. The whole process involves seven steps. Let us look at them in detail.

To work with MSTest Framework, you need to install the Visual Studio official MSI installer. You should then create a .NET Core Class Library application by navigating to Visual Studio and choosing File | New | Project:

The next step is to add references for MSTest by installing the MSTest.TestFramework package from nuget.org. Once you installed the runner, check out the dotnet-test-mstest package, and install it.

You need to open the project.json file in the solution and need to add the "testrunner" property and set it to "mstest". Microsoft has provided the source code on the official blog to simplify things.

By now, Visual Studio would have automatically created Class1.cs file. You need to open it and replace the content with source code as given below

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);
    }
  }
}

You can now run the application. For this purpose, open the Text Explorer window in Visual Studio and build the solution. You can also open a command prompt and navigate to the relevant folder, which contains the solution. You need to provide the following command to run the .NET CLI test runner.

dotnet test

We will continue to post updates regarding .NET Framework. Stay tuned.