- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
大家好,
由于脚本 block ,我的纠缠者没有达到 100% 的代码覆盖率,我为此苦苦挣扎了很长时间。我一直在研究和阅读文章但没有成功,我决定向你们寻求帮助。 :)
我想描述的部分代码包含一个脚本 block ,稍后将被提供给一个 cmdlet Invoke-Command。示例代码如下:
function Get-Function {
.....
Set-Alias Start-PowerShell32 $env:computername\WindowsPowerShell\v1.0\powershell.exe"
$ScriptBlock = {
Start-PowerShell32 -noprofile {
$sample = Get-Content -Path "C:\sample.txt
Import-Module "C:\Program Files (x86)\Software"
@($sample) | Get-Service | Where-Object { $_.Status -eq 'Stopped' }
}
}
Invoke-Command -ScriptBlock $ScriptBlock
}
Describe Get-Function {
....
function Get-Statistics {
Start-PowerShell32 -noprofile {
$sample = Get-Content -Path "C:\sample.txt
Import-Module "C:\Program Files (x86)\Software"
@($sample) | Get-Service | Where-Object { $_.Status -eq 'Stopped' }
}
}
Context '1st Context'{
mock Set-Alias {'Setting alias for Powershell 32 bit'} -Verifiable
mock Get-Statistics {'Getting Statistics ....'} -Verifiable
mock Invoke-Command {Get-Statistics} -Verifiable
$result = Get-Function
it 'should return etting alias for Powershell 32 bit'{
$result[0] | should be "Setting alias for Powershell 32 bit"
}
it 'should return Getting Mailbox Statistics ....'{
$result[1] | should be "Getting Statistics ...."
}
it 'should call all verifiable mocks'{
Assert-VerifiableMocks
}
}
}
我在我的 Pester 上所做的是,我在我的 Describe block (Get-Statistics)中创建了一个自定义函数,它基本上是脚本 block 的内部,以便在我将 Invoke-Command 模拟为 Get-Statistics 时调用它.我的 Pester 成功了,但代码覆盖率没有达到 100%。你们能告诉我如何做到这一点吗?我需要改变我的测试吗?谢谢你
最佳答案
在 Describe {
block 的开头,包含一个用于 Invoke-Command
的模拟:
Describe '..' {
Mock Invoke-Command { Param($SB) . $SB }
...
}
关于powershell - 由于脚本 block ,无法达到 100% 纠缠代码覆盖率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47677420/
我在 Pester 中有以下简单的测试: # Name.Tests.ps1 $name = "foo" Describe "Check name" { It "should have the co
我们正在尝试检查 CmdLet Start-ScheduledTask 是否已为特定计划任务准确调用一次。但由于某种原因,ParameterFilter 不匹配。 代码 $here = Split-P
我正在使用 pester 来测试我抛出的异常(负面测试)。 尽管看起来抛出的异常消息与我的Should -Throw 完全匹配,但当异常消息中有方括号时,Pester 会声明测试失败。通过从抛出的异常
我是一名优秀的程序员,十分优秀!