安装PowerShell Tools for Visual Studio 2015
后,我创建了一个新的Powershell Module Project
,它创建了一个MyProject.psd1
和一个MyProject.tests.ps1
文件。在Visual Studio中运行Pester测试
MyProject.tests.ps1文件看起来像这样
Describe "Connect-Database" {
Context "When Connection To Database" {
$result = Connect-Database -host localhost -user admin -pass pass
It "Should Return True" {
$result | Should Be $True
}
}
}
连接,数据库是一个函数从MyProject.psm1
并通过MyProject.psd1
# Functions to export from this module
FunctionsToExport = 'Connect-Database'
运行PowerShell控制台和执行
Import-Module .\MyProject.psd1
Invoke-Pester
出口
很好,并返回
Describing Connect-Database
Context When Connection To Database
[+] Should Return True 627ms
Tests completed in 627ms
Passed: 1 Failed: 0 Skipped: 0 Pending: 0
这里来我的问题:PowerShell的工具附带测试适配器和我的测试是在试验资源管理器。
,但如果我执行它,它总是失败,The term Connect-Database is not recognized as cmdlet function script file or operable program
即使添加Import-Module .\MyProject.psd1
到MyProject.tests.ps1
文件没有帮助。任何想法如何在运行测试之前加载我的模块?