如何在PowerShell脚本中运行所有单元测试用例

时间:2017-02-22 13:31:20

标签: .net asp.net-mvc visual-studio unit-testing powershell

我有一个包含8到9个不同项目的解决方案。其中1个是单元测试项目。一切正常。但我的问题是如何在PowerShell脚本中运行所有UNIT TEST案例?

我在这里得到了一个解决方案How to run ALL tests in my solution using command line MSTest.exe?

你可以看到@Gabrielius提供了1个解决方案。但我总是得到这个错误, mstest:术语“mstest”未被识别为cmdlet的名称,...

注意:我的笔记本电脑,bellow文件夹中已经有MSTest.exe C:\ Program Files(x86)\ Microsoft Visual Studio 14.0 \ Common7 \ IDE

我的UnitTest项目dll在此文件夹中

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

在我的UNIT TEST项目中,我有2个文件夹。 1是ASP.Net MVC控制器的测试用例,第2个用于API。 请帮助我如何从powershell运行所有案例(在不同的文件夹中)。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

我看到这仍然没有答案。当我看到这篇文章时,我一直在寻找类似的解决方案,如果你还有问题,我想我可以帮助你。

我发现当你想通过PowerShell使用exes和其他类似工具时,最简单的方法就是:

# 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 #>

或者,您可以跳过将路径加载到变量中,只需使用完整路径;然而,它确实使得必须不断地输入它会使它变得无比繁重。

关键点是&符号('&amp;'),它是让命令首先工作的关键。