Skip to content

Command line

Robert Coltheart edited this page May 6, 2019 · 2 revisions

Migrating from project.json to .csproj

  1. Convert your project.json to .csproj with either dotnet migrate or Visual Studio IDE.
  2. Replace the dotnet-test-mspec NuGet package with the Machine.Specifications.Runner.VisualStudio one
  3. Add the Microsoft.NET.Test.Sdk nuget package (required)

Done.

dotnet test (csproj)

The runner lives in the Machine.Specifications.Runner.VisualStudio NuGet package, but note that a reference to the Microsoft.NET.Test.Sdk NuGet package is also required.

Once those two are installed either dotnet test can be used or Visual Studio's Test Explorer.

Multi-targeting is supported for .NET Core and .NET framework 4.6+

Here is an example .csproj targeting both .NET Core 1.1 and .NET Framework 4.6:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>    
    <TargetFrameworks>netcoreapp1.1;net46</TargetFrameworks>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Machine.Specifications" Version="0.11.0" />
    <PackageReference Include="Machine.Specifications.Runner.VisualStudio" Version="2.*" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.*" />
  </ItemGroup>
</Project>

Example output:

C:\code\mspec-test-sample\MSpecSampleSolution\Sample>dotnet test
Build started, please wait...
Build completed.

Test run for C:\code\mspec-test-sample\MSpecSampleSolution\Sample\bin\Debug\netcoreapp1.1\MSpecSample.dll(.NETCoreApp,Version=v1.1)
Microsoft (R) Test Execution Command Line Tool Version 15.0.0.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
Machine Specifications Visual Studio Test Adapter - Executing Specifications.
Machine Specifications Visual Studio Test Adapter - Executing tests in C:\code\mspec-test-sample\MSpecSampleSolution\Sample\bin\Debug\netcoreapp1.1\MSpecSample.dll
Complete on 1 assemblies

Total tests: 1. Passed: 1. Failed: 0. Skipped: 0.
Test Run Successful.
Test execution time: 0.8338 Seconds


Test run for C:\code\mspec-test-sample\MSpecSampleSolution\Sample\bin\Debug\net46\MSpecSample.dll(.NETFramework,Version=v4.6)
Microsoft (R) Test Execution Command Line Tool Version 15.0.0.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
Machine Specifications Visual Studio Test Adapter - Executing Specifications.
Machine Specifications Visual Studio Test Adapter - Executing tests in C:\code\mspec-test-sample\MSpecSampleSolution\Sample\bin\Debug\net46\MSpecSample.dll
Complete on 1 assemblies

Total tests: 1. Passed: 1. Failed: 0. Skipped: 0.
Test Run Successful.
Test execution time: 0.7364 Seconds

Clone this wiki locally