我有一个可导出一个 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
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
533 次 |
| 最近记录: |