Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve export #1210

Closed
wants to merge 1 commit into from
Closed

Improve export #1210

wants to merge 1 commit into from

Conversation

gnuechtel
Copy link
Contributor

This pull requests improves the export of Pester test results.

I am opening this pull request because of the following comments:

(both from PR #1186)

The code has the following characteristics:

  • It creates a test report object wich contains a tree of test results which are suitable for the export in different formats
  • 99 percent of the code is equal for PSpec and Gherkin
  • It refactors the existing NUnit export with maintenance in mind
  • Also it fixes some NUnit report bugs for Gherkin
  • It introduced a shared test code module for XML tests (which will be removed on release)

Also, I carefully compared the output of my changes with the last output of the master.
It is the same (without time values).

I am still convinced, that Pester should support a small amount of some standard outputs say like Cucumber.

I think the following formats would be fine:

  • NUnit 2
  • Nunit 3
  • HTML (single page)
  • JSON (for tools like Donut)

More output formats could be provided as extra modules.

The following issues/pull requests I have been found about output/NUnit results.

Hopefully I'm not too overwhelming.
The code I have been provided can be uses as it is.
Or can used as starting point of discussion about the topic.

By the way: the object which is returned by passthru parameter seems not to be sufficient for me so I used the internal Pester state object.

Please give feedback to the code!
I would highly appreciate suggestions for improvements!

- 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
@nohwnd
Copy link
Member

nohwnd commented Jan 14, 2019

@cgnuechtel Thanks for the PR, it will take me some time to reivew it.

@clcaldwell
Copy link
Contributor

@cgnuechtel

I am not sure if this was intentional - but there is some interesting behavior you have introduced now that -OutputFormat is [string[]] .

Invoke-Pester -Path .\UnitTests\ -OutputFormat NUnitXml,html -OutputFile .\tmp\results.xml
Creates the result.xml, but ignores the html report.

Invoke-Pester -Path .\UnitTests\ -OutputFormat NUnitXml,html -OutputFile results.xml,result.html
Creates both files, as expected.

Invoke-Pester -Path .\UnitTests\ -OutputFormat NUnitXml,html -OutputFile results.html,result.xml
And
Invoke-Pester -Path .\UnitTests\ -OutputFormat html,NUnitXml -OutputFile results.xml,result.html
Creates both files, but the contents are switched (xml results in html <> html results in xml).

Similarly:
Invoke-Pester -Path .\UnitTests\ -OutputFormat NUnitXml -OutputFile results.html
Creates the xml file, but outputs html results into it.

So, I guess the question is: If you are going to offer multiple output formats, should you validate that the results are getting written into a valid file - or do some correction for mis-orded inputs on -OutputFile?

@gnuechtel
Copy link
Contributor Author

@clcaldwell As I remember, that was intended. The output file is just a name and has no special checks.

@nohwnd Any plans to include this pull request or is it outdated now?

@clcaldwell
Copy link
Contributor

@cgnuechtel Just to clarify what I mean with this:
If -OutputFormat only accepts 1 value, it would make sense to just output into whatever file is given (as the current behavior is). However, now that you are accepting a collecting of strings as input (in this PR), the outputs are no longer intuitive.

@nohwnd
Copy link
Member

nohwnd commented May 15, 2021

Thank your for the PR, as I said in my previous comments, I am not very interested in adding another output because I would have to support it in the future. Please feel free publishing this on your own as a module.

@nohwnd nohwnd closed this May 15, 2021
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