Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dotnet test only test projects on solution

Using Visual Studio 2017 and Dotnet Core 2.0 SDK I have a solution with several projects. Some of these are test projects and some are source projects.

I can run dotnet test in the root solution direction and it will try to discover tests in all projects of the solution.

However, the source projects do not have tests and so an error is shown for these. The tests all run and pass except the exit code of the process is 1. This means our CI build fails.

Is there any way to have it only run on the test projects of the solution? They are in a test directory, both on file system and a solution directory but I can't find any way to filter them.

I have written a Powershell script to run it for each item in the test folder however our CI server is using Linux and Docker image microsoft/dotnet:2.0-sdk so a Powershell script won't run there.

I could write it in Bash but then it won't run on Windows.

The only other idea I had to make a custom docker image for the builds that had both dotnet and powershell.

like image 549
A Jackson Avatar asked Sep 07 '17 09:09

A Jackson


People also ask

How do you exclude a project from code coverage?

To exclude test code from the code coverage results and only include application code, add the ExcludeFromCodeCoverageAttribute attribute to your test class. To include assemblies that aren't part of your solution, obtain the . pdb files for these assemblies and copy them into the same folder as the assembly .

What can be used unit testing for .NET solutions?

xUnit is a free, open-source, community-focused unit testing tool for . NET. The original inventor of NUnit v2 wrote xUnit.net. xUnit.net is the latest technology for unit testing .

Does dotnet test also build?

The dotnet test command is used to execute unit tests in a given solution. The dotnet test command builds the solution and runs a test host application for each test project in the solution.


2 Answers

It is a known issue without a fix. There are some workarounds listed in the issue: https://github.com/Microsoft/vstest/issues/411

like image 123
omajid Avatar answered Oct 06 '22 11:10

omajid


Good news, as of right now .NET Core 2.2 has this fixed. Commit: https://github.com/Microsoft/vstest/pull/1745

like image 29
mBrice1024 Avatar answered Oct 06 '22 12:10

mBrice1024