powershell - Powershell 将多个测试 dll 传递给 vstest.console.exe
问题描述
我可以通过传递以空格分隔的文件名来成功运行单元测试。例如
>vstest.console.exe a.dll b.dll
但是当我使用 PS 脚本做类似的事情时
> $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 的新手,我不知道这是否可能。
解决方案
您可以使用数组来帮助您处理命令行实用程序的参数,尤其是当您需要开始指定参数名称时。
$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
块之后添加它们来实现。
$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
如果参数与参数是分开的,这个实用程序似乎不是这种情况,您可以像这样将参数和参数添加在一起。
$dotnetArgs = @()
$dotnetArgs = "new"
$dotnetArgs = "classlib"
$dotnetArgs = $dotnetArgs + "--output" + "TestLib"
$dotnetArgs = $dotnetArgs + "--name" + "TestLib"
$dotnetArgs = $dotnetArgs + "--language" + "C#"
& dotnet $dotnetArgs
推荐阅读
- java - 在 Java 中使用 Unirest 的多部分文件上传请求
- ios - 从控制器外部呈现视图控制器,不传递自引用
- c# - 在 php Web 服务器和 C# 桌面应用程序之间进行通信
- c# - 在 C# 中使用 Ling 解析 xml
- spring - 如何使用 mockito 模拟 Spring RestTemplate?
- cmake - CUDA编译的一个奇怪问题
- css - 选择文本时防止标签变成标签
- height - 颤振垂直分隔线与其父级一样高
- python - 检查列表中数组的任何元素
- c# - JobStorage.Current 属性值尚未初始化。您必须在使用 Hangfire 客户端或服务器 API 之前设置它