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
    )

    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
        }
    }

    if (!($DoNotPrepTestSuite.IsPresent)) {
        Get-TestCodeunitsInContainer -ContainerName $ContainerName -TestSuite $TestSuite -Credential $Credential
    }

    Write-Host 'Executing tests in client'

    Run-TestsInNavContainer -containerName $ContainerName -credential $Credential -XUnitResultFileName "C:\ProgramData\NavContainerHelper\Extensions\$ContainerName\my\Results.xml" -detailed -testSuite $TestSuite -testCodeunit $TestCodeunit -testFunction $TestMethod -returnTrueIfAllPassed

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

Export-ModuleMember -Function Run-BCTests