从命令行使用自定义程序集基本目录运行MsTest [英] Running MsTest from the command line with a custom assembly base directory

查看:74
本文介绍了从命令行使用自定义程序集基本目录运行MsTest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网络上进行了大量研究,并尝试了一些设置,但无法重现在命令行中在Visual Studio 2012中运行MsTest的行为.

I did quite a lot of research on the web and tried a few settings, but I couldn't reproduce the behavior of running MsTest in Visual Studio 2012 on the command line.

我们的解决方案包含许多构建到解决方案级别的相同bin文件夹的项目(例如C:\ MySolution \ bin)-这是被测代码(CUT).将测试分组到一个单独的项目中,该项目驻留在其自己的解决方案中,并在其自己的bin文件夹中构建(例如C:\ MySolution \ Tests \ bin).确实有很多插件,因此我们希望MsTest在运行将所有内容复制到TestResults文件夹的测试界面时引用CUT bin文件夹.我们在Visual Studio 2012中确实做到了这一点,方法是编辑.testrunco​​nfig并将.\ bin"指定为"要加载的程序集的根文件夹"(在编辑testrunco​​nfig时,在单元测试"选项卡中) .因此,我们可以在VS2012中加载测试解决方案并在其中运行测试,而无需将bin文件夹内容复制到TestResults目录中.

Our solution consists of many projects that build to the same bin folder residing at the solution level (e.g. C:\MySolution\bin) - this is the code-under-test (CUT). The tests are grouped in a separate project that resides in its own solution and builds in its own bin folder (e.g. C:\MySolution\Tests\bin). There are really a lot of plugins thus we want MsTest to reference the CUT bin folder when running the test intead of copying everything to the TestResults folder. We did achieve this in Visual Studio 2012 by editing the .testrunconfig and specifying ".\bin" as "root folder for the assemblies to be loaded" (in tab "Unit Test" when editing the testrunconfig). So we can load the test solution in VS2012 and run the tests there without having to copy the bin folder contents to the TestResults directory.

现在,我想创建一个.bat文件,该文件将以与VS2012中相同的方式运行MsTest,以便我们可以省略为运行测试而启动Visual Studio的操作.我现在正在研究如何在命令行上执行MsTest,但已经感到非常沮丧.这是我尝试过的(在VS命令提示符下在解决方案级别执行的命令):

Now I wanted to create a .bat file that would run MsTest the same way as in VS2012 so that we can omit launching Visual Studio just for running the tests. I'm now working on how to execute MsTest on the command line, but have been quite frustrated. This is what I tried (command executed on the solution level in a VS command prompt):

MsTest/testcontainer:Tests\bin\Tests.dll

MsTest /testcontainer:Tests\bin\Tests.dll

这根本不起作用,甚至找不到Tests.dll需要运行的引用的dll.因此,我重新使用了配置并再次运行它:

This did not work at all, it couldn't even find the referenced dlls that Tests.dll need to run. So I re-used the configuration and ran it again:

MsTest/runco​​nfig:LocalTestRun.testrunco​​nfig/testcontainer:Tests\bin\Tests.dll

MsTest /runconfig:LocalTestRun.testrunconfig /testcontainer:Tests\bin\Tests.dll

仍然没有用.它可以开始测试,但是所有测试都失败了.我收到了很多此类警告

Still it did not work. It could start the tests, but all of them failed. I got a lot of warnings of the kind

警告:测试运行部署问题:未找到由测试容器'C:\ MySolution \ 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.

最后说:

已配置的应用程序基本目录'C:\ MySolution \ TestResults \ User_Machine 2013-07-28 13_16_59 \ Out \ bin'不存在.将使用测试目录.

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.

当我将testrunco​​nfig 中的选项applicationBaseDirectory更改为绝对路径(C:\ MySolution \ bin)时,它起作用了.我仍然收到许多警告,例如:

When I changed the option applicationBaseDirectory in the testrunconfig to an absolute path (C:\MySolution\bin), it worked. Still I get many warnings such as:

警告:测试运行部署问题:未找到由测试容器'C:\ MySolution \ 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.

但是无论如何,指定绝对路径并不是真正可行的解决方案. 如何在命令行中使用其他但相对的程序集基础目录运行MsTest?

But anyway, it's not really a feasible solution to specify an absolute path. How can I run MsTest on the command line with a different, but relative assembly base directory?

我的LocalTestRun.testrunco​​nfig如下:

My LocalTestRun.testrunconfig is as follows:

<?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附带的测试控制台运行程序:

After more searching we changed to use the test console runner that is included with VS2012:

VSTest.Console.exe Tests \ bin \ Tests.dll/Framework:framework40/Settings:LocalTestRun.testrunco​​nfig

VSTest.Console.exe Tests\bin\Tests.dll /Framework:framework40 /Settings:LocalTestRun.testrunconfig

这适用于相对路径为applicationBaseDirectory.

这篇关于从命令行使用自定义程序集基本目录运行MsTest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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