Vstest: What is Microsoft.NET.Test.Sdk and when should we use it in a test project?

Created on 16 Jul 2019  路  6Comments  路  Source: microsoft/vstest

馃憢 This is a general question for the VSTest team.

  • What is the Microsoft.NET.Test.Sdk nuget package / library?
  • When should we install this into a project and use it?

Currently, I have a simple test project and just updated this package to version 16.2.0. Everything is working fine. I then _commented it out_, full clean and rebuild and ran all the tests .. which .. worked?

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>

    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <!--<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />-->
  ... cut ....

I'm using Visual Studio 16.1.6 and the project leverages xUnit as the test framework.

I also tried looking through the docs in this repo but couldn't find anything. The docs were pretty low level / technical .. so I might have skipped over something in an attempt to find some info.

Thanks in advance for any help! 馃帀

question

Most helpful comment

@PureKrome, building the project without the reference should work, but running tests will not work. Interestingly, you said running tests also worked? Try running tests both via VS and via the command dotnet test.

This reference is required for projects targeting dotnet core, it basically carries the test platform reference along with it.

All 6 comments

@PureKrome, building the project without the reference should work, but running tests will not work. Interestingly, you said running tests also worked? Try running tests both via VS and via the command dotnet test.

This reference is required for projects targeting dotnet core, it basically carries the test platform reference along with it.

I am using Microsoft Visual Studio Professional 2019 Version 16.4.2 and have a .NET Core 3.1 NUnit test project. Once I add "Microsoft.NET.Test.Sdk (16.4.0)" as a package reference, all my NUnit tests are discovered by ReSharper's Unit Test Explorer, but not by the build-in VS Test Explorer. I do have the "NUnit3TestAdapter (3.16.0)" installed via NuGet.

Am I missing something?

@svdHero I believe you still need the visual studio nunit 3 test adapter extension https://github.com/nunit/docs/wiki/Visual-Studio-Test-Adapter
to see nunit tests in test explorer. You can download the release package from there or by searching for it in the extensions manager.

Is it a requirement as well that the Microsoft.NET.Test.Sdk package is declared as a primary reference (i.e. have it's own PackageReference entry in the test project)?

In my case I have a test project which uses a testing framework package that includes Microsoft.NET.Test.Sdk as a PackageReference, however the test discovery anyway fails with the following:

System.InvalidOperationException: The following TestContainer was not found 'MyTestAssembly.dll'

@mfogliatto Which test adapter do you use? Microsoft.NET.Test.Sdk is required for .net core targeting projects. It is loaded as Nuget package.

Sorry I didn't see this earlier. We use the MSTest test adapter. I understand that Microsoft.NET.Test.Sdk is required, though test discovery doesn't seem to work if that one is a dependency of a dependency.

The dependency chain looks like follows (all are PackageReferences):

MyTestProject -> TestDependency -> Microsoft.NET.Test.Sdk

Was this page helpful?
0 / 5 - 0 ratings