如何告诉MSTEST在解决方案中运行所有测试项目? [英] How do I tell MSTEST to run all test projects in a Solution?

查看:179
本文介绍了如何告诉MSTEST在解决方案中运行所有测试项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道如何告诉MSTEST在解决方案文件中运行所有测试项目.这需要从命令行完成.现在,我必须将特定的项目文件传递给它,我正在尝试使其从SOLUTION文件运行.

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.

我希望这是可能的,因为在Visual Studio中,按Ctrl + R,A可以在当前打开的解决方案中运行所有测试.

I'm hoping this is possible, because in Visual Studio, hitting Ctrl+R, A, runs ALL tests in the currently opened solution.

按照我解释帮助文件的方式,您必须专门传递每个DLL.

The way I've interpretted the help files, you have to pass in each DLL specifically.

我想从我的CruiseControl.NET服务器的命令行中运行它,所以我可以编写其他实用程序来实现此目的.如果有其他方法可以通过其他方法来实现此目的,请告诉我.

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.

我如何告诉MSTEST为解决方案运行所有测试项目?

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>

推荐答案

要详细说明VladV的答案并使事情更具体一点,可以按照

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.

<Target Name="GetTestAssemblies">
    <CreateItem
        Include="$(WorkingDir)\unittest\**\bin\$(Configuration)\**\*Test*.dll"
        AdditionalMetadata="TestContainerPrefix=/testcontainer:">
       <Output
           TaskParameter="Include"
           ItemName="TestAssemblies"/>
    </CreateItem>
</Target>
<!-- Unit Test -->
<Target Name="Test" DependsOnTargets="GetTestAssemblies">
    <Message Text="Normal Test"/>
<Exec 
    WorkingDirectory="$(WorkingDir)\unittest"
    Command="MsTest.exe @(TestAssemblies->'%(TestContainerPrefix)%(FullPath)',' ') /noisolation /resultsfile:$(MSTestResultsFile)"/>
    <Message Text="Normal Test Done"/>
</Target>

进一步将MsBuild与CruiseControl集成在一起是小菜一碟.

Furthermore integrating MsBuild with CruiseControl is a piece of cake.

修改
这是从ccnet.config中调用" msbuild的方法.

Edit
Here's how you can 'call' msbuild from your ccnet.config.

首先,如果您尚未使用 MSBuild 自动化在前面介绍的代码段周围添加以下xml:

First if you do not already use MSBuild for your build automation add the following xml around the snippet presented earlier:

<Project DefaultTargets="Build"
    xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    ..... <insert snippet here> .....
</Project>

将其保存在例如源树中解决方案旁边的RunTests.proj.现在,您可以将上面的ccnet.config位修改为以下内容:

Save this in e.g. RunTests.proj next to your solution in your source tree. Now you can modify the bit of ccnet.config above to the following:

<msbuild>
  <executable>C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe</executable>
  <workingDirectory>C:\projects\mysolution\</workingDirectory>
  <baseDirectory>C:\projects\mysolution\</baseDirectory>  
  <projectFile>RunTests.proj</projectFile>
  <targets>Test</targets>
  <timeout>600</timeout>
  <logger>C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll</logger>
</msbuild>

这篇关于如何告诉MSTEST在解决方案中运行所有测试项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆