【发布时间】:2015-09-12 15:49:54
【问题描述】:
我正在尝试测试一个设置 SharePoint 列表项的属性值的 PowerShell 命令 (Set-PropertyValue)。该函数使用Invoke-WebMethod函数做实际工作。
我当前的Set-PropertyValue.Test.ps1 文件:
# include stuff omitted
Describe 'Set-PropertyValue' {
#
# arrange
#
# set $url, $list, $id, $property variables
...
# the value that it should be
$expected=10.5
BeforeEach {
# get the property's current value
$original = Get-PropertyValue $url $list $id $property
}
AfterEach {
# restore original value
Set-PropertyValue $url $list $id $property $original
}
It "Should set a property's value" {
#
# act
#
# update property's value
$response = Set-PropertyValue $url $list $id $property $expected
# get the new value
$actual = Get-PropertyValue $url $list $id $property
#
# assert
#
$response.statuscode | should be 204 # no content
$actual | Should Be $expected
} # It
} # Describe
我不喜欢这个有很多原因:
- 对
Get-PropertyValue的外部依赖 - 没有测试隔离;对 SharePoint 列表进行了更改
- 可能会在不良状态下对列表项进行分级
- 测试结构不适合轻松测试多个属性,可能是在一个循环中
有没有更好的测试方法?
【问题讨论】:
-
我没有适合你的解决方案,但我一直在为同样的事情苦苦挣扎。 I found this article to be a good read.
-
我越想这种情况,就越觉得这些真的是集成测试。
-
没错。就个人而言,我在纠结 Pester 是否仍然是运行集成测试的合适工具,以及如何有效地实现它们。如果你发现你已经解决了这个问题,我很想听听你的想法。
标签: powershell sharepoint powershell-3.0 pester