Skip to content

Added detailed code coverage. #920

Merged
nohwnd merged 4 commits intopester:masterfrom
jonkeda:master
Dec 12, 2018
Merged

Added detailed code coverage. #920
nohwnd merged 4 commits intopester:masterfrom
jonkeda:master

Conversation

@jonkeda
Copy link
Copy Markdown
Contributor

@jonkeda jonkeda commented Oct 19, 2017

Hi mr Wyatt,

I added a switch -DetailedCodeCoverage to the Invoke-Pester command. If this switch is on then the JaCoCo codecoverage file will have additional data. Per sourcefile a line counter and each line covered or missed numbers are added to the export of de JaCoCo codecoverage file. Furthermore the lines will not be printed to the console.

The JaCoCo reader can be used to view the covered and missed percentages and show the sourcefiles with red and green line coloring.

This tool can be found here: https://visualstudiogallery.msdn.microsoft.com/14da4aa2-e833-4f1d-8765-0d3d79fd08a3?redir=0

One unittest was added to check the creation of the right data.

As an example run the following:

  1. Invoke-Pester ** -CodeCoverage Pester.psm1 -detailedcodecoverage -CodeCoverageOutputFile pestercc.xml
  2. And view the pestercc.xml with the JaCoCo Reader.

Next step is to add the code coverage reader functionality to the PoshTools.

Let me also thank you for Pester.

Kind regards,
Daan Jonkers

@it-praktyk
Copy link
Copy Markdown
Contributor

@jonkeda,
thank you for your contribution.

Please check the result of tests - your code is not compliant with the style rules defined for Pester.

@it-praktyk it-praktyk self-requested a review October 19, 2017 20:47
Copy link
Copy Markdown
Contributor

@it-praktyk it-praktyk left a comment

Choose a reason for hiding this comment

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

Please add a required help for the added parameter.

Comment thread Pester.psm1 Outdated
[ValidateSet('JaCoCo')]
[String]$CodeCoverageOutputFileFormat = "JaCoCo",

[Switch]$DetailedCodeCoverage = $false,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The newly added switch is not described in the comment based help.

…e switch is on then the CodeCoverage parameters of the Describe parts will be used for code coverage.
@jonkeda
Copy link
Copy Markdown
Contributor Author

jonkeda commented Oct 19, 2017

Fixed the style errors and added a comment on the DetailedCodeCoverage switch parameter.

Currently it fails localy on the release version tag.

Also added a -CodeCoverage parameter to the Describe function. If the DetailedCodeCoverage switch is on then the CodeCoverage files are collected by reading the parameter from the describe function.

For instance add the following to the Coverage.Tests.ps1 file:

-CodeCoverage $PSScriptRoot\Coverage.ps1

and it will cover this file also.

@scriptkiddie123
Copy link
Copy Markdown
Contributor

@jonkeda it is a bit difficult to test with test runner, as you have added an additional flag.
The way I see it you don't need a flag for extra details. The only reason the current implementation is so brief, is because I could not be bothered, to make it more detailed as TFS/VSTS did not have build in support for more. In other words, Pesters code coverage reports should always be detailed.

I have just tried to setup VSTS to build Pester with Pester Test Runner, but a lot of the test failed, so I think it will take me a couple of hours to figure out how to get a "beta" version of Pester into a VSTS build.

I have a few other projects on my todo list, but I will return this soon as it seems quite cool :-)

Copy link
Copy Markdown
Contributor Author

@jonkeda jonkeda left a comment

Choose a reason for hiding this comment

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

The change requested have been made.

@nohwnd nohwnd added this to the 4.2 milestone Nov 12, 2017
@nohwnd nohwnd removed this from the 4.3 milestone May 6, 2018
Comment thread Functions/Coverage.ps1
if ($DetailedCodeCoverage)
{

$fileName = ""
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The variable assigned but not used. Can you check why?

@ChrisLGardner
Copy link
Copy Markdown

Any reason that DetailedCodeCoverage isn't just the default output when CodeCoverageOutputFile is specified? It seems like an unnecessary switch.

I'd also suggest still outputting to the screen as it's quite handy to see at a glance what has been missed if you're not using the JaCoCo reader.

@it-praktyk
Copy link
Copy Markdown
Contributor

@ChrisLGardner,

  • because is not merged yet ;-)
  • because it's a breaking change and IMHO shouldn't be introduced without changing a major version number.

@nohwnd
Copy link
Copy Markdown
Member

nohwnd commented Sep 29, 2018

@it-praktyk Is it really a breaking change? I haven't tested it yet. But to me the switch also seems unnecessary. @ChrisLGardner have you tried it? I don't have experience with the jacoco format? Can we make the detailed format the default, or would it break existing builds?

@ChrisLGardner
Copy link
Copy Markdown

ChrisLGardner commented Sep 29, 2018 via email

@nohwnd
Copy link
Copy Markdown
Member

nohwnd commented Sep 29, 2018

@ChrisLGardner would be great if you could test it a bit more 👍

@nohwnd nohwnd merged commit ac0ccb1 into pester:master Dec 12, 2018
@nohwnd
Copy link
Copy Markdown
Member

nohwnd commented Dec 12, 2018

@jonkeda Thanks I merged it as is, if we figure out the change is not breaking I will just make it the default without the -DetailedCodeCoverage option. 😊

@nitinkshirsagar
Copy link
Copy Markdown

After generating coverage report XML file for pester tests, How to publish jacoco report on jenkins ?

@nohwnd
Copy link
Copy Markdown
Member

nohwnd commented Dec 13, 2018

@nitinkshirsagar I haven't worked with Jenkins in few years, but I would say you need a plugin, such as this one, and give it path or wildcarded path to your code coverage report.

Thilas pushed a commit to Thilas/Pester that referenced this pull request Dec 29, 2018
Thilas pushed a commit to Thilas/Pester that referenced this pull request Dec 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants