같은 디렉토리에있는 PowerShell 스크립트 Common.ps1
의 일부 기능에 대해 Pester를 사용하여 Common.tests.ps1
PowerShell 테스트 스크립트를 만들었습니다. Microsoft.Xrm.Data.PowerShell
모듈을 사용하여 Dynamics CRM 인스턴스에서 레코드를 만들고 가져 오는 동일한 디렉터리에도 TestInitializer.ps1
스크립트가 있습니다. Visual Studio에서 Pester 테스트를 실행할 때 PowerShell 모듈을로드 할 수 없습니다.
비주얼 스튜디오에서 PowerShell을 테스트 스크립트를 실행
이 테스트는 메시지와 함께 테스트 탐색기에서 실패CommandNotFoundException : 모듈 'Microsoft.Xrm.Data.PowerShell가'로드 할 수 없습니다. 자세한 내용은 'Import-Module Microsoft.Xrm.Data.PowerShell'을 실행하십시오.
PowerShell ISE에서 실행할 때와 동일한 테스트가 문제없이 실행됩니다. 이 모듈은 Visual Studio에 의해 실행되는 인스턴스 용으로 설치되지 않은 것처럼 보입니다. (Get-Module -ListAvailable
을 실행할 때 이것을 확인하고 Visual Studio 테스트를 위해 Microsoft.Xrm.Data.PowerShell
모듈이 출력에 포함되지 않았 음을 확인했습니다.) : Import-Module Microsoft.Xrm.Data.PowerShell -Global -Force
Visual Studio에서 스크립트를 실행하는 동안 모듈을로드하지 않는 것 같습니다.
여기 Common.test.ps1
입니다 : TestInitializer.ps1
에서
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path)
. $here\Common.ps1
. $here\TestInitializer.ps1
Describe "SelectionToSingleCharString" {
Context "StringTransforms" {
It "Retrieves a CRM record and uses the optionset value to retrieve a single character" {
SelectionToSingleCharString($crmRecord.new_type) | Should Be "I"
}
}
}
발췌문 : 내가 대신로드 할 수있는 것은 아니지만, 대신에 실제로 \ 레코드를 읽을 만들려고 시도의 모의를 사용하는 테스트를 설계 할 수
# Whether or not this is uncommented does not matter
#Import-Module "$env:SystemRoot\System32\WindowsPowerShell\v1.0\Modules\Microsoft.Xrm.Data.PowerShell\Microsoft.Xrm.Data.PowerShell.psd1" -Global -Force
#$modules = Get-Module -ListAvailable
#Write-Host $modules
# Failing here
Microsoft.Xrm.Data.PowerShell\Connect-CrmOnPremDiscovery -ServerUrl $loginServerUrl -OrganizationName $loginOrgName -Credential $cred
외부 모듈과 Visual Studio에서 실행되는 것은 제한적입니다. 모듈에 대해서는
이것은 Visual Studio 2015에 있으며, 테스트가 32 비트 프로세스에서 실행되고있는 것 같습니다. Windows PowerShell (x86) 환경에서'Install-Module Microsoft.Xrm.Data.PowerShell'을 실행하고 테스트를 다시 실행하면 성공했습니다. –