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.

'dotnet test' in solution folder fails when non-test projects are in the solution

See original GitHub issue

Description

Being able to run ‘dotnet test’ on a solution now is amazing! However, unless that solution contains ONLY test projects it always produces a failure result due to not finding the test sdk. In my experience it is rare for tests to be in a separate solution - they generally don’t exist or are in the same solution as the code they are testing.

It seems logical to me that when running tests on a solution any projects without the test sdk should be ignored. If a project has the test sdk and no tests or is being tested in isolation and does not have the sdk that is likely an error. However if a project does not have the sdk and is being tested as part of a solution that is likely not an error.

Alternatively, if that feels too much like a breaking change then adding an option to filter by patterns on the project name could suffice. Something like dotnet test --projects "*.Tests.*". Since most test projects in my experience have some form of pattern to the name - usually involving the word ‘test’ - this would probably be sufficient for most cases.

Note that the existing --filter <EXPRESSION> switch is insufficient to prevent the exception, presumably because it is processed by the underlying test framework which happens after the missing sdk error is thrown.

Steps to reproduce

‘’’ dotnet new sln -n Solution dotnet new console -n Program dotnet sln Solution.sln add Program/Program.csproj dotnet new mstest -n Tests dotnet sln Solution.sln add Tests/Tests.csproj dotnet test $? ‘’’

Expected behavior

  1. Existing tests run.
  2. Projects with no test sdk reference are ignored.
  3. Return code is zero.

Actual behavior

  1. Exiting tests run.
  2. Projects with no test sdk reference are run as test projects and fail due to an error.
  3. Return code is non-zero. In this case it appears to be 1 but I’m not sure if that is consistent.

Environment data

dotnet --info output: .NET Command Line Tools (2.0.0)

Product Information: Version: 2.0.0 Commit SHA-1 hash: cdcd1928c9

Runtime Environment: OS Name: ubuntu OS Version: 16.04 OS Platform: Linux RID: ubuntu.16.04-x64 Base Path: /usr/share/dotnet/sdk/2.0.0/

Microsoft .NET Core Shared Framework Host

Version : 2.0.0 Build : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d

What is not clear form this environment output is that I am running in bash via the WSL.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:31
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

17reactions
bencyoungcommented, Sep 4, 2017

We have the same issue. A filter or the ability to point it at a sub-directory would be great

dotnet test tests/

or something like that…

0reactions
livarcocccommented, Sep 25, 2017

This issue was moved to Microsoft/vstest#1129

Read more comments on GitHub >

github_iconTop Results From Across the Web

'dotnet test' in solution folder fails when non-test projects ...
It seems logical to me that when running tests on a solution any projects without the test sdk should be ignored. If a...
Read more >
unit testing - dotnet test only test projects on solution
The tests all run and pass except the exit code of the process is 1. This means our CI build fails.
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 >
Setting up code coverage with .Net, xUnit and TeamCity for ...
You can run dotnet test against the solution by omitting the project location and running it in the folder of the solution file....
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