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:
- dotnet-test-mstest is built against .NET Core 1.0 RTM.
- Deprecated support for netstandardapp1.5 moniker as announced here.
- Fixes for bugs reported by you:
- “the test suite returns an exit code of zero even when there are failing tests” (from a comment in our earlier post)
- “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:
Adding references for MSTest
From nuget.org, install the MSTest.TestFramework package (shown below).
Now, install the runnerĀ – look for the updated dotnet-test-mstest package, and install it:
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:
Ā Click on “Run All” to run the tests.
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:Use the dotnet test --list
command to discover tests.
Use the dotnet test --test
to execute specific tests.
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
Use vstest.console.exe project.json /UseVsixExtensions:true /logger:trx
to generate reports too.
Testing using VSTS
To execute the tests in VSTS CI, check in the code and create a build definition with the following steps:
- a Command Line step that invokes theĀ
dotnet restore
(i.e. “Tool” set todotnet
and “Arguments” set torestore
) - a Visual Studio Build step with the default settings
- 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:
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.
0 comments