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

Update NUnitXml.xslt to emit properties element before reason/failure #1797

Merged
merged 1 commit into from Aug 22, 2018

Conversation

akoeplinger
Copy link
Contributor

The NUnit 2.5 schema at http://nunit.org/files/testresult_schema_25.txt specifies
that the test-case element should look like this:

<xs:complexType name="test-caseType">
    <xs:sequence>
        <xs:element name="categories" type="categoriesType" minOccurs="0" maxOccurs="1" />
        <xs:element name="properties" type="propertiesType" minOccurs="0" maxOccurs="1" />
        <xs:choice>
            <xs:element name="failure" type="failureType" minOccurs="0" />
            <xs:element name="reason" type="reasonType" minOccurs="0" />
        </xs:choice>
    </xs:sequence>
    <xs:attribute name="name" type="xs:string" use="required" />
    ...

The usage of xs:sequence means categories, properties and failure/reason elements
need to be emitted in exactly that order.

Currently NUnitXml.xslt however emits the properties after the reason element.

This fixes the xslt to emit properties in the expected order.


We noticed this because (for reasons ...) we emit xunit test results in NUnit format and parse it with the popular Jenkins xunit plugin (name similarity is just coincidence, the plugin supports multiple xml formats). That plugin had an update where it enforced the NUnit schema more stringently than before and this broke the parsing:

WARNING: At line 7609 of file:/home/builder/jenkins/workspace/test-mono-mainline-2018-04/label/debian-9-arm64/mcs/class/corlib/TestResult-net_4_x-xunit.xml:
  cvc-complex-type.2.4.d: Invalid content was found starting with element 'properties'. No child element is expected at this point.

It'd be nice if this could make the 2.4.1 release.

The NUnit 2.5 schema at http://nunit.org/files/testresult_schema_25.txt specifies
that the test-case element should look like this:

```xml
<xs:complexType name="test-caseType">
    <xs:sequence>
        <xs:element name="categories" type="categoriesType" minOccurs="0" maxOccurs="1" />
        <xs:element name="properties" type="propertiesType" minOccurs="0" maxOccurs="1" />
        <xs:choice>
            <xs:element name="failure" type="failureType" minOccurs="0" />
            <xs:element name="reason" type="reasonType" minOccurs="0" />
        </xs:choice>
    </xs:sequence>
    <xs:attribute name="name" type="xs:string" use="required" />
    ...
```

The usage of xs:sequence means categories, properties and failure/reason elements
need to be emitted in exactly that order.

Currently NUnitXml.xslt however emits the properties _after_ the reason element.

This fixes the xslt to emit properties in the expected order.
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this pull request Aug 22, 2018
Context: https://jenkins.mono-project.com/job/xamarin-android-pr-builder/3806
Context: xunit/xunit#1797

Our on-device XUnit tests don't appear to be reporting properly in
Jenkins:

    WARNING: The result file '/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/TestResult-Xamarin.Android.Bcl_Tests.nunit-Debug.xml' for the metric 'NUnit' is not valid. The result file has been skipped.
    WARNING: The file '/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/TestResult-Xamarin.Android.Bcl_Tests.xunit-Debug.xml' is an invalid file.
    WARNING: At line 36993 of file:/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/TestResult-Xamarin.Android.Bcl_Tests.xunit-Debug.xml:cvc-complex-type.2.4.d: Invalid content was found starting with element 'properties'. No child element is expected at this point.
    WARNING: At line 37006 of file:/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/TestResult-Xamarin.Android.Bcl_Tests.xunit-Debug.xml:cvc-complex-type.2.4.d: Invalid content was found starting with element 'properties'. No child element is expected at this point.

@akoeplinger also has a patch for the XLST transforms in XUnit.

Hopefully this fixes all of our on-device tests!
@bradwilson bradwilson merged commit aa79468 into xunit:v2 Aug 22, 2018
@bradwilson
Copy link
Member

Thanks!

@akoeplinger akoeplinger deleted the fix-nunit-properties-order branch August 22, 2018 15:49
grendello pushed a commit to xamarin/xamarin-android that referenced this pull request Aug 22, 2018
* [Xamarin.Android.NUnitLite] don't omit empty <categories />

Context: https://jenkins.mono-project.com/job/xamarin-android-pr-builder/3806
Context: mono/NUnitLite#12

Our on-device tests don't appear to be reporting properly in Jenkins:

    INFO: Starting to record.
    INFO: Processing NUnit-2.x (default)
    INFO: [NUnit-2.x (default)] - 16 test report file(s) were found with the pattern 'xamarin-android/TestResult-*.xml' relative to '/Users/builder/jenkins/workspace/xamarin-android-pr-builder' for the testing framework 'NUnit-2.x (default)'.
    WARNING: The file '/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/TestResult-Xamarin.Android.Bcl_Tests.nunit-Debug.xml' is an invalid file.
    WARNING: At line 7 of file:/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/TestResult-Xamarin.Android.Bcl_Tests.nunit-Debug.xml:cvc-complex-type.2.4.b: The content of element 'categories' is not complete. One of '{category}' is expected.

Followed by thousands of similar warnings...

Apparently the latest Jenkins plugin for NUnit tests is more strict
about the test result format. We can add the patch from @akoeplinger
to prevent these empty `<categories />` from being omitted.

Hopefully this fixes it!

* [TestRunner.xUnit] reorder when <properties /> emitted

Context: https://jenkins.mono-project.com/job/xamarin-android-pr-builder/3806
Context: xunit/xunit#1797

Our on-device XUnit tests don't appear to be reporting properly in
Jenkins:

    WARNING: The result file '/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/TestResult-Xamarin.Android.Bcl_Tests.nunit-Debug.xml' for the metric 'NUnit' is not valid. The result file has been skipped.
    WARNING: The file '/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/TestResult-Xamarin.Android.Bcl_Tests.xunit-Debug.xml' is an invalid file.
    WARNING: At line 36993 of file:/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/TestResult-Xamarin.Android.Bcl_Tests.xunit-Debug.xml:cvc-complex-type.2.4.d: Invalid content was found starting with element 'properties'. No child element is expected at this point.
    WARNING: At line 37006 of file:/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/TestResult-Xamarin.Android.Bcl_Tests.xunit-Debug.xml:cvc-complex-type.2.4.d: Invalid content was found starting with element 'properties'. No child element is expected at this point.

@akoeplinger also has a patch for the XLST transforms in XUnit.

Hopefully this fixes all of our on-device tests!
grendello pushed a commit to xamarin/xamarin-android that referenced this pull request Aug 22, 2018
* [Xamarin.Android.NUnitLite] don't omit empty <categories />

Context: https://jenkins.mono-project.com/job/xamarin-android-pr-builder/3806
Context: mono/NUnitLite#12

Our on-device tests don't appear to be reporting properly in Jenkins:

    INFO: Starting to record.
    INFO: Processing NUnit-2.x (default)
    INFO: [NUnit-2.x (default)] - 16 test report file(s) were found with the pattern 'xamarin-android/TestResult-*.xml' relative to '/Users/builder/jenkins/workspace/xamarin-android-pr-builder' for the testing framework 'NUnit-2.x (default)'.
    WARNING: The file '/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/TestResult-Xamarin.Android.Bcl_Tests.nunit-Debug.xml' is an invalid file.
    WARNING: At line 7 of file:/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/TestResult-Xamarin.Android.Bcl_Tests.nunit-Debug.xml:cvc-complex-type.2.4.b: The content of element 'categories' is not complete. One of '{category}' is expected.

Followed by thousands of similar warnings...

Apparently the latest Jenkins plugin for NUnit tests is more strict
about the test result format. We can add the patch from @akoeplinger
to prevent these empty `<categories />` from being omitted.

Hopefully this fixes it!

* [TestRunner.xUnit] reorder when <properties /> emitted

Context: https://jenkins.mono-project.com/job/xamarin-android-pr-builder/3806
Context: xunit/xunit#1797

Our on-device XUnit tests don't appear to be reporting properly in
Jenkins:

    WARNING: The result file '/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/TestResult-Xamarin.Android.Bcl_Tests.nunit-Debug.xml' for the metric 'NUnit' is not valid. The result file has been skipped.
    WARNING: The file '/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/TestResult-Xamarin.Android.Bcl_Tests.xunit-Debug.xml' is an invalid file.
    WARNING: At line 36993 of file:/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/TestResult-Xamarin.Android.Bcl_Tests.xunit-Debug.xml:cvc-complex-type.2.4.d: Invalid content was found starting with element 'properties'. No child element is expected at this point.
    WARNING: At line 37006 of file:/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/TestResult-Xamarin.Android.Bcl_Tests.xunit-Debug.xml:cvc-complex-type.2.4.d: Invalid content was found starting with element 'properties'. No child element is expected at this point.

@akoeplinger also has a patch for the XLST transforms in XUnit.

Hopefully this fixes all of our on-device tests!
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.

None yet

2 participants