question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Running tests from output directory

See original GitHub issue

On 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:

  1. Binaries\Obj\MyProject
  • Contains nuget generated props/targets/json files
  1. Binaries\Obj\MyProject\Debug\netcoreapp1.1\
  • Contains obj files and binaries
  1. Binaries\Debug\MyProject\netcoreapp1.1\
  • Contains just the binary and its pdb
  1. 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:closed
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

10reactions
livarcocccommented, Mar 29, 2017

If you are trying to run tests out of a published dll, dotnet vstest in the command you should use.

Something like

dotnet publish -o outputdir
dotnet vstest outputdir/your.dll
0reactions
brah-mcdudecommented, Jun 16, 2021

#codito @livarcocc thanks for the info. Will follow the issue mentioned above. In the meantime, I hand authored a script that copies the binaries appropriately.

could you please share your script.

Read more comments on GitHub >

github_iconTop Results From Across the Web

.net - How can I run tests from a folder other than the ...
I have multiple C# projects in my solution. Each project is built to bin\Debug\. From there, the output from all the projects is...
Read more >
Tests wont run from build output folder when using ...
It keeps wanting to run the test from the test results folder instead of the build output folder. I don't know why this...
Read more >
dotnet test command - .NET CLI
dotnet test always runs tests from the output directory. You can use AppDomain.BaseDirectory to consume test assets in the output directory.
Read more >
Unit Test execution and data folders - Build/Test Issues
When the tests are run, NCrunch specifically sets the current directory to be the build output directory in the workspace.
Read more >
How to set the output directory of TestNG BeforeTest
To set up the output directory at @BeforeTest, ITestContext dependency can be used. It creates the folder at a given path or override...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found