0

在阅读并尝试了 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 脚本来触发测试。如果有人知道简单或更好的方法,请分享...

谢谢

4

1 回答 1

5

谢谢大家,我已经使用下面的代码来使它工作。

$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 中进行试验以使其在本地工作。当我进行搜索时,没有找到直接的答案。我有时间想通了。希望此代码对某人有所帮助。谢谢你。

于 2019-05-20T22:10:03.610 回答