Running tests from output directory
See original GitHub issueOn dotnet cli 1.1.0 (928f77c4bc3f49d892459992fb6e1d5542cb5e86), I’m trying to do the following:
dotnet new xunit
dotnet restore
dotnet publish
dotnet test
The sample project builds successfully, and I can run the sample test, with the following project file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
</ItemGroup>
</Project>
Now I want to redirect the output (binaries and obj file) to a custom folder other than the project folder, so I modify the project file to add this:
<RepositoryRoot>..</RepositoryRoot>
<ProjectName>MyProject</ProjectName>
<OutputPath>$(RepositoryRoot)\Binaries\$(Configuration)\$(ProjectName)</OutputPath>
<BaseIntermediateOutputPath>$(RepositoryRoot)\Binaries\Obj\$(ProjectName)\</BaseIntermediateOutputPath>
<IntermediateOutputPath>$(BaseIntermediateOutputPath)$(Configuration)\</IntermediateOutputPath>
And I run the same commands. I see the following directories created:
Binaries\Obj\MyProject
- Contains nuget generated props/targets/json files
Binaries\Obj\MyProject\Debug\netcoreapp1.1\
- Contains obj files and binaries
Binaries\Debug\MyProject\netcoreapp1.1\
- Contains just the binary and its pdb
Binaries\Debug\MyProject\ netcoreapp1.1\publish\
- Contains the binary, its pdb, and dependencies (mainly xunit binaries and testhost)
The problem now is that if I try and run dotnet test
, I get the following error:
Could not find testhost.dll for source MyProject.dll. Make sure test project has a nuget reference of package "microsoft.testplatform.testhost"
I’m guessing it is because the test runner is trying to run the tests from the binary in the output directory, not the publish directory, which doesn’t have the required dependencies.
What is the proper properties to set to redirect tests to be run from there? is there a certain flag missing?
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
If you are trying to run tests out of a published dll, dotnet vstest in the command you should use.
Something like
could you please share your script.