0
votes

I have a Solution having 8 to 9 different projects. Among them 1 is Unit Test Project. Everything working properly. But my question is how can I run all my UNIT TEST cases in PowerShell script ?

I got a solution here How to run ALL tests in my solution using command line MSTest.exe?

You can see @Gabrielius gave 1 solution. But I'm always getting this error, mstest : The term 'mstest' is not recognized as the name of a cmdlet,...

Note: I have already MSTest.exe in my laptop, bellow folder C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE

My UnitTest project dll is in this folder

E:\Company projects\BWS\Main\BWS.Ins\BWS.Ins.UnitTest\bin\Debug\

In my UNIT TEST project I have 2 folder. 1 is test cases for ASP.Net MVC Controllers and 2nd one is for API. Please any help for how can I run all the cases (which are in different folders) from powershell. Thanks in advance.

1
add MSTest directory to path? - 4c74356b41
Yah! I already added in the Path. I followed all the steps like in that solution. Still getting same error. - Basanta Matia
showing your current script would be helpful in determining and troubleshooint the actual error. Do you run the script from one of the test directories or from the mstest folder? - Ronald Rink 'd-fens'

1 Answers

0
votes

I see that this still doesn't have an answer. I was looking for a similar solution when I saw this post and I think I can help you if you are still having issues.

I have found that when you want to use exes and other similar tools through PowerShell, it is easiest to do the following:

# put the path to the target exe into a variable
$msbuild = "E:\Company projects\BWS\Main\BWS.Ins\BWS.Ins.UnitTest\bin\Debug\"

# Use the '&' to initialize the software/command
& $msbuild <# Command #>

Alternatively, you can skip loading the path into a variable and just simply use the full path; however, it does make it infinitely more taxing to have to type that out constantly.

The key point is the ampersand ('&') which is the key to getting the command to work in the first place.