【问题标题】:Pester test non-exported PowerShell cmdlets/functionPester 测试非导出的 PowerShell cmdlet/函数
【发布时间】:2018-11-07 06:20:42
【问题描述】:

我有一个导出一个 cmdlet 的 PowerShell 模块。该模块包含几个最终用户不可见的功能。但是,我想通过 Pester 测试这些功能(因为测试设置很简单)。

是否可以调用 cmdlet 的非导出函数?或者,是否可以强制加载所有功能的模块,尽管 psd1 文件只导出其中的一部分?

【问题讨论】:

    标签: powershell pester


    【解决方案1】:

    如果您将InModuleScope 块添加到您的 Pester 脚本中,您就可以访问私有(非导出)函数:

    https://github.com/pester/Pester/wiki/InModuleScope

    Import-Module MyModule
    
    InModuleScope MyModule {
        Describe 'Testing MyModule' {
            It 'Tests the Private function' {
                PrivateFunction | Should Be $true
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-21
      • 2017-09-08
      • 1970-01-01
      相关资源
      最近更新 更多