Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VSTest task changes #2

Closed
wants to merge 13 commits into from
19 changes: 16 additions & 3 deletions Tasks/VsTest/VSTest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ param(
[string]$runSettingsFile,
[string]$codeCoverageEnabled,
[string]$pathtoCustomTestAdapters,
[string]$otherConsoleOptions
[string]$overrideTestrunParameters,
[string]$otherConsoleOptions,
[string]$platform,
[string]$configuration
)

Write-Verbose "Entering script VSTestConsole.ps1"

# Import the Task.Common dll that has all the cmdlets we need for Build
import-module "Microsoft.TeamFoundation.DistributedTask.Task.Common"
# Import the Task.TestResults dll that has the cmdlet we need for publishing results
import-module "Microsoft.TeamFoundation.DistributedTask.Task.TestResults"

if (!$testAssembly)
{
Expand All @@ -38,9 +43,17 @@ if($testAssemblyFiles)
{
Write-Verbose "Calling Invoke-VSTest for all test assemblies"
$timeline = Start-Timeline -Context $distributedTaskContext
$cwd = Get-Location
$projectName = Get-Variable -Context $distributedTaskContext -Name "System.TeamProject"
$buildDir = Get-Variable -Context $distributedTaskContext -Name "Agent.BuildDirectory" -Global $FALSE
$buildNumber = Get-Variable -Context $distributedTaskContext -Name "Build.BuildNumber"
$buildUri = Get-Variable -Context $distributedTaskContext -Name "Build.BuildUri"
$cwd = $buildDir+"\"+$projectName
$testResultsDir = $buildDir+"\"+$projectName+"\"+"TestResults"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need project here BuildDir should be unique enough

$trxLocation = $buildDir+"\"+$projectName+"\"+"Temp"
Write-Verbose "Calling Invoke-VSTest from working folder: $cwd"
Invoke-VSTest -TestAssemblies $testAssemblyFiles -Timeline $timeline -VSTestVersion $vsTestVersion -TestFiltercriteria $testFiltercriteria -RunSettingsFile $runSettingsFile -PathtoCustomTestAdapters $pathtoCustomTestAdapters -CodeCoverageEnabled $codeCoverage -OtherConsoleOptions $otherConsoleOptions -WorkingFolder $cwd
Invoke-VSTest -TestAssemblies $testAssemblyFiles -Timeline $timeline -VSTestVersion $vsTestVersion -TestFiltercriteria $testFiltercriteria -RunSettingsFile $runSettingsFile -PathtoCustomTestAdapters $pathtoCustomTestAdapters -CodeCoverageEnabled $codeCoverage -OverrideTestrunParameters $overrideTestrunParameters -OtherConsoleOptions $otherConsoleOptions -WorkingFolder $cwd -TestResultsDir $testResultsDir -ResultLocation $trxLocation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you even populating the timeline anymore? I don't believe so and if not we should remove it.

$connection = Get-VssConnection -TaskContext $distributedTaskContext
Invoke-ResultPublisher -Connection $connection -ProjectName $projectName -ResultLocation $trxLocation -Extension "trx" -ReaderType "Trx" -BuildUri $buildUri -BuildNumber $buildNumber -Platform $platform -Configuration $configuration
}
else
{
Expand Down
52 changes: 38 additions & 14 deletions Tasks/VsTest/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 8
"Patch": 9
},
"demands": [
"vstest"
Expand Down Expand Up @@ -37,30 +37,45 @@
"required": false,
"helpMarkDown": "Filter criteria for the tests."
},
{
"name": "platform",
"type": "string",
"label": "Platform",
"defaultValue":"",
"required":false
},
{
"name": "configuration",
"type": "string",
"label": "Configuration",
"defaultValue":"",
"required":false
},
{
"name": "runSettingsFile",
"type": "filePath",
"type": "string",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change this to a string? This should be a file path so I optionally get a picker and the infrastructure will automatically try to convert a relative path to a full path.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this should be a filePath

"label": "Run Settings File",
"defaultValue": "",
"required": false,
"helpMarkDown": "The run settings file to use."
},
{
"name": "codeCoverageEnabled",
"type": "boolean",
"label": "Code Coverage Enabled",
"defaultValue": "True",
"required": false,
"helpMarkDown": "Whether code coverage needs to be enabled."
"helpMarkDown": "Path to runsettings file to use with the Tests. Use $(agent.BuildDirectory)\\$(system.teamProject) to access the Project folder"
},
{
"name": "otherConsoleOptions",
"name": "overrideTestrunParameters",
"type": "string",
"label": "Other console options",
"label": "Override TestRun Parameters",
"defaultValue": "",
"required": false,
"helpMarkDown": "Any other console options to be used."
"helpMarkDown": "Override parameters defined in the TestRunParameters section of runsettings file. For example: Platform=$(platform);Port=8080"
},
{
"name": "codeCoverageEnabled",
"type": "boolean",
"label": "Code Coverage Enabled",
"defaultValue": "False",
"required": false,
"helpMarkDown": "Whether code coverage needs to be enabled.",
"groupName":"advanced"
},
{
"name": "vsTestVersion",
"type": "pickList",
Expand All @@ -82,6 +97,15 @@
"required": false,
"helpMarkDown": "Path to custom adapters.",
"groupName":"advanced"
},
{
"name": "otherConsoleOptions",
"type": "string",
"label": "Other console options",
"defaultValue": "",
"required": false,
"helpMarkDown": "Other console options.",
"groupName": "advanced"
}
],
"instanceNameFormat": "Test Assemblies $(testAssembly)",
Expand Down