1

I have a test project configured with .NET Standard 1.5

IDE: Visual Studio 2017 Community

I have included xunit and xunit.runner.console but I cannot run the tests. I tried dotnet test on the test project but I get the following error

Could not find testhost.dll for source 'D:\Dev\Visual Studio 2017\CSharpSeven.NewFeatures\CSharpSeven.NewFeatures\CSharpSeven.Tests\bin\Debug\netstandard1.5\CSharpSeven.Tests.dll'. Make sure test project has a nuget reference of package "microsoft.testplatform.testhost".

My .csproj is the following:

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

  <PropertyGroup>
    <TargetFramework>netstandard1.5</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.TestPlatform.TestHost" Version="15.0.0" />
    <PackageReference Include="System.ValueTuple" Version="4.3.0" />
    <PackageReference Include="xunit" Version="2.2.0" />
    <PackageReference Include="xunit.runner.console" Version="2.2.0" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\CSharpSeven\CSharpSeven.csproj" />
  </ItemGroup>

</Project>

I've been struggling for quite sometime to get the tests running, can anyone please help?

Athari
  • 33,702
  • 16
  • 105
  • 146
gdyrrahitis
  • 5,598
  • 3
  • 23
  • 37

2 Answers2

1

Have you tried to do a restore and build first ?

dotnet restore
dotnet build

This should add any missing packages then you may run the tests.

valentinvs
  • 191
  • 1
  • 6
1

Test projects needs to be runable applications. You need to target a specific runtime. For example:

  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
  </PropertyGroup>

See this answer for more information

Can't get XUnit tests to run with .NET Core

Community
  • 1
  • 1
Chris Jansson
  • 401
  • 4
  • 5