【问题标题】:How to launch a loadtest run from command line in powershell?如何从 powershell 的命令行启动 loadtest 运行?
【发布时间】:2019-08-23 10:22:31
【问题描述】:

我需要能够使用 powershell 启动负载测试运行

目前,使用以下代码

$test = "D:\LPT\abc.loadtest"
$fs = New-Object -ComObject Scripting.FileSystemObject
$f = $fs.GetFile("C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\mstest.exe")
$mstestPath = $f.shortpath   
$arguments = " /testcontainer:" + $test + " /testsettings:D:\LPT\RemoteExecution.testsettings" + " /resultsfile:D:\LPT\TestResults\Results.trx"

Invoke-Expression "$mstestPath $arguments" 

运行后,在 ps 控制台中显示 加载中

D:\LPT\abc.loadtest...
Starting execution...

但在 Visual Studio 中,在测试结果中

以这种方式显示失败。有没有办法使用 powershell + cmd 成功运行 loadtest 行?

使用 VS2017、PS4

【问题讨论】:

  • “.trx”文件只是文本 (xml)。它包含什么?我希望它包含错误消息或类似信息。
  • @AdrianHHH 它说“结果:未执行”而且 xml 文件说“测试运行部署问题:测试容器直接或间接引用的程序集或模块 XXX 'd:\lpt\bin\未找到 release\YYY.dll'。- 但它们可用。
  • 消息说没有找到 YYY.dll 引用的东西,可能包含错误的版本。这里和其他网站上有几个关于 DLL not found 和调试问题的方法的问题。有一个 Microsoft 实用程序可以监视 DLL 加载(我忘记了它的名称,现在无法轻松搜索)。
  • 好的,我再检查一次(我确实遇到过,但发现我的 dll 是完整的,只是我不知道版本可能是个问题)谢谢!
  • 您可能会发现fuslogvw 很有用。

标签: command-line load-testing powershell-4.0 start-process


【解决方案1】:

最初我在某处读到,添加它会有所帮助:

[DeploymentItem("Microsoft.Practices.Prism.dll")]

添加此代码后,代码运行良好,负载测试开始运行,但我仍然不断收到错误

"Test Run deployment issue: The assembly or module log4net directly or indirectly referenced by the test container 'd:\lpt\bin\release\YYY.dll"

我认为问题主要在于参数是如何传递的。一位同事建议 $Arguments 是一个非常敏感的变量要传递,应该仔细编写

然后参数写得更正确了,$Arguments 改成了这个,[DeploymentItem] 被删除了,但是即使没有这个代码 sn-p 下面的代码也可以工作:

使用 Invoke-Expression 启动 LoadTest

$FileSystem = New-Object -ComObject Scripting.FileSystemObject
$File = $FileSystem.GetFile( $MsTestPath )
$MsTestPath = $File.shortpath

$Arguments = "/testcontainer:$TestMethodPath /testsettings:$TS /resultsfile:$Res"            
Invoke-Expression "$MsTestPath $Arguments" 

最后,从头到尾跟踪负载测试的更好方法是使用 Start-Process,因此 下面的代码对我来说完美运行,如果负载测试运行成功,则返回 0 或如果出现任何问题,任何其他值:

使用 Start-Process 启动 LoadTest

$FileSystem = New-Object -ComObject Scripting.FileSystemObject
$File = $FileSystem.GetFile( $MsTestExePath )
$MsTestPath = $File.shortpath

$Arguments = "/testcontainer:$TestMethodPath /testsettings:$TestSettingsPath /resultsfile:$ResultsFile"

$Result = ( Start-Process $MsTestExePath -ArgumentList $Arguments -NoNewWindow -Wait -PassThru )

$Result.ExitCode - provides pass/fail info

【讨论】:

    猜你喜欢
    • 2018-04-11
    • 2015-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-16
    • 1970-01-01
    • 2016-05-18
    • 1970-01-01
    相关资源
    最近更新 更多