Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run ALL tests in my solution using command line MSTest.exe?

According to MSDN here and discussed here, we can use MSTest.exe to run tests from command line - which is sweet and faster than running within the IDE (especially slow if you are working on a big solution like me).

My question is how can I use MSTest.exe to run all tests in my solution? The command only have the /test option to filter the tests in one assembly specified in /container option. I only can think of calling this command N times given that I can have all the N test assembly in my solution (!?) Moreover, the results after run are per-assembly basics so that it's not easy to get what tests were failed/passed.

If you know a better way, please share! Thank you!

like image 319
Nam G VU Avatar asked Oct 18 '10 17:10

Nam G VU


People also ask

How do I run MSTest from command line?

To access the MSTest tool, add the Visual Studio install directory to the path or open the Visual Studio Group from the Start menu, and then open the Tools section to access the Visual Studio command prompt. Use the command MSTest from the command prompt.

How do I run a MSTest unit test?

To run MSTest unit tests, specify the full path to the MSTest executable (mstest.exe) in the Unit Testing Options dialog. To call this dialog directly from the editor, right-click somewhere in the editor and then click Options.

How run all tests in C#?

To run all the tests in a solution, choose the Run All icon (or press Ctrl + R, V).


2 Answers

I accomplished this using the testmetadata argument and pointing it to my .vsmdi file.

As explained here.

E.g.:

mstest /testmetadata:mySolution.vsmdi 

However note that testmetadata can be more fragile (e.g. empty test lists combined with the Ignore attribute cause "Specified cast is not valid"). Creating a batch with all DLLs containing test classes could be more reliable alternative.

like image 58
chief7 Avatar answered Sep 20 '22 07:09

chief7


I needed the same thing, without wanting to install anything or generate vsmdi files, so I came up with this PowerShell script, below. It runs ALL tests in one command on a folder and it's subfolders (not solution, but fine for me).

Feel free to suggest how to make this script more elegant:

$x = ""; dir *\bin\*test*.dll -Recurse | foreach { $x += "/testcontainer:""$_"" " }; iex "mstest $x" 

Instructions:

  • Add path to mstest.exe via Environment variables variable PATH, otherwise just replace mstest with its full path in the PowerShell script above.

    enter image description here

  • Open PowerShell, paste the command.
  • Modify *\bin\*test*.dll to meet your needs. In current script it will get all DLLs in the bin folder recursively, containing substring "test" in the filename.
  • Run the command!
like image 34
Gabrielius Avatar answered Sep 19 '22 07:09

Gabrielius