Skip to content

Commit

Permalink
Add number of failed tests, number of passed tests and test pass rate
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuBuisson committed May 6, 2017
1 parent 4f6e19f commit c5a8471
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
3 changes: 3 additions & 0 deletions PSCodeHealth/Private/New-PSCodeHealthReport.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ Function New-PSCodeHealthReport {
'ScriptAnalyzerInformation' = ($ScriptAnalyzerInformation | Measure-Object).Count
'ScriptAnalyzerFindingsAverage' = [math]::Round(($FunctionHealthRecord.ScriptAnalyzerFindings | Measure-Object -Average).Average, 2)
'NumberOfTests' = If ( $TestResult ) { $TestResult.TotalCount } Else { 0 }
'NumberOfFailedTests' = If ( $TestResult ) { $TestResult.FailedCount } Else { 0 }
'NumberOfPassedTests' = If ( $TestResult ) { $TestResult.PassedCount } Else { 0 }
'TestsPassRate' = If ($TestResult.TotalCount) { [math]::Round(($TestResult.PassedCount / $TestResult.TotalCount) * 100, 2) } Else { 0 }
'TestCoverage' = $CodeCoveragePerCent
'CommandsMissedTotal' = $CommandsMissed
'ComplexityAverage' = [math]::Round(($FunctionHealthRecord.Complexity | Measure-Object -Average).Average, 2)
Expand Down
54 changes: 54 additions & 0 deletions Tests/Unit/Private/New-PSCodeHealthReport.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ Describe 'New-PSCodeHealthReport' {
It 'Should return an object with the expected property "NumberOfTests"' {
$Result.NumberOfTests | Should Be 0
}
It 'Should return an object with the expected property "NumberOfFailedTests"' {
$Result.NumberOfFailedTests | Should Be 0
}
It 'Should return an object with the expected property "NumberOfPassedTests"' {
$Result.NumberOfPassedTests | Should Be 0
}
It 'Should return an object with the expected property "TestsPassRate"' {
$Result.TestsPassRate | Should Be 0
}
It 'Should return an object with the expected property "TestCoverage"' {
$Result.TestCoverage | Should Be 0
}
Expand Down Expand Up @@ -117,6 +126,15 @@ Describe 'New-PSCodeHealthReport' {
It 'Should return an object with the expected property "NumberOfTests"' {
$Result.NumberOfTests | Should Be 51
}
It 'Should return an object with the expected property "NumberOfFailedTests"' {
$Result.NumberOfFailedTests | Should Be 7
}
It 'Should return an object with the expected property "NumberOfPassedTests"' {
$Result.NumberOfPassedTests | Should Be 44
}
It 'Should return an object with the expected property "TestsPassRate"' {
$Result.TestsPassRate | Should Be 86.27
}
It 'Should return an object with the expected property "TestCoverage"' {
$Result.TestCoverage | Should Be 81.48
}
Expand Down Expand Up @@ -177,6 +195,15 @@ Describe 'New-PSCodeHealthReport' {
It 'Should return an object with the expected property "NumberOfTests"' {
$Result.NumberOfTests | Should Be 0
}
It 'Should return an object with the expected property "NumberOfFailedTests"' {
$Result.NumberOfFailedTests | Should Be 0
}
It 'Should return an object with the expected property "NumberOfPassedTests"' {
$Result.NumberOfPassedTests | Should Be 0
}
It 'Should return an object with the expected property "TestsPassRate"' {
$Result.TestsPassRate | Should Be 0
}
It 'Should return an object with the expected property "TestCoverage"' {
$Result.TestCoverage | Should Be 0
}
Expand Down Expand Up @@ -239,6 +266,15 @@ Describe 'New-PSCodeHealthReport' {
It 'Should return an object with the expected property "NumberOfTests"' {
$Result.NumberOfTests | Should Be 0
}
It 'Should return an object with the expected property "NumberOfFailedTests"' {
$Result.NumberOfFailedTests | Should Be 0
}
It 'Should return an object with the expected property "NumberOfPassedTests"' {
$Result.NumberOfPassedTests | Should Be 0
}
It 'Should return an object with the expected property "TestsPassRate"' {
$Result.TestsPassRate | Should Be 0
}
It 'Should return an object with the expected property "TestCoverage"' {
$Result.TestCoverage | Should Be 0
}
Expand Down Expand Up @@ -294,6 +330,15 @@ Describe 'New-PSCodeHealthReport' {
It 'Should return an object with the expected property "NumberOfTests"' {
$Result.NumberOfTests | Should Be 0
}
It 'Should return an object with the expected property "NumberOfFailedTests"' {
$Result.NumberOfFailedTests | Should Be 0
}
It 'Should return an object with the expected property "NumberOfPassedTests"' {
$Result.NumberOfPassedTests | Should Be 0
}
It 'Should return an object with the expected property "TestsPassRate"' {
$Result.TestsPassRate | Should Be 0
}
It 'Should return an object with the expected property "TestCoverage"' {
$Result.TestCoverage | Should Be 0
}
Expand Down Expand Up @@ -350,6 +395,15 @@ Describe 'New-PSCodeHealthReport' {
It 'Should return an object with the expected property "NumberOfTests"' {
$Result.NumberOfTests | Should Be 0
}
It 'Should return an object with the expected property "NumberOfFailedTests"' {
$Result.NumberOfFailedTests | Should Be 0
}
It 'Should return an object with the expected property "NumberOfPassedTests"' {
$Result.NumberOfPassedTests | Should Be 0
}
It 'Should return an object with the expected property "TestsPassRate"' {
$Result.TestsPassRate | Should Be 0
}
It 'Should return an object with the expected property "TestCoverage"' {
$Result.TestCoverage | Should BeNullOrEmpty
}
Expand Down
18 changes: 18 additions & 0 deletions Tests/Unit/Public/Invoke-PSCodeHealth2.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ Describe 'Invoke-PSCodeHealth (again)' {
It 'Should return an object with the expected property "NumberOfTests"' {
$Result.NumberOfTests | Should Be 0
}
It 'Should return an object with the expected property "NumberOfFailedTests"' {
$Result.NumberOfFailedTests | Should Be 0
}
It 'Should return an object with the expected property "NumberOfPassedTests"' {
$Result.NumberOfPassedTests | Should Be 0
}
It 'Should return an object with the expected property "TestsPassRate"' {
$Result.TestsPassRate | Should Be 0
}
It 'Should return an object with the expected property "TestCoverage"' {
$Result.TestCoverage | Should Be 0
}
Expand Down Expand Up @@ -108,6 +117,15 @@ Describe 'Invoke-PSCodeHealth (again)' {
It 'Should return an object with the expected property "NumberOfTests"' {
$Result.NumberOfTests | Should Be 0
}
It 'Should return an object with the expected property "NumberOfFailedTests"' {
$Result.NumberOfFailedTests | Should Be 0
}
It 'Should return an object with the expected property "NumberOfPassedTests"' {
$Result.NumberOfPassedTests | Should Be 0
}
It 'Should return an object with the expected property "TestsPassRate"' {
$Result.TestsPassRate | Should Be 0
}
It 'Should return an object with the expected property "TestCoverage"' {
$Result.TestCoverage | Should Be 0
}
Expand Down
2 changes: 2 additions & 0 deletions Tests/Unit/TestData/MockObjects.json
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,8 @@
{
"NumberOfTests": {
"TotalCount": 51,
"FailedCount": 7,
"PassedCount": 44,
"CodeCoverage": {
"NumberOfCommandsAnalyzed": 27,
"NumberOfCommandsMissed": 5,
Expand Down

0 comments on commit c5a8471

Please sign in to comment.