Pester 测试未导出的 PowerShell cmdlets/function
Pester test non-exported PowerShell cmdlets/function
我有一个导出一个 cmdlet 的 PowerShell 模块。该模块包含几个最终用户不可见的功能。但是,我想通过 Pester 测试这些功能(因为测试设置会很简单)。
是否可以调用 cmdlet 的非导出函数?或者,是否可以强制模块加载所有功能,尽管 psd1 文件仅导出其中的一些功能?
如果您将 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
}
}
}
我有一个导出一个 cmdlet 的 PowerShell 模块。该模块包含几个最终用户不可见的功能。但是,我想通过 Pester 测试这些功能(因为测试设置会很简单)。
是否可以调用 cmdlet 的非导出函数?或者,是否可以强制模块加载所有功能,尽管 psd1 文件仅导出其中的一些功能?
如果您将 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
}
}
}