如何使用命令行MSTest.exe在我的解决方案中运行所有测试?

Nam*_* VU 42 command-line unit-testing visual-studio-2010

根据MSDN 在这里讨论并在这里讨论,我们可以使用MSTest.exe从命令行运行测试 - 这比在IDE中运行更快,更快(如果你正在研究像我这样的大解决方案,那么速度特别慢).

我的问题是如何在我的解决方案中MSTest.exe运行所有测试?该命令只能选择过滤选项中指定的一个程序集中的测试.考虑到我可以在我的解决方案中使用所有N测试程序集,我只能想到调用此命令N次(!?)此外,运行后的结果是每个程序集的基础知识,因此不容易得到哪些测试失败/通过./test/container

如果您了解更好的方式,请分享!谢谢!

chi*_*ef7 13

我使用testmetadata参数完成了这个并将其指向我的.vsmdi文件.

正如解释在这里.

例如:

mstest /testmetadata:mySolution.vsmdi
Run Code Online (Sandbox Code Playgroud)

但请注意,这testmetadata可能更脆弱(例如,空的测试列表与Ignore属性相结合会导致"指定的强制转换无效").使用包含测试类的所有DLL创建批处理可能是更可靠的替代方法.


Gab*_*ius 9

我需要相同的东西,不想安装任何东西或生成vsmdi文件,所以我想出了这个PowerShell脚本,如下所示.它在文件夹上的一个命令中运行所有测试,它是子文件夹(不是解决方案,但对我来说很好).

随意建议如何使这个脚本更优雅:

$x = ""; dir *\bin\*test*.dll -Recurse | foreach { $x += "/testcontainer:""$_"" " }; iex "mstest $x"
Run Code Online (Sandbox Code Playgroud)

说明:

  • 添加mstest.exevia Environment variables变量的路径PATH,否则只需替换上面脚本中的mstest完整路径PowerShell.

    在此输入图像描述

  • 打开PowerShell,粘贴命令.
  • 修改*\bin\*test*.dll以满足您的需求.在当前脚本中,它将DLLsbin递归方式获取文件夹中的所有内容,包含文件名中的子字符串"test".
  • 运行命令!

  • 我已经修改了一下以便能够更好地找到测试dll:`$ x =""; Get-ChildItem -path.-Recurse -Include*Test.dll | 其中{$ _.FullName -match"bin"} | foreach {$ x + ="/ testcontainer:""$ _"""}; iex"mstest $ x"` (2认同)

Yan*_*vin 5

You might want to have a look at the Gallio.Echo test runner which comes with the Gallio test automation platform. It's a free (OSS) package with many convenient reporting tools and test runners and which supports most the existing test frameworks (MbUnit, NUnit, MSTest, xUnit, etc.)

替代文字

More specifically, Gallio.Echo is a versatile command line test runner. You can specify a list of test assemblies, various filters, and many extra options. Gallio consolidates the test results in a single report (Xml, Html, Zip, etc.)