Skip to content

Commit

Permalink
Split unit and integration test execution in CI process so that integ…
Browse files Browse the repository at this point in the history
…ration tests - Fixes #184 (#189)

* Split unit and integration test execution in CI process so that integration tests

* Ensure Code Coverage is uploaded to Azure DevOps CI
  • Loading branch information
PlagueHO committed Oct 20, 2018
1 parent 92aeebf commit 32c6da2
Show file tree
Hide file tree
Showing 18 changed files with 122 additions and 31 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -36,7 +36,8 @@ bld/

# NUNIT
*.VisualState.xml
test/TestResults.xml
test/**/TestResults.*.xml
test/**/CodeCoverage.xml

# Build Results of an ATL Project
[Dd]ebugPS/
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,8 @@
- Fixed 'Unable to find type \[Microsoft.PowerShell.Commands.HttpResponseException\]' exception
being thrown in `Invoke-CosmosDbRequest` when error is returned by Cosmos DB in PowerShell 5.x
or earlier - fixes [Issue #186](https://github.com/PlagueHO/CosmosDB/issues/186).
- Split unit and integration test execution in CI process so that integration tests do
not run when unit tests fail - fixes [Issue #184](https://github.com/PlagueHO/CosmosDB/issues/184).

## 2.1.8.59

Expand Down
49 changes: 40 additions & 9 deletions azure-pipelines.yml
Expand Up @@ -17,9 +17,24 @@ jobs:
- task: PublishTestResults@2
inputs:
testRunner: 'NUnit'
testResultsFiles: '**/TestResults.xml'
testRunTitle: 'PS_Win2016'
displayName: 'Publish Test Results'
testResultsFiles: '**/Unit/TestResults.unit.xml'
testRunTitle: 'PS_Win2016_Unit'
displayName: 'Publish Unit Test Results'
condition: in(variables['Agent.JobStatus'], 'Succeeded', 'SucceededWithIssues', 'Failed')

- task: PublishCodeCoverageResults@1
inputs:
summaryFileLocation: '**/Unit/CodeCoverage.xml'
failIfCoverageEmpty: true
displayName: 'Publish Unit Test Code Coverage'
condition: and(in(variables['Agent.JobStatus'], 'Succeeded', 'SucceededWithIssues', 'Failed'), eq(variables['System.PullRequest.IsFork'], false))

- task: PublishTestResults@2
inputs:
testRunner: 'NUnit'
testResultsFiles: '**/Integration/TestResults.integration.xml'
testRunTitle: 'PS_Win2016_Integration'
displayName: 'Publish Integration Test Results'
condition: in(variables['Agent.JobStatus'], 'Succeeded', 'SucceededWithIssues', 'Failed')

- task: PublishBuildArtifacts@1
Expand Down Expand Up @@ -76,9 +91,17 @@ jobs:
- task: PublishTestResults@2
inputs:
testRunner: 'NUnit'
testResultsFiles: '**/TestResults.xml'
testRunTitle: 'PSCore_Ubuntu1604'
displayName: 'Publish Test Results'
testResultsFiles: '**/Unit/TestResults.unit.xml'
testRunTitle: 'PSCore_Ubuntu1604_Unit'
displayName: 'Publish Unit Test Results'
condition: in(variables['Agent.JobStatus'], 'Succeeded', 'SucceededWithIssues', 'Failed')

- task: PublishTestResults@2
inputs:
testRunner: 'NUnit'
testResultsFiles: '**/Integration/TestResults.integration.xml'
testRunTitle: 'PSCore_Ubuntu1604_Integration'
displayName: 'Publish Integration Test Results'
condition: in(variables['Agent.JobStatus'], 'Succeeded', 'SucceededWithIssues', 'Failed')

- job: Build_PSCore_MacOS1013
Expand All @@ -104,7 +127,15 @@ jobs:
- task: PublishTestResults@2
inputs:
testRunner: 'NUnit'
testResultsFiles: '**/TestResults.xml'
testRunTitle: 'PSCore_MacOS1013'
displayName: 'Publish Test Results'
testResultsFiles: '**/TestResults.unit.xml'
testRunTitle: 'PSCore_MacOS1013_Unit'
displayName: 'Publish Unit Test Results'
condition: in(variables['Agent.JobStatus'], 'Succeeded', 'SucceededWithIssues', 'Failed')

- task: PublishTestResults@2
inputs:
testRunner: 'NUnit'
testResultsFiles: '**/TestResults.integration.xml'
testRunTitle: 'PSCore_MacOS1013_Integration'
displayName: 'Publish Integration Test Results'
condition: in(variables['Agent.JobStatus'], 'Succeeded', 'SucceededWithIssues', 'Failed')
69 changes: 63 additions & 6 deletions psakefile.ps1
Expand Up @@ -13,7 +13,7 @@ Properties {
$separator = '----------------------------------------------------------------------'
}

Task Default -Depends Test,Build
Task Default -Depends Test, Build

Task Init {
Set-Location -Path $ProjectRoot
Expand Down Expand Up @@ -44,7 +44,19 @@ Task Init {
"`n"
}

Task Test -Depends Init {
Task PrepareTest -Depends Init {
# Install any dependencies required for testing
Invoke-PSDepend `
-Path $PSScriptRoot `
-Force `
-Import `
-Install `
-Tags 'Test',('Test_{0}' -f $PSVersionTable.PSEdition)
}

Task Test -Depends UnitTest, IntegrationTest

Task UnitTest -Depends Init, PrepareTest {
$separator

# Install any dependencies required for the Test stage
Expand All @@ -56,13 +68,18 @@ Task Test -Depends Init {
-Tags 'Test',('Test_{0}' -f $PSVersionTable.PSEdition)

# Execute tests
$testResultsFile = Join-Path -Path $ProjectRoot -ChildPath 'test\TestResults.xml'
$testScriptsPath = Join-Path -Path $ProjectRoot -ChildPath 'test\Unit'
$testResultsFile = Join-Path -Path $testScriptsPath -ChildPath 'TestResults.unit.xml'
$codeCoverageFile = Join-Path -Path $testScriptsPath -ChildPath 'CodeCoverage.xml'
$testResults = Invoke-Pester `
-Script $testScriptsPath `
-OutputFormat NUnitXml `
-OutputFile $testResultsFile `
-PassThru `
-ExcludeTag Incomplete `
-CodeCoverage @( Join-Path -Path $ProjectRoot -ChildPath 'src\lib\*.ps1' )
-CodeCoverage @( Join-Path -Path $ProjectRoot -ChildPath 'src\lib\*.ps1' ) `
-CodeCoverageOutputFile $codeCoverageFile `
-CodeCoverageOutputFileFormat JaCoCo

# Prepare and uploade code coverage
if ($testResults.CodeCoverage)
Expand Down Expand Up @@ -109,14 +126,54 @@ Task Test -Depends Init {

if ($testResults.FailedCount -gt 0)
{
throw "$($testResults.FailedCount) tests failed."
throw "$($testResults.FailedCount) unit tests failed."
}
}
else
{
if ($testResults.FailedCount -gt 0)
{
Write-Error -Exception "$($testResults.FailedCount) unit tests failed."
}
}

"`n"
}

Task IntegrationTest -Depends Init, PrepareTest {
$separator

# Execute tests
$testScriptsPath = Join-Path -Path $ProjectRoot -ChildPath 'test\Integration'
$testResultsFile = Join-Path -Path $testScriptsPath -ChildPath 'TestResults.integration.xml'
$testResults = Invoke-Pester `
-Script $testScriptsPath `
-OutputFormat NUnitXml `
-OutputFile $testResultsFile `
-PassThru `
-ExcludeTag Incomplete

# Upload tests
if ($ENV:BHBuildSystem -eq 'AppVeyor')
{
'Publishing test results to AppVeyor'
(New-Object 'System.Net.WebClient').UploadFile(
"https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)",
(Resolve-Path $testResultsFile))

"Publishing test results to AppVeyor as Artifact"
Push-AppveyorArtifact $testResultsFile

if ($testResults.FailedCount -gt 0)
{
throw "$($testResults.FailedCount) integration tests failed."
}
}
else
{
if ($testResults.FailedCount -gt 0)
{
Write-Error -Exception "$($testResults.FailedCount) tests failed."
Write-Error -Exception "$($testResults.FailedCount) integration tests failed."
}
}

Expand Down
Expand Up @@ -4,8 +4,8 @@ param (
)

$ModuleManifestName = 'CosmosDB.psd1'
$ModuleManifestPath = "$PSScriptRoot\..\src\$ModuleManifestName"
$TestHelperPath = "$PSScriptRoot\TestHelper"
$ModuleManifestPath = "$PSScriptRoot\..\..\src\$ModuleManifestName"
$TestHelperPath = "$PSScriptRoot\..\TestHelper"

Import-Module -Name $ModuleManifestPath -Force
Import-Module -Name $TestHelperPath -Force
Expand Down
Expand Up @@ -4,7 +4,7 @@ param (
)

$ModuleManifestName = 'CosmosDB.psd1'
$ModuleManifestPath = "$PSScriptRoot\..\src\$ModuleManifestName"
$ModuleManifestPath = "$PSScriptRoot\..\..\src\$ModuleManifestName"

Import-Module -Name $ModuleManifestPath -Force

Expand Down
Expand Up @@ -4,7 +4,7 @@ param (
)

$ModuleManifestName = 'CosmosDB.psd1'
$ModuleManifestPath = "$PSScriptRoot\..\src\$ModuleManifestName"
$ModuleManifestPath = "$PSScriptRoot\..\..\src\$ModuleManifestName"

Import-Module -Name $ModuleManifestPath -Force

Expand Down
Expand Up @@ -4,7 +4,7 @@ param (
)

$ModuleManifestName = 'CosmosDB.psd1'
$ModuleManifestPath = "$PSScriptRoot\..\src\$ModuleManifestName"
$ModuleManifestPath = "$PSScriptRoot\..\..\src\$ModuleManifestName"

Import-Module -Name $ModuleManifestPath -Force

Expand Down
Expand Up @@ -4,7 +4,7 @@ param (
)

$ModuleManifestName = 'CosmosDB.psd1'
$ModuleManifestPath = "$PSScriptRoot\..\src\$ModuleManifestName"
$ModuleManifestPath = "$PSScriptRoot\..\..\src\$ModuleManifestName"

Import-Module -Name $ModuleManifestPath -Force

Expand Down
Expand Up @@ -4,7 +4,7 @@ param (
)

$ModuleManifestName = 'CosmosDB.psd1'
$ModuleManifestPath = "$PSScriptRoot\..\src\$ModuleManifestName"
$ModuleManifestPath = "$PSScriptRoot\..\..\src\$ModuleManifestName"

Import-Module -Name $ModuleManifestPath -Force

Expand Down
Expand Up @@ -4,7 +4,7 @@ param (
)

$moduleManifestName = 'CosmosDB.psd1'
$moduleRootPath = "$PSScriptRoot\..\src\"
$moduleRootPath = "$PSScriptRoot\..\..\src\"
$moduleManifestPath = Join-Path -Path $moduleRootPath -ChildPath $moduleManifestName

Describe 'Module Manifest Tests' {
Expand Down
Expand Up @@ -4,7 +4,7 @@ param (
)

$ModuleManifestName = 'CosmosDB.psd1'
$ModuleManifestPath = "$PSScriptRoot\..\src\$ModuleManifestName"
$ModuleManifestPath = "$PSScriptRoot\..\..\src\$ModuleManifestName"

Import-Module -Name $ModuleManifestPath -Force

Expand Down
Expand Up @@ -4,7 +4,7 @@ param (
)

$ModuleManifestName = 'CosmosDB.psd1'
$ModuleManifestPath = "$PSScriptRoot\..\src\$ModuleManifestName"
$ModuleManifestPath = "$PSScriptRoot\..\..\src\$ModuleManifestName"

Import-Module -Name $ModuleManifestPath -Force

Expand Down
Expand Up @@ -4,7 +4,7 @@ param (
)

$ModuleManifestName = 'CosmosDB.psd1'
$ModuleManifestPath = "$PSScriptRoot\..\src\$ModuleManifestName"
$ModuleManifestPath = "$PSScriptRoot\..\..\src\$ModuleManifestName"

Import-Module -Name $ModuleManifestPath -Force

Expand Down
Expand Up @@ -4,7 +4,7 @@ param (
)

$ModuleManifestName = 'CosmosDB.psd1'
$ModuleManifestPath = "$PSScriptRoot\..\src\$ModuleManifestName"
$ModuleManifestPath = "$PSScriptRoot\..\..\src\$ModuleManifestName"

Import-Module -Name $ModuleManifestPath -Force

Expand Down
Expand Up @@ -4,7 +4,7 @@ param (
)

$ModuleManifestName = 'CosmosDB.psd1'
$ModuleManifestPath = "$PSScriptRoot\..\src\$ModuleManifestName"
$ModuleManifestPath = "$PSScriptRoot\..\..\src\$ModuleManifestName"

Import-Module -Name $ModuleManifestPath -Force

Expand Down
Expand Up @@ -4,7 +4,7 @@ param (
)

$ModuleManifestName = 'CosmosDB.psd1'
$ModuleManifestPath = "$PSScriptRoot\..\src\$ModuleManifestName"
$ModuleManifestPath = "$PSScriptRoot\..\..\src\$ModuleManifestName"

Import-Module -Name $ModuleManifestPath -Force

Expand Down
Expand Up @@ -4,7 +4,7 @@ param (
)

$ModuleManifestName = 'CosmosDB.psd1'
$ModuleManifestPath = "$PSScriptRoot\..\src\$ModuleManifestName"
$ModuleManifestPath = "$PSScriptRoot\..\..\src\$ModuleManifestName"

Import-Module -Name $ModuleManifestPath -Force

Expand Down

0 comments on commit 32c6da2

Please sign in to comment.