Pester PowerShell测试提示多次输入 [英] Pester PowerShell testing prompting to enter the input multiple times

查看:133
本文介绍了Pester PowerShell测试提示多次输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

function Palindrome1
{
    [CmdletBinding()]
    param (
        [Parameter(Mandatory)]
        [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
. "$here\Palindrome1.ps1"

Describe -Tags "Example" "Palindrome1" {
    It "does something useful" {
        Palindrome1 | Should Be $true
    }
}

推荐答案

标记参数Mandatory时,必须为其提供输入值-否则将提示您输入一个值.

When you mark a parameter Mandatory, you MUST supply an input value to it - otherwise it will prompt you for one.

来自 Get-Help about_Parameters :



 PARAMETER ATTRIBUTE TABLE
 [...] 
   Parameter Required?
     This setting indicates whether the parameter is mandatory, that
     is, whether all commands that use this cmdlet must include this
     parameter. When the value is "True" and the parameter is missing
     from the command, Windows PowerShell prompts you for a value for
     the parameter.

将测试更改为:

Describe -Tags "Example" "Palindrome1" {
    It "does something useful" {
        Palindrome1 -param "value goes here" | Should Be $true
    }
}

这篇关于Pester PowerShell测试提示多次输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆