1+ parameters :
2+ - name : TargetDirectory
3+ type : string
4+ - name : CustomTestSteps
5+ type : object
6+ default : []
7+ - name : EnvVars
8+ type : object
9+ default : {}
10+ - name : TargetTags
11+ type : string
12+ default : ' '
13+
14+ steps :
15+ - pwsh : |
16+ Install-Module -Name Pester -Force
17+ displayName: Install Pester
18+
19+ # default test steps
20+ - ${{ if eq(length(parameters.CustomTestSteps), 0) }} :
21+ - pwsh : |
22+ $tags = "${{ parameters.TargetTags }}" -Split "," | ForEach-Object { return $_.Trim() }
23+
24+ $config = New-PesterConfiguration
25+ $config.CodeCoverage.Enabled = $true
26+ $config.TestResult.Enabled = $true
27+ $config.Run.PassThru = $true
28+
29+ if ($tags) {
30+ $config.Filter.Tag = $tags
31+ }
32+
33+ Invoke-Pester -Configuration $config
34+ displayName: Run Tests
35+ env: ${{ parameters.EnvVars }}
36+ workingDirectory: $(Build.SourcesDirectory)/${{ parameters.TargetDirectory }}
37+
38+ - ${{ if not(eq(length(parameters.CustomTestSteps), 0)) }} :
39+ - ${{ parameters.CustomTestSteps }}
40+
41+ - task : PublishTestResults@2
42+ displayName : ' Publish Test Results'
43+ condition : succeededOrFailed()
44+ inputs :
45+ testResultsFormat : ' NUnit'
46+ testResultsFiles : $(Build.SourcesDirectory)/${{ parameters.TargetDirectory }}/testResults.xml
47+ testRunTitle : ' $(System.StageName)_$(Agent.JobName)_Tests'
48+
49+ - task : PublishCodeCoverageResults@1
50+ displayName : ' Publish Code Coverage to Azure DevOps'
51+ condition : succeededOrFailed()
52+ inputs :
53+ codeCoverageTool : ' JaCoCo'
54+ summaryFileLocation : ' $(Build.SourcesDirectory)/${{ parameters.TargetDirectory }}/coverage.xml'
55+ pathToSources : ' $(Build.SourcesDirectory)/${{ parameters.TargetDirectory }}'
0 commit comments