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.

Question: why not add `IsTestProject` to project property when create a test project?

See original GitHub issue

As the title, why not add <IsTestProject>true</IsTestProject> to the test project, it seemed the ci platform like azure devops and travis will not run the test when no <IsTestProject>true</IsTestProject> specified

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:25 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
giggiocommented, Aug 3, 2022

I have found the solution for this problem. This is my scenario:

  1. I’m running in a CI machine
  2. It does not have a cache for packages, so there is no ~/.nuget directory
  3. I have all the binaries available, restored from an artifact

If I run this, it fails:

dotnet test --configuration Release --list-tests --nologo --no-build

If I dotnet restore, then run it, it works.

I with I did not have to restore again. Adding <IsTestProject>true</IsTestProject> works, too.

Not having the package at ~\.nuget\packages\microsoft.net.test.sdk\17.2.0\build\netcoreapp2.1\ is making it not find the .targets and .props files, I guess.

1reaction
mjolkacommented, May 15, 2022

I ran into this problem when building the project as root and trying to run the tests as a non-root user.

I believe the problem comes down to Microsoft.NET.Test.Sdk.props being unreadable by the user trying to run the tests, as it’s under /root.

A workaround is setting NUGET_PACKAGES to /tmp/.nuget/packages.

To see the issue:

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
RUN dotnet new xunit --name TestProject --output . --no-restore
ARG NUGET_PACKAGES
ENV NUGET_PACKAGES=${NUGET_PACKAGES}
RUN dotnet restore TestProject.csproj
RUN dotnet build TestProject.csproj --configuration Release --output /app/build --no-restore

Running the tests as root works:

$ docker build -t issue-3790 --quiet .
sha256:02b63fadacaf72fd215a105dcdf366d36c58eef08f0e9618a732cede18df7d6d
$ docker run --rm issue-3790 dotnet test --no-build --output /app/build
Test run for /app/build/TestProject.dll (.NETCoreApp,Version=v6.0)
Microsoft (R) Test Execution Command Line Tool Version 17.2.0 (x64)
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.

Passed!  - Failed:     0, Passed:     1, Skipped:     0, Total:     1, Duration: < 1 ms - /app/build/TestProject.dll (net6.0)
$ 

Running the tests as a non-root user gives no output:

$ docker run --rm --user 1000 -e DOTNET_CLI_HOME=/tmp issue-3790 dotnet test --no-build --output /app/build
$ 

But if you set NUGET_PACKAGES=/tmp/.nuget/packages, you get this:

$ docker build -t issue-3790 --quiet --build-arg NUGET_PACKAGES=/tmp/.nuget/packages . 
sha256:655c8e20298adcf7fa8f187c4c66f2189d1c5fab7e2aa356b09c60d8f86521c2
$ docker run --rm --user 1000 -e DOTNET_CLI_HOME=/tmp issue-3790 dotnet test --no-build --output /app/build
Test run for /app/build/TestProject.dll (.NETCoreApp,Version=v6.0)
Microsoft (R) Test Execution Command Line Tool Version 17.2.0 (x64)
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.

Passed!  - Failed:     0, Passed:     1, Skipped:     0, Total:     1, Duration: < 1 ms - /app/build/TestProject.dll (net6.0)
$ 
Read more comments on GitHub >

github_iconTop Results From Across the Web

Preventing a project from being discovered as a test project
This is the error that I was running into that is fixed by adding the above ... Test discovery or execution might not...
Read more >
Make dotnet test work on solution files - Martin Ullrich
The dotnet cli's test command can be run on any msbuild project or solution, yet it fails when run on non-test projects and...
Read more >
dotnet test command - .NET CLI
The dotnet test command is used to execute unit tests in a given project.
Read more >
Test Explorer fails to execute any tests under netcore3.1 ...
Trying the same project (minus the net5.0 target) in Visual Studio 16.7.x, I can successfully execute tests for both net461 and netcoreapp3.1 with...
Read more >
Moving to SDK-Style projects and package references in ...
The Math class is has only two methods, Add, and AsJson, the latter just returns a json representation of the last result of...
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