powershell - 如何在 powershell 中使用 VSTEST.CONSOLE.EXE 运行 mstest
问题描述
在阅读并尝试了 Stack overflow 中的可用帖子后,我问了这个问题。
我正在努力在 powershell 中触发 MSTEST
这是我的尝试(显然借助堆栈溢出中可用的帖子)
$testDLL = "C:\Automation\Tests\My.Tests.dll"
$fs = New-Object -ComObject Scripting.FileSystemObject
$f = $fs.GetFile("C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe")
$vstestPath = $f.shortpath
$arguments = " " + $testDLL + ' /TestCaseFilter:"TestCategory=FunctionalTests"'
Write-Host $arguments
& $vstestPath $arguments
控制台输出:
PS C:\Users\myuser\Desktop\Powershell scripts> .\exp5.ps1
C:\Automation\Tests\My.Tests.dll /TestCaseFilter:"TestCategory=FunctionalTests"
Microsoft (R) Test Execution Command Line Tool Version 15.9.1
Copyright (c) Microsoft Corporation. All rights reserved.
VSTEST~1.EXE : The test source file "C:\Automation\Tests\My.Tests.dll /TestCaseFilter:TestCategory=FunctionalTests" provided was not found.
At C:\Users\myuser\Desktop\Powershell scripts\exp5.ps1:7 char:1
+ & $vstestPath $arguments
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (The test source... was not found.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Usage: vstest.console.exe [Arguments] [Options] [[--] <RunSettings arguments>...]]
Description: Runs tests from the specified files.
Arguments:
[TestFileNames]
Run tests from the specified files. Separate multiple test file names
.
.
.
. etc
如果我在正常的 Windows cmd 提示符下运行,则测试运行没有任何问题,但是当我尝试从 powershell 触发时出现上述错误。
有人可以帮助我我的脚本有什么问题吗?
如果我的脚本很复杂或没有意义,请原谅我是 powershell 的新手。我的目标是在 Octopus Deploy 步骤过程中使用上述 powershell 脚本来触发测试。如果有人知道简单或更好的方法,请分享...
谢谢
解决方案
谢谢大家,我已经使用下面的代码来使它工作。
$command = "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe"
$arguments = @('C:\Automation\Tests\My.Tests.dll', '/TestCaseFilter:"TestCategory=FunctionalTests"')
& $command $arguments
@Leee_Dailey - 很抱歉造成混乱。我只是想使用 powershell 命令从 Octopus Deploy (OD) 'Inline Source Code' 触发'Run Script' 模板的测试。在 OD 中使用之前,我已经开始在 PowerShell 中进行试验以使其在本地工作。当我进行搜索时,没有找到直接的答案。我有时间想通了。希望此代码对某人有所帮助。谢谢你。
推荐阅读
- android - “Null”类型不是“String”类型 Flutter 的子类型
- unit-testing - 如何为以下功能编写单元测试用例
- sql - 如何在单引号 oracle sql 中传递变量
- smalltalk - Smalltalk 语言到底是做什么用的?
- npm - 萨斯。通过 @use 使用 glob 模式
- r - 按列名中的模式组合列
- oracle - 使用 ASM 安装后 Oracle 19C 创建数据库失败
- delphi - Delphi 11 Alexandria PaintBox 在 RDP 中闪烁
- python - 或工具制定收入
- python - 如何编写程序以在python中使用for循环以REVERSED顺序打印数字的乘法表?