Pester测试未导出的PowerShell cmdlet /功能

时间:2018-11-07 06:20:43

标签: powershell pester

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

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

1 个答案:

答案 0 :(得分:2)

如果您将P 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
        }
    }
}
相关问题