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

本文关键字:mstest 运行 单元测试 项目 模式 | 更新日期: 2023-09-27 17:53:41

我们正在运行单元测试,mstest由我们的buildserver执行。

我们有一个约定,每个单元测试项目以"结束。测试",每个集成测试项目以"结束"。IntegrationTest "

是否可以指定mstest从符合约定的项目中运行所有测试?

现在,我们像这样在一行中手动列出所有的测试项目,它变得非常乏味和不可维护:

"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

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

这可以用一些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