如何告诉 MSTEST 运行解决方案中的所有测试项目?
我需要知道如何告诉 MSTEST 运行解决方案文件中的所有测试项目。 这需要从命令行完成。 现在我必须向它传递一个特定的项目文件,我试图让它从解决方案文件运行。
我希望这是可能的,因为在 Visual Studio 中,按 Ctrl+R、A 可以运行当前打开的解决方案中的所有测试。
按照我解释帮助文件的方式,您必须专门传入每个 DLL。
我想从 CruiseControl.NET 服务器的命令行运行它,这样我就可以编写其他实用程序来实现这一点。 如果有一种奇怪的方法可以通过其他方法实现这一点,请告诉我。
如何告诉 MSTEST 运行解决方案的所有测试项目?
<exec>
<!--MSTEST seems to want me to specify the projects to test -->
<!--I should be able to tell it a SOLUTION to test!-->
<executable>mstest.exe</executable>
<baseDirectory>C:\projects\mysolution\</baseDirectory>
<buildArgs>/testcontainer:testproject1\bin\release\TestProject1.dll
/runconfig:localtestrun.Testrunconfig
/resultsfile:C:\Results\testproject1.results.trx</buildArgs>
<buildTimeoutSeconds>600</buildTimeoutSeconds>
</exec>
I need to know how to tell MSTEST to run all test projects in a solution file. This needs to be done from the command line. Right now I have to pass it a specific project file, I'm trying to get it to run from a SOLUTION file.
I'm hoping this is possible, because in Visual Studio, hitting Ctrl+R, A, runs ALL tests in the currently opened solution.
The way I've interpretted the help files, you have to pass in each DLL specifically.
I want to run this from the command line from my CruiseControl.NET server, so I can write other utilities to make this happen. If there is a wierd way of getting this to happen through some OTHER method, let me know.
How do I tell MSTEST to run all test projects for a solution?
<exec>
<!--MSTEST seems to want me to specify the projects to test -->
<!--I should be able to tell it a SOLUTION to test!-->
<executable>mstest.exe</executable>
<baseDirectory>C:\projects\mysolution\</baseDirectory>
<buildArgs>/testcontainer:testproject1\bin\release\TestProject1.dll
/runconfig:localtestrun.Testrunconfig
/resultsfile:C:\Results\testproject1.results.trx</buildArgs>
<buildTimeoutSeconds>600</buildTimeoutSeconds>
</exec>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
为了详细说明 VladV 的答案并使事情更加具体,按照建议的命名约定,可以使用 MSBuild. 我当前项目的 msbuild 文件中的以下代码片段完全符合您的要求。
此外,将 MsBuild 与 CruiseControl 集成也是小菜一碟。
编辑
以下是如何从 ccnet.config 中“调用”msbuild。
首先,如果您尚未使用 MSBuild 进行构建自动化,请添加将
其保存在源代码树中解决方案旁边的例如
RunTests.proj
中。 现在您可以将上面的 ccnet.config 部分修改为以下内容:To elaborate on VladV's answer and make things a bit more concrete, following the suggested naming convention running your tests can be easily be automated with MSBuild. The following snippet from the msbuild file of my current project does exactly what you asked.
Furthermore integrating MsBuild with CruiseControl is a piece of cake.
Edit
Here's how you can 'call' msbuild from your ccnet.config.
First if you do not already use MSBuild for your build automation add the following xml around the snippet presented earlier:
Save this in e.g.
RunTests.proj
next to your solution in your source tree. Now you can modify the bit ofccnet.config
above to the following:这是一个旧线程,但我一直在努力解决同样的问题,我意识到你真的可以在整个解决方案中的每个 dll 上运行 MSTest,并且它不会真正引起任何问题。 MSTest 正在用 [TestMethod] 属性标记的程序集中查找方法,而不是“测试”程序集的程序集不会有任何用该属性修饰的方法。 所以你会得到一个“没有要执行的测试”。 回复消息并没有造成任何伤害。
例如,在 NAnt 中,您可以这样做:
它将运行解决方案中每个 bin\Release 文件夹中每个 dll 中的所有测试方法。 那些不是测试 dll 的文件将返回“没有要执行的测试”。 那些有测试的将运行测试。 我唯一还没有弄清楚的部分是(在 NAnt 中)命令第一次返回非零值时执行会停止。 因此,如果任何单元测试失败,它不会继续在后续程序集中执行任何测试。 这不太好,但如果所有测试都通过,那么它们都会运行。
This is an old thread, but I have been struggling with the same issue and I realized that you can really just run MSTest on every dll in the whole solution and it doesn't really cause any problems. MSTest is looking for methods in the assemblies marked with the [TestMethod] attribute, and assemblies that aren't "test" assemblies just won't have any methods decorated with that attribute. So you get a "No tests to execute." message back and no harm done.
So for example in NAnt you can do this:
and it will run all the test methods in every dll in every bin\Release folder in the solution. Those which are not test dlls will return a "No tests to execute." and those that have tests will have the tests run. The only part I haven't figured out yet is that (in NAnt) execution stops the first time a command returns a non-zero value. So if any unit tests fail it doesn't keep going to execute any tests in subsequent assemblies. That is not great, but if all the tests pass, then they will all run.
我最近刚刚解决这个问题。 这是我的建议:使用 mstest 的 testmetadata + testlist 选项
mstest /testmetadata:....vsmdi /testlist:
I just resolve this problem recently. Here is my proposal: Use testmetadata + testlist option of mstest
mstest /testmetadata:....vsmdi /testlist:<name>
我知道这个帖子已经很老了,但它在谷歌上的排名仍然很高,所以我想我可以帮助一两个。
无论如何,因为对此没有令人满意的解决方案。
我为此编写了一个 msbuild 任务。
详细信息可以在这里找到:
http://imistaken.blogspot.com/2010/ 08/running-all-tests-in-solution.html
i know this thread is quite Old, but its still high on Google so i thought i might help one or two.
Anyway, since there is no satisfactory solution for this.
I've written an msbuild task for this.
details can be found here:
http://imistaken.blogspot.com/2010/08/running-all-tests-in-solution.html
您可以对测试项目的命名和位置强制执行一些约定,然后您可以在解决方案位置下方的所有 *Test.dll 上运行 MSTest。
据我所知,没有办法仅根据解决方案文件来区分测试项目和“正常”DLL 项目。 因此,另一种方法是分析项目文件和/或 .vsmdi 文件以查找测试项目,但这可能相当棘手。
You could enforce some convention on the naming and location of test projects, then you could run MSTest on, say, all *Test.dll below the location of your solution.
As far as I know, there is no way to tell a test project from a 'normal' DLL project based soleley on a solution file. So, an alternative could be to analyze the project files and/or .vsmdi files to find the test projects, but that could be rather tricky.
我不直接知道,但这就是 VSMDI [fx:spits in acorner] 可以提供帮助的地方。 在您的解决方案中,将所有测试添加到 VSMDI。 然后使用 /testmetadata 将 VSMDI 传递给 mstest。
不过,我建议您遵循上述约定。 并使用命名约定并使用命令脚本中的 for 循环将其从 SLN 文件中转储出来
I don't know directly but this is where VSMDI [fx:spits in a corner] can help. In your solution add all the tests to the VSMDI. And then pass the VSMDI to mstest using /testmetadata.
However I would suggest that you follow the conventions above. And use a naming convention and dump that out from the SLN file using say a for loop in the command script
我只需编写一个按照您想要的方式调用它的目标,然后创建一个批处理文件来调用包含所有要测试的 DLL 的目标。
除非您一直添加测试项目,否则您很少需要修改它。
I would just write a target that calls it the way you want, then whip up a batch file that calls the target that contains all the DLL's to be tested.
Unless you're adding test projects all the time, you'll very rarely need to modify it.
为什么不让 msbuild 将所有测试程序集输出到一个文件夹中。
尝试在 msbuild 中设置 OutputPath、OutputDir、OutDir 属性来完成此操作。
然后让 mstest 针对该文件夹中的所有程序集执行。
Why not just have msbuild output all the test assemblies to a folder.
Try setting OutputPath,OutputDir,OutDir properties in msbuild to accomplish this.
then have mstest execute against all assemblies in that folder.