首页 文章

从TFS2010 Team Build运行VS2012单元测试

提问于
浏览
4

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

我已经按照以下文章中描述的步骤(我没有找到任何与VS2012和TFS2010直接相关的有用文章)而没有成功:Running VS2010 UnitTests project from TFS2008 Team BuildVS2010, TFS 2008 and Unit Tests

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

安装了

  • 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"

我有2个构建定义,我一直在测试:

  • 在第一个构建定义中,我将"run MS Test"活动的ToolPath留空了,因此它使用"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE"

  • 在另一个构建定义中,我已将"Run MS Test"活动ToolPath参数更改为"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE"

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

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

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并传递相关测试:

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"

我已经做了很多这些构建的运行,但我无法解决问题 . 我还缺少哪些需要在构建服务器或构建定义中完成的工作?

对于失败的实际测试,他们有共同点,他们正在比较列表中的对象,但如上所述,它们在VS2012内运行时通过 .

1 回答

  • 4

    在构建服务器上安装VS2012 Ultimate会导致运行MSTest时无效的交换机错误消失,并且MSTest可以成功运行 . 我之前安装过VS2012 Professional和VS2012 Team Explorer,但这些版本"obviously"(经过大量调试运行后发现!!)不包含所需的MSTest版本 . 有关MSTest命令行选项的信息未提及此(MSDN Command-Line options for publishing tests),仅提及必须安装Team Explorer .

相关问题