简体   繁体   English

在与名称模式匹配的项目中使用mstest运行所有单元测试

[英]Run all unit tests with mstest in projects matching a name pattern

We're running our unit tests with mstest executed by our buildserver. 我们正在使用我们的构建服务器执行的mstest运行我们的单元测试。

We have the convention that each unit test project ends with ".Test" and each integration test project ends with ".IntegrationTest" 我们有一个约定,每个单元测试项目以“.Test”结束,每个集成测试项目以“.IntegrationTest”结束

Is it possible to specify for mstest to run all tests from the projects matching our conventions? 是否可以指定mstest从符合我们约定的项目中运行所有测试?

Right now, we manually list all our test projects like this in one single line, and it's getting really tedious and unmaintainable: 现在,我们在一行中手动列出我们所有的测试项目,并且它变得非常乏味且不可维护:

"C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\Common7\\IDE\\mstest" /testcontainer:D:\\workspace\\unittestjob\\solution\\project1.Test\\bin\\Release\\project1.Test.dll /testcontainer:D:\\workspace\\unittestjob\\solution\\project2.Test\\bin\\Release\\project2.Test.dll /testcontainer:D:\\workspace\\unittestjob\\solution\\project3.Test\\bin\\Release\\project3.Test.dll /testcontainer:D:\\workspace\\unittestjob\\solution\\project4.Test\\bin\\Release\\project4.Test.dll /testcontainer:D:\\workspace\\unittestjob\\solution\\project5.Test\\bin\\Release\\project5.Test.dll /testcontainer:D:\\workspace\\unittestjob\\solution\\project6.Test\\bin\\Release\\project6.Test.dll /testcontainer:D:\\workspace\\unittestjob\\solution\\project7.Test\\bin\\Release\\project7.Test.dll /testcontainer:D:\\workspace\\unittestjob\\solution\\project8.Test\\bin\\Release\\project8.Test.dll “C:\\ Program Files(x86)\\ Microsoft Visual Studio 11.0 \\ Common7 \\ IDE \\ mstest”/testcontainer:D:\\workspace\\unittestjob\\solution\\project1.Test\\bin\\Release\\project1.Test.dll / testcontainer:D :\\ workspace \\ unittestjob \\ solution \\ project2.Test \\ bin \\ Release \\ project2.Test.dll /testcontainer:D:\\workspace\\unittestjob\\solution\\project3.Test\\bin\\Release\\project3.Test.dll / testcontainer:D :\\ workspace \\ unittestjob \\ solution \\ project4.Test \\ bin \\ Release \\ project4.Test.dll /testcontainer:D:\\workspace\\unittestjob\\solution\\project5.Test\\bin\\Release\\project5.Test.dll / testcontainer:D :\\ workspace \\ unittestjob \\ solution \\ project6.Test \\ bin \\ Release \\ project6.Test.dll /testcontainer:D:\\workspace\\unittestjob\\solution\\project7.Test\\bin\\Release\\project7.Test.dll / testcontainer:D :\\工作区\\ unittestjob \\解决方案\\ project8.Test \\ BIN \\发布\\ project8.Test.dll

It can be done with some PowerShell magic: 它可以通过一些PowerShell魔术完成:

$temp = '/testsettings:D:\workspace\unittestjob\solution\local.testsettings /resultsfile:TestResult.trx ' ; #General stuff

Get-ChildItem D:\workspace\unittestjob\solution\ -Filter *.Test.dll -Recurse | ? {$_.fullname -notmatch 'obj'} | % { $temp =  $temp + "/testcontainer:" + $_.FullName+ " "};  #Get all dlls, but exclude the ones from 'obj'. Add /testcontainer to each

$temp  =  '"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\mstest" ' + $temp ; #Prepare the command of MSTest to be ran

iex "& $temp"; #Run MSTest

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM