大家好我写了一个示例脚本来查找给定字符串是否为Palindrome,如下所示
function Palindrome1([string] $param)
{
[string] $ReversString
$StringLength = @()
$StringLength = $param.Length
while ( $StringLength -ge 0 )
{
$ReversString = $ReversString + $param[$StringLength]
$StringLength--
}
if($ReversString -eq $param)
{
return $true
}
else
{
return $false
}
}
这是我的.tests.ps1
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.'
. "$here\$sut"
Describe "Palindrome1" {
It "does something useful" {
Palindrome1 "radar" | Should Be $true
}
}
下面是调用脚本
$modulePath = "D:\Pester-master\Pester.psm1"
$SourceDir = "E:\Pester"
Import-Module $modulePath -ErrorAction Inquire
$outputFile = Join-Path $SourceDir "TEST-pester.xml"
$result = Invoke-Pester -Path $SourceDir -CodeCoverage "$SourceDir\*.ps1" -PassThru -OutputFile $outputFile
$result
我没有得到预期的结果,有人可以告诉我我做错了什么
答案 0 :(得分:1)
本声明:
[string] $ReversString
是一个值表达式,导致空字符串。每次运行时,Palindrome1
函数都会输出该空字符串。将其更改为:
[string] $ReversString = ''