{"id":1139,"date":"2017-06-07T19:33:16","date_gmt":"2017-06-07T19:33:16","guid":{"rendered":"http:\/\/tpodolak.com\/blog\/?p=1139"},"modified":"2017-06-09T19:53:38","modified_gmt":"2017-06-09T19:53:38","slug":"dotnet-cli-running-tests-from-multiple-assemblies","status":"publish","type":"post","link":"https:\/\/tpodolak.com\/blog\/2017\/06\/07\/dotnet-cli-running-tests-from-multiple-assemblies\/","title":{"rendered":"<i>Dotnet CLI<\/i> &#8211; running tests from multiple assemblies"},"content":{"rendered":"<p>When you start looking for information how to run unit tests for <i>.NET Core<\/i> based projects in the command line, you will most probably stumble upon <i>dotnet CLI<\/i> and its  <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/core\/tools\/dotnet-test\">dotnet test<\/a> command.<br \/>\nThe command works really great when you have just one test project in your solution, however, it doesn\u2019t allow you to run tests from multiple projects at once. Of course, you can write little <i>PowerShell<\/i> which will run the command in the loop e.g.<\/p>\n<pre lang=\"ps\">\r\nGet-ChildItem | ? { $_.Name.Contains(\".Tests.\") } | ForEach-Object { Push-Location; Set-Location $_.Name; dotnet test; Pop-Location}\r\n<\/pre>\n<p>Unfortunately, in this case, you won&#8217;t get an aggregated summary of tests results, instead, you will get a summary per test project.<br \/>\n<a href=\"\/\/tpodolak.com\/blog\/wp-content\/uploads\/2017\/06\/dotnet-cli-running-tests-from-multiple-assemblies\/dotnettest.png\" rel=\"attachment wp-att-1141\"><img decoding=\"async\" src=\"\/\/tpodolak.com\/blog\/wp-content\/uploads\/2017\/06\/dotnet-cli-running-tests-from-multiple-assemblies\/dotnettest.png\" alt=\"dotnettest\" width=\"900\" class=\"aligncenter size-full wp-image-1141\" srcset=\"https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2017\/06\/dotnet-cli-running-tests-from-multiple-assemblies\/dotnettest.png 1123w, https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2017\/06\/dotnet-cli-running-tests-from-multiple-assemblies\/dotnettest-150x99.png 150w, https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2017\/06\/dotnet-cli-running-tests-from-multiple-assemblies\/dotnettest-300x197.png 300w, https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2017\/06\/dotnet-cli-running-tests-from-multiple-assemblies\/dotnettest-1024x673.png 1024w\" sizes=\"(max-width: 1123px) 100vw, 1123px\" \/><\/a><br \/>\nLuckily <i>dotnet CLI<\/i> have another command for running tests &#8211; namely <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/core\/tools\/dotnet-vstest\">dotnet vstest<\/a>. 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<\/p>\n<pre lang=\"bash\">\r\ndotnet vstest .\\DotnetCLIRunningTestsFromMultipleAssemblies.Tests.Integration\\bin\\Debug\\netcoreapp1.1\\DotnetCLIRunningTestsFromMultipleAssemblies.Tests.Integration.dll .\\DotnetCLIRunningTestsFromMultipleAssemblies.Tests.Unit\\bin\\Debug\\netcoreapp1.1\\DotnetCLIRunningTestsFromMultipleAssemblies.Tests.Unit.dll\r\n<\/pre>\n<p>If you want a bit more flexible solution this simple <i>PowerShell<\/i> script will scan files and based on naming convention retrieve tests assemblies.<\/p>\n<pre lang=\"ps\">\r\ndotnet vstest (Get-ChildItem -recurse -File *.Tests.*dll | ? { $_.FullName -notmatch \"\\\\obj\\\\?\" })\r\n<\/pre>\n<p>One way or another, the <i>dotnet vstest<\/i> command will aggregate all of the test results and will present them as one summary.<br \/>\n<a href=\"\/\/tpodolak.com\/blog\/wp-content\/uploads\/2017\/06\/dotnet-cli-running-tests-from-multiple-assemblies\/dotnetvstest.png\" rel=\"attachment wp-att-1142\"><img decoding=\"async\" src=\"\/\/tpodolak.com\/blog\/wp-content\/uploads\/2017\/06\/dotnet-cli-running-tests-from-multiple-assemblies\/dotnetvstest.png\" alt=\"dotnetvstest\" width=\"941\" class=\"aligncenter size-full wp-image-1142\" srcset=\"https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2017\/06\/dotnet-cli-running-tests-from-multiple-assemblies\/dotnetvstest.png 941w, https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2017\/06\/dotnet-cli-running-tests-from-multiple-assemblies\/dotnetvstest-150x62.png 150w, https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2017\/06\/dotnet-cli-running-tests-from-multiple-assemblies\/dotnetvstest-300x123.png 300w\" sizes=\"(max-width: 941px) 100vw, 941px\" \/><\/a><br \/>\nOne thing to note, <i>dotnet vstest<\/i> won&#8217;t build the solution, you have to run the build manually with <i>dotnet build<\/i> command.<br \/>\nSource code for this post can be found <a href=\"https:\/\/github.com\/tpodolak\/Blog\/tree\/master\/DotnetCLIRunningTestsFromMultipleAssemblies\">here<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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\u2019t allow you to run [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[324],"tags":[325],"class_list":["post-1139","post","type-post","status-publish","format-standard","hentry","category-dotnet-cli","tag-dotnet-cli"],"_links":{"self":[{"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/posts\/1139","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/comments?post=1139"}],"version-history":[{"count":7,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/posts\/1139\/revisions"}],"predecessor-version":[{"id":1363,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/posts\/1139\/revisions\/1363"}],"wp:attachment":[{"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/media?parent=1139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/categories?post=1139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/tags?post=1139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}