【问题标题】:Mock [System.IO.Path]::IsPathRooted() using Pester?使用 Pester 模拟 [System.IO.Path]::IsPathRooted()?
【发布时间】:2017-04-19 03:15:49
【问题描述】:

如何使用 Pester 模拟 [System.IO.Path]::IsPathRooted()?我尝试了以下但没有运气。

Describe "Configuration" {
    Mock [System.IO.Path]::IsPathRooted {
        return false
    }

    It "should mock rooted Path" {
        [System.IO.Path]::IsPathRooted("C:\a") | Should Be False
    }

【问题讨论】:

    标签: unit-testing powershell testing mocking pester


    【解决方案1】:

    很遗憾,您的问题的答案很简短:

    你不能。


    根据Pester's Github Issue #72,最好的选择是将方法调用包装在一个单独的函数中,Mock这个函数。

    对此进行了一些讨论,很多人都希望能够模拟 .Net 方法,但直到现在,我还没有找到任何解决方案。不幸的是,即使覆盖方法(独立于 Pester)也不是那么容易。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多