Dotnet CLI – running tests from multiple assemblies

When you start looking for information how to run unit tests for .NET Core based projects in the command line, you will most probably stumble upon dotnet CLI and its dotnet test command.
The command works really great when you have just one test project in your solution, however, it doesn’t allow you to run tests from multiple projects at once. Of course, you can write little PowerShell which will run the command in the loop e.g.

Unfortunately, in this case, you won’t get an aggregated summary of tests results, instead, you will get a summary per test project.
Luckily dotnet CLI have another command for running tests – namely dotnet vstest. In this case, we do not operate on projects but we provide a location for assemblies with tests. So if you, for instance, would like to run unit and integration tests at once, you can write something like that

If you want a bit more flexible solution this simple PowerShell script will scan files and based on naming convention retrieve tests assemblies.

One way or another, the dotnet vstest command will aggregate all of the test results and will present them as one summary.
One thing to note, dotnet vstest won’t build the solution, you have to run the build manually with dotnet build command.
Source code for this post can be found here

Dotnet CLI – running tests from multiple assemblies

2 thoughts on “Dotnet CLI – running tests from multiple assemblies

  1. Priya Kannan says: 

    This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.

Comments are closed.