我在网上做了很多研究并尝试了一些设置,但我无法在命令行上重现在 Visual Studio 2012 中运行 MsTest 的行为。
我们的解决方案由许多项目组成,这些项目构建到位于解决方案级别(例如 C:\MySolution\bin)的同一个 bin 文件夹中 - 这是被测代码 (CUT)。测试分组在一个单独的项目中,该项目位于其自己的解决方案中,并在其自己的 bin 文件夹(例如 C:\MySolution\Tests\bin)中构建。确实有很多插件,因此我们希望 MsTest 在运行测试时引用 CUT bin 文件夹,而不是将所有内容复制到 TestResults 文件夹。我们确实在 Visual Studio 2012 中通过编辑 .testrunconfig 并将“.\bin”指定为“要加载的程序集的根文件夹”(在编辑 testrunconfig 时在“单元测试”选项卡中)实现了这一点。因此,我们可以在 VS2012 中加载测试解决方案并在那里运行测试,而无需将 bin 文件夹内容复制到 TestResults 目录。
现在我想创建一个 .bat 文件,它将以与 VS2012 中相同的方式运行 MsTest,以便我们可以省略启动 Visual Studio 仅用于运行测试。我现在正在研究如何在命令行上执行 MsTest,但一直很沮丧。这是我尝试过的(在 VS 命令提示符中的解决方案级别执行的命令):
MsTest /testcontainer:Tests\bin\Tests.dll
这根本不起作用,它甚至找不到 Tests.dll 需要运行的引用 dll。所以我重新使用了配置并再次运行它:
MsTest /runconfig:LocalTestRun.testrunconfig /testcontainer:Tests\bin\Tests.dll
仍然没有奏效。它可以开始测试,但都失败了。我收到了很多此类警告
Warning: Test Run deployment issue: The assembly or module '....' directly or indirectly referenced by the test container 'C:\MySolution\Tests\bin\tests.dll' was not found.
最后它说:
The configured application base directory 'C:\MySolution\TestResults\User_Machine 2013-07-28 13_16_59\Out\bin' does not exist. The test directory will be used instead.
当我更改选项时
applicationBaseDirectory
在 testrunconfig 到绝对路径 (C:\MySolution\bin) 中,它起作用了。我仍然收到许多警告,例如:Warning: Test Run deployment issue: The assembly or module '....' directly or indirectly referenced by the test container 'C:\MySolution\Tests\bin\tests.dll' was not found.
但无论如何,指定绝对路径并不是真正可行的解决方案。 如何使用不同但相对的程序集基目录在命令行上运行 MsTest?
我的 LocalTestRun.testrunconfig 如下:
<?xml version="1.0" encoding="UTF-8"?>
<TestSettings name="Local Test Run" id="...." xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Description>This is a default test run configuration for a local test run.</Description>
<Deployment>
<DeploymentItem filename="Tests\....\Resources\" />
</Deployment>
<Execution hostProcessPlatform="MSIL">
<TestTypeSpecific>
<UnitTestRunConfig testTypeId="....">
<AssemblyResolution applicationBaseDirectory=".\bin">
<TestDirectory useLoadContext="true" />
</AssemblyResolution>
</UnitTestRunConfig>
<WebTestRunConfiguration testTypeId="....">
<Browser name="Internet Explorer 7.0">
<Headers>
<Header name="User-Agent" value="Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)" />
<Header name="Accept" value="*/*" />
<Header name="Accept-Language" value="{{$IEAcceptLanguage}}" />
<Header name="Accept-Encoding" value="GZIP" />
</Headers>
</Browser>
</WebTestRunConfiguration>
</TestTypeSpecific>
<AgentRule name="LocalMachineDefaultRole">
</AgentRule>
</Execution>
</TestSettings>
最佳答案
经过更多搜索,我们改为使用 VS2012 中包含的测试控制台运行程序:
VSTest.Console.exe Tests\bin\Tests.dll /Framework:framework40 /Settings:LocalTestRun.testrunconfig
这适用于作为
applicationBaseDirectory
的相对路径.
关于visual-studio - 使用自定义程序集基目录从命令行运行 MsTest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17907884/