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

Jer*_*iah 20 cruisecontrol.net tdd mstest command-prompt

我需要知道如何告诉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>
Run Code Online (Sandbox Code Playgroud)

Bas*_*ink 10

要详细说明VladV的答案并使事情更具体一点,遵循建议的命名约定,运行测试可以通过MSBuild轻松实现自动化.我当前项目的msbuild文件中的以下片段完全符合您的要求.

<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>
Run Code Online (Sandbox Code Playgroud)

此外,将MsBuild与CruiseControl集成是一件小事.

编辑
以下是如何从ccnet.config"调用"msbuild.

首先,如果您尚未使用MSBuild进行构建自动化,请在前面提供的代码段周围添加以下xml:

<Project DefaultTargets="Build"
    xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    ..... <insert snippet here> .....
</Project>
Run Code Online (Sandbox Code Playgroud)

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

<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>
Run Code Online (Sandbox Code Playgroud)


Jos*_*off -1

我只需编写一个按照您想要的方式调用它的目标,然后创建一个批处理文件来调用包含所有要测试的 DLL 的目标。

除非您一直添加测试项目,否则很少需要修改它。