dotcover.exe中的NUnit访问被拒绝错误

问题描述 投票:0回答:1

我正在为dotCover编写PowerShell脚本,以使用NUnit-console.exe生成覆盖率报告运行脚本后-

$testRunner="C:\Program Files (x86)\NUnit 2.6.2\bin\nunit-console.exe"
$testContainers="path/to/test1.dll","path/to/test2.dll"
$dotcover="D:\JetBrains.dotCover.CommandLineTools.2019.3.4\dotcover.exe"

foreach($test in $testContainers)
{
$testAssembly=Get-Item $test
$testName= $testAssembly.BaseName
&$dotcover cover /TargetExecutable=$testRunner /TargetArguments=$test /Output="D:\JetBrains.dotCover.CommandLineTools.2019.3.4\TestReport\$testName.dcvr"
}

$testReports=$testContainer|%{
$testAssembly=Get-Item $test
$name= $testAssembly.BaseName
return ("D:\JetBrains.dotCover.CommandLineTools.2019.3.4\TestReport\{0}.dcvr" -f $name)
}

$testReportArguments=[String]::Join(";",$testReports)
&$dotcover merge /Source="$testReportArguments" /Output="D:\JetBrains.dotCover.CommandLineTools.2019.3.4\TestReport\mergedReport.dcvr" /ReportType="DCVR"


&$dotcover report /Source="D:\JetBrains.dotCover.CommandLineTools.2019.3.4\TestReport\mergedReport.dcvr" /Output="D:\JetBrains.dotCover.CommandLineTools.2019.3.4\TestReport\mergedReport.html" /ReportType="HTML"

出现以下错误-

Unhandled Exception:
System.UnauthorizedAccessException: Access to the path 'C:\Program Files (x86)\NUnit 2.6.2\bin\TestResult.xml' is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String 
msgPath, Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
   at System.IO.StreamWriter..ctor(String path)
   at NUnit.ConsoleRunner.ConsoleUi.Execute(ConsoleOptions options)
   at NUnit.ConsoleRunner.Runner.Main(String[] args)

即使TestResult.xml文件不在该位置,也位于-

C:\Program Files (x86)\NUnit 2.6.2\doc\files\TestResult.xml

但是我复制了该文件并将其放入bin文件夹,但错误仍然存​​在。这个问题与权利有关吗?有什么办法摆脱这个?在此之后,执行既不会失败,也不会失败。

powershell nunit-console dotcover
1个回答
0
投票

老实说,我建议将这些“ exe”路径添加到Windows系统路径或PowerShell环境路径。但是,按照我在评论中包括的链接,获取您到目前为止显示的内容:

PowerShell: Running Executables

  1. 呼叫运营商&

为什么:

[用于将字符串视为SINGLE命令。对处理有用空格。在PowerShell V2.0中,如果您正在运行7z.exe(7-Zip.exe)或另一个以数字开头的命令,您必须使用命令调用运算符&。 PowerShell V3.0解析器现在就做更聪明,在这种情况下,您就不再需要&。

详细信息:

运行命令,脚本或脚本块。呼叫操作员,也称为作为“调用运算符”,您可以运行存储在变量并由字符串表示。因为呼叫接线员会无法解析命令,无法解释命令参数

# Example:
& 'C:\Program Files\Windows Media Player\wmplayer.exe' "c:\videos\my home video.avi"  /fullscreen

当外部命令具有很多参数时,事情会变得棘手或参数或路径中有空格!

带空格,您必须嵌套引号,而结果却不是总是清楚!

在这种情况下,最好像这样将所有内容分开:

$CMD  =  'SuperApp.exe'
$arg1 =  'filename1'
$arg2 =  '-someswitch'
$arg3 =  'C:\documents and settings\user\desktop\some other file.txt'
$arg4 =  '-yetanotherswitch'
& $CMD $arg1 $arg2 $arg3 $arg4

# or same like that:
$AllArgs =  @('filename1',  '-someswitch', 'C:\documents and settings\user\desktop\some other file.txt', '-yetanotherswitch')
& 'SuperApp.exe' $AllArgs

因此,此更改将使您继续前进。同样,我不使用该工具,因此无法进行验证,因此您可能需要进行调整。

另请参见:

Implementing DotCover from Powershell

$testRunner     = 'C:\Program Files (x86)\NUnit 2.6.2\bin\nunit-console.exe'
$testContainers = 'path/to/test1.dll','path/to/test2.dll'
$dotcover       = 'D:\JetBrains.dotCover.CommandLineTools.2019.3.4\dotcover.exe'

foreach($test in $testContainers)
{
    $testAssembly = Get-Item $test
    $testName     = $testAssembly.BaseName

    $arg1 = 'cover'
    $arg2 = '/TargetExecutable = $testRunner'
    $arg3 = '/TargetArguments = $test'
    $arg4 = '/TargetExecutable = $testRunner'
    $arg5 = '/Output = "D:\JetBrains.dotCover.CommandLineTools.2019.3.4\TestReport\$testName.dcvr"'
    & $dotcover $arg1 $arg2 $arg3 $arg4 $arg5
}

$testReports  = $testContainer | 
%{
    $testAssembly = Get-Item $test
    $name = $testAssembly.BaseName
    return ('D:\JetBrains.dotCover.CommandLineTools.2019.3.4\TestReport\{0}.dcvr' -f $name)
}

$testReportArguments = [String]::Join(';',$testReports)

$arg1 = 'merge'
$arg2 = '/Source = $testReportArguments'
$arg3 = '/Output = "D:\JetBrains.dotCover.CommandLineTools.2019.3.4\TestReport\mergedReport.dcvr"'
$arg4 = '/ReportType = "DCVR"'
& $dotcover $arg1 $arg2 $arg3 $arg4


$arg1 = 'report'
$arg2 = '/Source = "D:\JetBrains.dotCover.CommandLineTools.2019.3.4\TestReport\mergedReport.dcvr"'
$arg3 = '/Output = "D:\JetBrains.dotCover.CommandLineTools.2019.3.4\TestReport\mergedReport.html"'
$arg4 = '/ReportType="HTML"'
& $dotcover $arg1 $arg2 $arg3 $arg4
© www.soinside.com 2019 - 2024. All rights reserved.