2016-08-15 31 views
1

大家好我有一個書面的示例腳本查找給定的字符串是否是迴文與否如下一個示例腳本糾纏PowerShell的測試工作不正常

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

你看到了什麼結果? – Kirill

+0

在我的xml我得到如下'預計:{真實} 但是:{}' – Dotnet

回答

1

本聲明:

[string] $ReversString 

是造成空字符串值表達式。每次運行它時,該空字符串都由Palindrome1函數輸出。將其更改爲:

[string] $ReversString = '' 
+0

感謝'Mathia' – Dotnet

+0

嗨,多一點幫助,當我把輸入參數作爲強制性它要求我多次輸入字符串'功能Palindrome1 { [列出CmdletBinding()] \t PARAM( [參數(強制性)] [字符串] $ PARAM )' – Dotnet

+0

不能夠再現,它只有當參數不存在提示一次。請[問一個新的問題](http://stackoverflow.com/questions/ask)如果你需要幫助參數 –