我从XML中调用mstest.exe作为:
<exec executable="${mstest}">
<arg value ="/category:${test}"/>
<arg value ="/TestContainer:${Destination}binDebugUnitTestApp.dll"/>
<arg value="/resultsfile:${Destination}testResults.trx"/>
</exec>
,
<property name ="mstest" location="C:Program Files (x86)Microsoft Visual Studio 11.0Common7IDEmstest.exe"/>
<property name ="test" value="MyTest"/>
当Ant执行命令时,我看到传递了正确的值:
[exec] Current OS is Windows 7
[exec] Executing 'C:Program Files (x86)Microsoft Visual Studio 11.0Common7IDEmstest.exe' with arguments:
[exec] '/category:MyTest'
[exec] '/TestContainer:C:VS2012myAppUnitTestAppbinDebugUnitTestApp.dll'
[exec] '/resultsfile:C:VS2012testResults.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.0Common7IDEmstest.exe' with arguments:
'/category:MyTest'
'/TestContainer:C:VS2012myAppUnitTestAppbinDebugUnitTestApp.dll'
'/resultsfile:C:VS2012testResults.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:VS2012myAppUnitTestAppbinDebugUnitTestApp.dll...
[exec] Starting execution...
[exec] No tests to execute.
如果我不使用/category开关。它工作正常,代码中定义的所有测试都被执行,但我不希望这样。我想做一个具体的测试。
为什么Ant在使用/类别切换时有问题。
从CMD (windows 7)中,如果我将相同的参数传递给正在执行Ant的同一台机器上的mstest.exe,则一切正常。/category:MyTest如预期般被拾取。请帮助。
问题似乎不是ANT。我用了下面的,它工作正常。
<target name="pb">
<exec executable="mstest">
<arg value="/TestContainer:C:VS2012myAppUnitTestAppbinDebugUnitTestApp.dll"/>
<arg value ="/resultsfile:C:VS2012testResults3.trx"/>
<arg value ="/category:MyTest"/>
</exec>
如果有人想知道我是如何解决这个问题的?我创建了一个XML来执行下面这样的命令,然后用msbuild.exe调用它。:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Build">
<Exec Command="CALL mstest /TestContainer:$(Destination)myAppUnitTestmyAppbinDebugUnitTestmyApp.dll /resultsfile:$(Destination)testResults.trx /category:MyTest"/>
</Target>
</Project>