Testing/Run-BCTests.ps1

function Run-BCTests
{
    Param(
        [Parameter(Mandatory=$false)]
        [string]$ResultPath = '',
        [Parameter(Mandatory=$false)]
        [string]$ContainerName = (Get-ContainerFromLaunchJson),
        # Name of test suite to run
        [Parameter(Mandatory=$false)]
        [string]
        $TestSuite = 'DEFAULT',
        # Number of test codeunit to run
        [Parameter(Mandatory=$false)]
        [string]
        $TestCodeunit ='*',
        # Name of test method to run
        [Parameter(Mandatory=$false)]
        [string]
        $TestMethod = '*',
        [Parameter(Mandatory=$false)]
        [PSCredential]$Credential = (New-CredentialFromEnvironmentJson),
        [Parameter(Mandatory=$false)]
        [switch]$DoNotPrepTestSuite,
        [Parameter(Mandatory=$false)]
        [string]$ExtensionId        
    )

    Write-Host -ForegroundColor Green "Run tests in container $ContainerName, suite $TestSuite, codeunit $TestCodeunit, method $TestMethod"

    if ((Get-IsALRepo) -and ($ContainerName -eq '')) {
        $ContainerName = (Split-Path (Get-Location) -Leaf)
    }

    if ($ResultPath -ne '') {
        if (Test-Path $ResultPath) {
            Remove-Item $ResultPath
        }
    }
    
    Write-Host 'Executing tests in client'

    #for versions prior to BC15 we need to prep the test suite with the build helper extension
    if ([Version]::Parse((Get-AppKeyValue -KeyName 'platform')) -lt [Version]::new('15.0.0.0')) {
        if (!($DoNotPrepTestSuite.IsPresent)) {
            Get-TestCodeunitsInContainer -ContainerName $ContainerName -TestSuite $TestSuite -Credential $Credential
        }
        
        Run-TestsInNavContainer -containerName $ContainerName -credential $Credential -XUnitResultFileName "C:\ProgramData\BcContainerHelper\Extensions\$ContainerName\my\Results.xml" -detailed -testSuite $TestSuite -testCodeunit $TestCodeunit -testFunction $TestMethod -returnTrueIfAllPassed
    }
    else {
        Run-TestsInNavContainer -containerName $ContainerName -credential $Credential -XUnitResultFileName "C:\ProgramData\BcContainerHelper\Extensions\$ContainerName\my\Results.xml" -detailed -testSuite $TestSuite -testCodeunit $TestCodeunit -testFunction $TestMethod -returnTrueIfAllPassed -extensionId $ExtensionId
    }

    if ($ResultPath -ne '') {
        Copy-Item "C:\ProgramData\BcContainerHelper\Extensions\$ContainerName\my\Results.xml" $ResultPath -Force
    }
}

Export-ModuleMember -Function Run-BCTests