【问题标题】:Test a collection for equality or equivalence in Pester在 Pester 中测试集合是否相等或等价
【发布时间】:2017-01-04 16:20:09
【问题描述】:

在 nUnit 中,我们可以这样做:

Expect(actualColleciton, EquivalentTo(expectedCollection));

Expect(actualCollection, EqualTo(expectedCollection));

Pester 中是否有等价物?

我知道我能做到

$actualCollection | Should Be $expectedCollection

但它的行为与您预期的不同。

我是否使用了正确的语法?

【问题讨论】:

    标签: powershell pester


    【解决方案1】:

    我猜您想比较集合的内容,而不是集合的指针/地址。

    我认为您可以从以下内容中获得启发:

    $a1=@(1,2,3,4,5)
    $b1=@(1,2,3,4,5,6)
    $ret = (Compare-Object $a1 $b1).InputObject
    
    if ($ret)
    {
    "different"
    }
    else
    {
    "same"
    }
    

    做一些类似的事情:

    $ret = (Compare-Object $actualCollection $expectedCollection).InputObject
    $ret | Should Be $null 
    

    其中 $null 表示列表相同。

    【讨论】:

    • 哦,好建议!我将测试更改为:``` $result = Compare-Object $expectedScripts $ScriptsToRun $result |应该 BeNullOrEmpty ``` 原因是,如果它是错误的,并且它不是 null,你会得到这样的输出: `` alue to be empty but it was {@{InputObject=LoadRoomsLegacy; SideIndicator=
    猜你喜欢
    • 2016-10-26
    • 2013-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-12
    • 2013-07-15
    • 2011-11-22
    相关资源
    最近更新 更多