在ANT xml中使用mstest.exe时,/ category开关无法正常工作

时间:2015-10-01 08:11:55

标签: xml ant mstest categories

我从XML调用mstest.exe:

<exec executable="${mstest}">
    <arg value ="/category:${test}"/>
    <arg value ="/TestContainer:${Destination}\bin\Debug\UnitTestApp.dll"/> 
    <arg value="/resultsfile:${Destination}\testResults.trx"/>
</exec>

其中

<property name ="mstest" location="C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\mstest.exe"/>
<property name ="test" value="MyTest"/>

当Ant执行命令时,我看到传递了正确的值:

   [exec] Current OS is Windows 7
   [exec] Executing 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\mstest.exe' with arguments:
   [exec] '/category:MyTest'
   [exec] '/TestContainer:C:\VS2012\myApp\UnitTestApp\bin\Debug\UnitTestApp.dll'
   [exec] '/resultsfile:C:\VS2012\testResults.trx'
   [exec] 
   [exec] The ' characters around the executable and arguments are
   [exec] not part of the command.
Execute:Java13CommandLauncher: Executing 'C:\Program Files(x86)\Microsoft Visual Studio 11.0\Common7\IDE\mstest.exe' with arguments:
'/category:MyTest'
'/TestContainer:C:\VS2012\myApp\UnitTestApp\bin\Debug\UnitTestApp.dll'
'/resultsfile:C:\VS2012\testResults.trx'

The ' characters around the executable and arguments are
not part of the command.

但是当测试执行时,我看到了消息:

[exec] Microsoft (R) Test Execution Command Line Tool Version 11.0.50727.1
[exec] Copyright (c) Microsoft Corporation. All rights reserved.
[exec]     
[exec] Loading C:\VS2012\myApp\UnitTestApp\bin\Debug\UnitTestApp.dll...
[exec] Starting execution...
[exec] No tests to execute.

如果我不使用/ category开关。它工作正常,代码中定义的所有测试都会执行,但我不希望这样。我想运行一个特定的测试。

为什么Ant在使用/ category开关时遇到问题。

从CMD(Windows 7),如果我在执行Ant的同一台机器上将相同的参数传递给mstest.exe,一切正常。 / category:MyTest按预期被提升。请帮忙。

2 个答案:

答案 0 :(得分:0)

问题似乎不是ANT。我使用以下内容,它可以正常工作。

using (var client = new WebClient())
{
      string uri = "http://chronicletwilio.azurewebsites.net/res/12345.png";
      byte[] data = client.DownloadData(uri);
      string contentType = client.ResponseHeaders["content-type"];
      // contentType is 'image/png'
}

答案 1 :(得分:0)

如果有人想知道我是如何解决这个问题的? 我创建了一个XML来执行如下所示的命令,然后使用msbuild.exe调用它。 :

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="Build">
  <Exec Command="CALL mstest /TestContainer:$(Destination)\myApp\UnitTestmyApp\bin\Debug\UnitTestmyApp.dll /resultsfile:$(Destination)\testResults.trx /category:MyTest"/>
  </Target>
</Project>