Skip to content

Export test results to HTML#1186

Closed
gnuechtel wants to merge 9 commits into
pester:masterfrom
gnuechtel:HtmlReport
Closed

Export test results to HTML#1186
gnuechtel wants to merge 9 commits into
pester:masterfrom
gnuechtel:HtmlReport

Conversation

@gnuechtel
Copy link
Copy Markdown
Contributor

@gnuechtel gnuechtel commented Dec 28, 2018

  • Support additional output format HTML for Invoke-Pester and Invoke-Gherkin
  • Count total, passed, inconclusive and failed results by three groups
    • Files/Groups/Specs for Pester Specs
    • Features/Scenarios/Steps for Gherkin
  • Include summary of information like PowerShell version, date/time, culture info, operation system or duration
  • Internally use XSLT script NUnitXml-html.xslt to transform NUnit XML to HTML
  • Export Convert-Report cmdlet to allow conversion of already created XML files
  • HTML output is also XHTML to allow easier testing
  • Add extensive tests for Gherkin HTML reports
  • Add smaller set of tests for PSpec HTML reports which should be sufficient
  • Changes should be backward compatible since string parameters for output file and format were replaced by string[]

Share XML test code

  • Store it in Functions/TestUtilities/Xml.ps1
  • Use it in Gherkin.Tests.ps1 and TestResults.Tests.ps1
  • Remove it before release in cleanUpBeforeBuild.ps1

- Support additional output format HTML for Invoke-Pester and Invoke-Gherkin
- Count total, passed, inconclusive and failed results by three groups
  * Files/Groups/Specs for Pester Specs
  * Features/Scenarios/Steps for Gherkin
- Include summary of information like PowerShell version, date/time, culture info, operation system or duration
- Internally use XSLT script NUnitXml-html.xslt to transform NUnit XML to HTML
- Export Convert-Report cmdlet to allow conversion of already created XML files
- HTML output is also XHTML to allow easier testing
- Add extensive tests for Gherkin HTML reports
- Add smaller set of tests for PSpec HTML reports which should be sufficient
- Changes should be backward compatible since string parameters for output file and format were replaced by string[]

Share XML test code

- Store it in Functions/TestUtilities/Xml.ps1
- Use it in Gherkin.Tests.ps1 and TestResults.Tests.ps1
- Remove it before release in cleanUpBeforeBuild.ps1
@gnuechtel
Copy link
Copy Markdown
Contributor Author

This pull request adds a new output format HTML.

There are two unclear things with the code:

  • the inclusion of shared XML test code
  • the location of the used XSLT script

Any advice is welcome!

@gnuechtel
Copy link
Copy Markdown
Contributor Author

gnuechtel commented Dec 28, 2018

Example report (clipped)

image

@gnuechtel
Copy link
Copy Markdown
Contributor Author

gnuechtel commented Dec 28, 2018

Another example (Gherkin)

image

@nohwnd nohwnd self-assigned this Dec 29, 2018
@nohwnd
Copy link
Copy Markdown
Member

nohwnd commented Jan 3, 2019

@cgnuechtel I like the functionality, but it has very thin connection to Pester itself, because it depends on the NUnit schema. So I am thinking if this should be included in Pester or not, and I am so far leaning more towards not merging this. That said I like the code, I like how it looks, I just don't know if I want to be stuck supporting this for the next 10 years.

Have you considered publishing this as a separate module?

@gnuechtel
Copy link
Copy Markdown
Contributor Author

@cgnuechtel I like the functionality, but it has very thin connection to Pester itself, because it depends on the NUnit schema. So I am thinking if this should be included in Pester or not, and I am so far leaning more towards not merging this. That said I like the code, I like how it looks, I just don't know if I want to be stuck supporting this for the next 10 years.

I am with you at this point that the dependency to NUnit XML should be removed.
For example, if Pester switches to NUnit 3 format, the HTML output would be broken.
(Which would not be very problematic since there are HTML output tests.)
Furthermore I have to admit, that Export-PesterResults is too long now and has too much functions which should be separated.

Though the HTML is pretty simple. And XSLT is not so bad as some people may think.
But from the maintenance point of view it could be a little bit difficult.

I suggest one of the following options to remove the dependency of NUnit XML format:

  1. Create an intermediate XML format for Pester and adjust the XSLT
  2. Directly write HTML in PowerShell code (in TestResults.ps1 or a similar file)

Have you considered publishing this as a separate module?

Not yet. I think a HTML report should be part of the core.
For example Cucumber has HTML output.

But in general the export should be more modular and separated by different formats.

Would that changes convince you to include HTML output into Pester core?

@fourpastmidnight
Copy link
Copy Markdown
Contributor

Just to chime in here, I think the NUnit XML output is just fine. I think the objection here is adding support, into Pester itself, for transforming that report to HTML. If my understanding of the objection is correct, I agree. There are already several formatters available which can consume the NUnit XML report and output nice HTML reports, as I mentioned on #1142, such as Pickles and DonutReport (Demo).

@fourpastmidnight
Copy link
Copy Markdown
Contributor

BTW, I also liked the work you did in this PR; I just happen to agree with @nohwnd in this case. I also think the work done here on this PR would be a valuable contribution as a module that others could use apart from, but in concert with Pester--as another option to the aforementioned formatters above.

@nohwnd
Copy link
Copy Markdown
Member

nohwnd commented Jan 4, 2019

@cgnuechtel I think you understood me the other way around. What @fourpastmidnight says is what I meant. Your code can convert any NUnit XML output, not just the output Pester produces (and that's a good thing). So your code can be shipped in it's own module without adding XSLT "dependency" to Pester. I hope it's not too disappointing :/

@nohwnd
Copy link
Copy Markdown
Member

nohwnd commented Jan 5, 2019

@cgnuechtel I am going to close this as: won't merge. I value your work on this, but I don't think it belongs into the framework. It adds yet another thing that I (or potential other maintainers) need to know and the functionality can easily be provided separately.

@nohwnd nohwnd closed this Jan 5, 2019
@gnuechtel
Copy link
Copy Markdown
Contributor Author

It is okay to close this for now.

I am considering to provide an extra module.
But I am not sure, if this makes any sense.
Because the other report tools are amazing and go far beyond this simple output.

The goal of this pull request was to provide a simple output like Cucumber does.
(Not to provide a sophisticated reporting tool.)

Cucumber also provides a JSON output (which DonutReport seems to require).

Still wondering, if the output should be more generic and not tied to just one output format.

NUnit XML is a widely accepted format by many CI servers.
Also more output formats will increase complexity.
But, I still think that a limited amount of output formats would be fine, if maintenance is easier than the code of this pull request.

If it makes sense, I will provide some code later with a more generic approach (without XSLT and separated code by output format).

But before, I will try out the reporting tools.

@fourpastmidnight
Copy link
Copy Markdown
Contributor

fourpastmidnight commented Jan 5, 2019 via email

@nohwnd
Copy link
Copy Markdown
Member

nohwnd commented Jan 5, 2019

@fourpastmidnight To discuss this further there should be another thread, but a short answer to your questions, is that in my opinion the approach that we are taking now is the way to go:

  • Have a single output format that widely used and supported by CI servers -> NUnit, and at best support two versions of it.
  • Transform the output internally from the same -PassThru object that we "publish", to make sure that the information is accessible.
  • Let people implement their transformers for the -PassThru object and try not to introduce breaking changes in it.

So all in all, I will try to keep/reduce the scope of what Pester can natively do to the crucial parts + useful stuff that 90% of the users will definitely need, and the rest of the stuff should come as a separate module. We have a powerful package delivery system provided by PSGallery, so let's use it.

@fourpastmidnight
Copy link
Copy Markdown
Contributor

fourpastmidnight commented Jan 5, 2019 via email

gnuechtel added a commit to gnuechtel/Pester that referenced this pull request Jan 12, 2019
- Fix Gherkin NUnit output: test suites with failures were reported as success
- Separate test statistics for export from display (makes code reusable between different formats)
- Support additional output format HTML for Invoke-Pester and Invoke-Gherkin
  - reincarnation of pull request pester#1186 with various improvements
    - PowerShell only code (no XSLT) in Functions/Export/Html.ps1
    - shared code (test statistics) between different formats (NUNit XML and HTML)
    - fix for parameterized test cases (were not nested correctly)
  - Count total, passed, inconclusive and failed results by three groups
  - Files/Groups/Specs for Pester Specs
  - Features/Scenarios/Steps for Gherkin
  - Include summary of information like PowerShell version, date/time, culture info, operation system or duration
  - HTML output is also XHTML to allow easier testing
  - Add extensive tests for Gherkin HTML reports
  - Add smaller set of tests for PSpec HTML reports which should be sufficient
  - Changes should be backward compatible since string parameters for output file and format were replaced by string[]
- Remove not used function Get-TestTime from TestResults.ps1

Create module for shared test code

- Create functions Get-XmlNode, Get-XmlInnerText, Get-XmlValue, Get-XmlCount and Get-NextPreText
- Store it in Functions/TestUtilities/TestUtilities.psm1
- Use it in Gherkin.Tests.ps1 and TestResults.Tests.ps1
- Remove it before release in cleanUpBeforeBuild.ps1
@gnuechtel gnuechtel mentioned this pull request Jan 12, 2019
gnuechtel added a commit to gnuechtel/Pester that referenced this pull request Jan 13, 2019
- Improve/fix NUnit output for PSpec and Gherkin

  - Reword main test suite name from 'Pester' to 'Pester Specs'/'Features'
  - Write description attribute at first position on test suites (like test cases)
  - Fix Gherkin NUnit output: test suites with failures were reported as success
  - Include feature name in full qualified names in Gherkin NUnit reports

- Add additional output format HTML for Invoke-Pester and Invoke-Gherkin

  - Reincarnation of pull request pester#1186 with various improvements
    - PowerShell only code (no XSLT) in Functions/Export/Html.ps1
    - Regard parameterized test cases (were not nested correctly)
  - Count total, passed, inconclusive and failed results by three groups
    - Files/Groups/Specs for Pester Specs
    - Features/Scenarios/Steps for Gherkin
  - Include summary of information like PowerShell version, date/time, culture info, operation system or duration
  - HTML output is also XHTML to allow easier testing
  - Add extensive tests for Gherkin HTML reports
  - Add smaller set of tests for PSpec HTML reports which should be sufficient
  - Regard HTML encoding
  - Changes should be backward compatible since string parameters for output file and format were replaced by string[]

- Refactor TestResults.ps1

  - Create test report object and pass it as top level element to NUnit and HTML export functions
  - Remove not used function Get-TestTime
  - Move NUnit specific code to Functions/Export/NUnit.ps1
  - Rename Get-NUnitGroupResult to Get-NUnitTestSuiteResult
  - Use inner functions in NUnit.ps1 to avoid repeated arguments (e.g. for XMLWriter)
  - Add new internal functions
    - New-TestReport
    - New-TestResult
    - Group-TestResult
    - New-TestResultTree
    - ConvertTo-TestResult

- Create separate module for shared test code

  - Create functions Get-XmlNode, Get-XmlInnerText, Get-XmlValue, Get-XmlCount and Get-NextPreText
  - Store it in Dependencies/TestUtilities/TestUtilities.psm1
  - Use it in Gherkin.Tests.ps1 and TestResults.Tests.ps1
  - Remove it before release in cleanUpBeforeBuild.ps1

- Add NUnit output test for correct names on all levels

- Improve Gherkin NUnit tests

  - Add expected description values for features, scenarios and steps
  - Fix expected name values for scenarios and steps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants