首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Powershell将多个测试dll传递给vstest.console.exe

Powershell将多个测试dll传递给vstest.console.exe
EN

Stack Overflow用户
提问于 2021-06-13 07:59:45
回答 1查看 601关注 0票数 0

https://learn.microsoft.com/en-us/visualstudio/test/vstest-console-options?view=vs-2019#general-command-line-options

我可以通过传递以空格分隔的文件名来成功地运行单元测试。例如:

代码语言:javascript
复制
>vstest.console.exe a.dll b.dll 

但是当我使用PS脚本做类似的事情时

代码语言:javascript
复制
> $TestDlls = Get-ChildItem -Path "Folder" -Filter "Test.*.dll" -Recurse -File
> $JoinedPath = $TestDlls -join " " #Try to join the paths by ' ' ??? Is it a wrong command?
> vstest.console.exe $JoinedPath

我有意想不到的事..。

因为$JoinedPath是一个带有引号的字符串,如"a.dll b.dll"

所以vstest.console.exe总是会收到一个"a.dll“(vstest.console.exe "a.dll b.dll")

我不知道如何准确地表达我的问题..。

简而言之,我想使用powershell来模拟命令

vstest.console.exe a.dll b.dll

vstest.console.exe "a.dll b.dll“

我是PowerShell的新手,我不知道这是否可能。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-13 08:23:59

您可以使用数组来帮助您处理命令行实用程序的参数,特别是当您需要开始指定参数名时。

代码语言:javascript
复制
$TestDlls = Get-ChildItem -Path $Folder -Filter "Test.*.dll" -Recurse  # -File is not needed unless you have folders also named Test.*.dll
$VSTestArgs = @()
foreach ($TestDll in $TestDlls) {
    $VSTestArgs = $VSTestArgs + $TestDll.FullName
}
& vstest.console.exe $VSTestArgs  # & is the call operator.

呼叫操作员

如果必须添加其他参数,则可以在foreach块之后添加它们。

代码语言:javascript
复制
$TestDlls = Get-ChildItem -Path $Folder -Filter "Test.*.dll" -Recurse  # -File is not needed unless you have folders also named Test.*.dll
$VSTestArgs = @()
foreach ($TestDll in $TestDlls) {
    $VSTestArgs = $VSTestArgs + $TestDll.FullName
}
$VSTestArgs = $VSTestArgs + "/Settings:local.runsettings"
$VSTestArgs = $VSTestArgs + "/Tests:TestMethod1,testMethod2"
$VSTestArgs = $VSTestArgs + "/EnableCodeCoverage"
& vstest.console.exe $VSTestArgs

如果参数与参数是分开的,而这个实用程序似乎并非如此,那么您可以像这样将参数和参数相加在一起。

代码语言:javascript
复制
$dotnetArgs = @()
$dotnetArgs = "new"
$dotnetArgs = "classlib"
$dotnetArgs = $dotnetArgs + "--output" + "TestLib"
$dotnetArgs = $dotnetArgs + "--name" + "TestLib"
$dotnetArgs = $dotnetArgs + "--language" + "C#"
& dotnet $dotnetArgs
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67956083

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档