Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing 使用';纠缠';(PowerShell单元测试框架)具有属性_Unit Testing_Powershell_Tdd_Pester - Fatal编程技术网

Unit testing 使用';纠缠';(PowerShell单元测试框架)具有属性

Unit testing 使用';纠缠';(PowerShell单元测试框架)具有属性,unit-testing,powershell,tdd,pester,Unit Testing,Powershell,Tdd,Pester,我正在尝试将一个文本夹具包装在一些PowerShell代码周围,这些代码扩展了一个具有属性的对象。我得到一个错误,似乎是由纠缠引起的。下面我有一个人为的例子,展示了我正在尝试做的事情 有人成功地编写了对使用Pester属性的函数的测试吗 我得到的错误是: Describing Get-PropertyOfItem Select-Object : Property cannot be processed because property "should" already exists. At C:

我正在尝试将一个文本夹具包装在一些PowerShell代码周围,这些代码扩展了一个具有属性的对象。我得到一个错误,似乎是由纠缠引起的。下面我有一个人为的例子,展示了我正在尝试做的事情

有人成功地编写了对使用Pester属性的函数的测试吗

我得到的错误是:

Describing Get-PropertyOfItem
Select-Object : Property cannot be processed because property "should" already exists.
At C:\Repos\ClinicientOps\clinicientops\General\Functions\Get-PropertyOfItem.ps1:4 char:11
+     $files | Select-Object *, @{Name = "TestProperty"; Expression = { $dir.Length}} ...
+              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Windows:PSObject) [Select-Object], PSArgumentException
    + FullyQualifiedErrorId : AlreadyExistingUserSpecifiedPropertyNoExpand,Microsoft.PowerShell.Commands.SelectObjectCommand
我的职能:

function Get-PropertyOfItem {
    $dir = "C:\"
    $files = Get-ChildItem $dir
    $files | Select-Object *, @{Name = "TestProperty"; Expression = { $dir.Length}} -Last 1
}
我的测试代码:

$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
. "$here\$sut"

Describe "Get-PropertyOfItem" {

    It "does something useful" {

        $prop = Get-PropertyOfItem
        $prop.TestProperty.should.be(3)
    }
}

这似乎是他们正在版本2中调查的一个限制。

已被悄悄发布。你必须重新写下你的期望

$prop.TestProperty | Should Be 3

这也意味着您的所有其他测试都需要迁移到此管道表单期望语法。

来自pester的github上的scottmuc:“呸,似乎对象扩展导致了更多问题。我们正在考虑删除$object.should扩展,并在版本2.0中使用基于管道的断言,这将解决此问题。”我真的很难开始使用Pester。我是一名DBA,对BDD非常陌生。我需要做的大多数测试要么是特定于环境的(确保环境已配置),要么是集成多个步骤。wiki似乎专注于测试单个函数。你对学习如何使用这个工具有什么建议吗?有一件事很有帮助,那就是在一个页面上解释如何设置Pester-当我按照这里的说明操作时,我很好奇:。。。我得到的是什么版本,1.2还是2.0?能否添加上下文-对GitHub内容的引用?