There is the issue in Run tsSQLt Tests task (can reproduce this issue).
The source code (can find it in agent working folder, for example: _work/_task/RunDatabaseTestsxxx):
RunDatabaseTests.ps1:
[CmdletBinding(DefaultParameterSetName = 'None')]
param()
$global:ErrorActionPreference = 'Stop'
Import-Module -Name "$PSScriptRoot\ps_modules\TaskHelpers"
[string]$outputPath = Get-VstsInput -Name OutputPath
[string]$databaseServer = Get-VstsInput -Name DatabaseServer
[string]$databaseName = Get-VstsInput -Name DatabaseName
[bool]$useWindowsAuth = Get-VstsInput -Name UseWindowsAuth -AsBool
[string]$databaseUserName = Get-VstsInput -Name DatabaseUserName
[string]$databasePassword = Get-VstsInput -Name DatabasePassword
Write-VstsTaskVerbose -Message 'Ensuring the path to sqlcmd is present in env:PATH'
Initialize-SqlCmdInPathEnvironmentVariable
[string]$sourcesDirectory = Get-VstsTaskVariable -Name 'Build.SourcesDirectory'
if(!$sourcesDirectory)
{
Write-VstsTaskVerbose -Message 'Build.SourcesDirectory was not found as a VSTS Task variable'
Write-VstsTaskVerbose -Message 'Looking for Agent.ReleaseDirectory to use as source directory instead'
# For RM, look for the test assemblies under the release directory.
$sourcesDirectory = Get-VstsTaskVariable -Name 'Agent.ReleaseDirectory'
}
if(!$sourcesDirectory)
{
$msg = 'No source directory found'
Exit-WithError $msg
}
Write-VstsTaskVerbose -Message 'Source directory found'
Write-VstsTaskDebug -Message "buildSourcesDirectory = $buildSourcesDirectory"
if ([System.IO.Path]::IsPathRooted($outputPath) -eq $False)
{
$outputPath = Join-Path $sourcesDirectory $outputPath
}
Write-VstsTaskDebug -Message "OutputPath(absolute) = $outputPath"
if ($useWindowsAuth -eq $True) {
Write-VstsTaskVerbose -Message 'Starting sqlcmd with Windows Authentication'
Invoke-VstsTool -FileName 'sqlcmd.exe' -Arguments "-S $databaseServer -d $databaseName -i 'RunTests.sql'"
Invoke-VstsTool -FileName 'sqlcmd.exe' -Arguments "-S $databaseServer -d $databaseName -i 'OutputResults.sql' -o $outputPath"
}
else {
Write-VstsTaskVerbose -Message 'Starting sqlcmd with SQL Authentication'
Invoke-VstsTool -FileName 'sqlcmd.exe' -Arguments "-S $databaseServer -d $databaseName -U $databaseUserName -P $databasePassword -i 'RunTests.sql'"
Invoke-VstsTool -FileName 'sqlcmd.exe' -Arguments "-S $databaseServer -d $databaseName -U $databaseUserName -P $databasePassword -i 'OutputResults.sql' -o $outputPath"
}
# sqlcmd limits line length to 2034 characters and inserts new lines. Remove these.
$x = Get-Content $outputPath -Raw
$x.Replace("`r`n", "") > $outputPath
RunTests.sql:
EXEC [tSQLt].[RunAll];
OutputResults.sql:
:XML ON
EXEC [tSQLt].[XmlResultFormatter];
I can run the test by calling "sqlcmd.exe" -S v-tinmo-12r2 -d ReadyRollDemo2 -U starain -P User@123 -i RunTests.sql
command (remove single quotes from 'RunTests.sql', also can replace single quotes to double quotes))
So, you can run test and get reports by calling sqlcmd.exe through command line tasks or you can refer to the source code of Run tSQLt Tests task to custom the build/release task.