从TFS2010 Team Build运行VS2012单元测试 [英] Running VS2012 unit tests from TFS2010 Team Build

查看:82
本文介绍了从TFS2010 Team Build运行VS2012单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用.NET 4.5框架的Visual Studio 2012解决方案.我们开发系统的其余部分是TFS2010.最近,我们的某些单元测试仅在构建服务器上失败了.经过几轮调试后,我能够确定测试失败的原因很可能是由于构建服务器上使用的MSTest版本引起的.在本地计算机上从VS2012运行时以及在实际构建服务器上从VS2012运行时,相关测试均通过.

I have a Visual Studio 2012 solution using .NET 4.5 framework. The rest of our development system is TFS2010. Recently some of our unit tests have been failing on the build server only. After going through several rounds of debugging I was able to determine that the cause of the failed tests was most likely due to the version of MSTest being used on the build server. The tests in question pass when run from VS2012 on my local machine and when run from VS2012 on the actual build server.

我没有遵循以下文章中描述的步骤(我没有找到与VS2012和TFS2010直接相关的有用文章),没有成功:

I have followed the steps described in the following articles (I have not found any useful articles directly relevant to VS2012 and TFS2010) without success: Running VS2010 UnitTests project from TFS2008 Team Build and VS2010, TFS 2008 and Unit Tests

在构建服务器上,我现在有以下内容:

On the build server I now have the following:

  • 已安装VS2010 Ultimate SP1
  • 已安装VS2012 Update 3
  • 已安装.NET 4.5框架SDK
  • 更改了"C:\ Program Files(86)\ MSBuild \ Microsoft \ VisualStudio \ TeamBuild \"和"C:\ Program Files \ MSBuild \ Microsoft \ VisualStudio \ TeamBuild \"中的Microsoft.TeamFoundation.Build.targets文件,因此 TestToolsTask构建任务的AssemblyFile属性指向"C:\ Program Files(x86)\ Microsoft Visual Studio 11.0 \ Common7 \ IDE \ PrivateAssemblies \ Microsoft.TeamFoundation.Build.ProcessComponents.dll"
  • VS2010 Ultimate SP1 installed
  • VS2012 Update 3 installed
  • .NET 4.5 framework SDK installed
  • Changed Microsoft.TeamFoundation.Build.targets file in "C:\Program Files (86)\MSBuild\Microsoft\VisualStudio\TeamBuild\" and "C:\Program Files\MSBuild\Microsoft\VisualStudio\TeamBuild\" so the AssemblyFile attribute of the TestToolsTask build task pointed to "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PrivateAssemblies\Microsoft.TeamFoundation.Build.ProcessComponents.dll"

我有2个用于测试的构建定义:

I have 2 build definitions that I have been testing with:

  1. 在第一个构建定义中,我将运行MS测试"活动的工具路径留为空白,因此它随后使用了"C:\ Program Files(x86)\ Microsoft Visual Studio 10.0 \ Common7 \ IDE"
  2. 在另一个内部版本定义中,我已将运行MS测试"活动的ToolPath参数更改为"C:\ Program Files(x86)\ Microsoft Visual Studio 11.0 \ Common7 \ IDE"

两个构建定义似乎都在正确构建,并且正在使用以下MSBuild.exe: C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ MSBuild.exe

Both build definitions appear to be building correctly and are using the following MSBuild.exe: C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe

第一个生成定义运行VS2010版本的MStest,但有任何错误,但大约5个错误. 2030年测试失败.从Visual Studaio 2012中运行时,这些测试不会失败.命令行示例是(删除了实际路径和服务器名称):

The first build defintion runs the VS2010 version of MStest with any errors, but 5 of the approx. 2030 tests fail. These tests do not fail when run from within Visual Studaio 2012. An example of the command line is (actual paths and server names removed):

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe 
/nologo /usestderr /searchpathroot:"d:\Builds\xxxxx\Binaries" 
/resultsfileroot:"d:\Builds\xxxxx\TestResults" /testcontainer:"d:\Builds\xxxxx.dll" 
/testcontainer:"d:\Builds\xxxxx.dll" /publish:"http://xxxxx 
/publishbuild:"vstfs:///Build/Build/xxxxx" /teamproject:"xxxxx" /platform:"x86" /flavor:"Debug"

运行第二个构建定义时,MSTest无法运行以下输出.如果我从构建服务器上的命令行运行此命令,而没有导致无效开关错误的开关,则MSTest将运行并通过有问题的测试:

When running the second build definition MSTest fails to run with the output below. If I run this command from the command line on the build server without the switches that are causing the Invalid switch error then MSTest runs and the tests in question are passed:

The MSTestActivity was invoked without a value for Platform or Flavor. The values x86 and Debug were used.

    C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\MSTest.exe 
    /nologo /usestderr /searchpathroot:"d:\Builds\xxxxx\Binaries" 
    /resultsfileroot:"d:\Builds\xxxxx\TestResults" /testcontainer:"d:\Builds\xxxxx.dll" 
    /publish:"http://xxxxx" /publishbuild:"vstfs:///Build/Build/xxxxx" /teamproject:"xxxxx" 
    /platform:"x86" /flavor:"Debug" 
    Invalid switch "/publish".
    Invalid switch "/publishbuild".
    Invalid switch "/teamproject".
    Invalid switch "/platform".
    Invalid switch "/flavor".
    For switch syntax, type "MSTest /help"

我已经进行了很多次此类构建,但是无法解决问题.我还有其他需要在构建服务器上或在构建定义中完成的事情吗?

I have done a lot of runs of these builds but I hvae not been able to resolve the problem. Is there anything else that I am missing that needs to be done either on the build server or in the build definition?

相对于失败的实际测试,它们的共同点是它们在比较列表中的对象,但是如上所述,当它们在VS2012中运行时可以通过.

In relation to the actual tests that are failing they have in common that they are comparing objects in lists, but as mentioned they pass when run from within VS2012.

推荐答案

在构建服务器上安装VS2012 Ultimate会导致运行MSTest消失时无效的开关错误,并且MSTest可以成功运行.我之前安装了VS2012 Professional和VS2012 Team Explorer,但是这些版本显然"(在大量调试运行后发现!)不包含所需的MSTest版本.有关MSTest命令行选项的信息未提及此内容(用于发布的MSDN命令行选项测试),只提到必须安装Team Explorer.

Installing VS2012 Ultimate on the build server caused the Invalid switch errors when running MSTest to go away and the MSTest could run successfully. I had earlier installed VS2012 Professional and VS2012 Team Explorer, but these editions "obviously" (discovered after lots of debug runs!!) do not contain the required version of MSTest. The information about MSTest command line options does not mention this (MSDN Command-Line options for publishing tests), only mentioning that Team Explorer must be installed.

这篇关于从TFS2010 Team Build运行VS2012单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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