Skip to content

Request for log_property functionality for xunit writer #3944

Closed

Description

@MrKevinWeiss

I would like to request a log property capability in order to story key values in the xunit output.

Reasoning

The output.xml is very verbose and makes it a bit of a challenge when wanting use just some test results with benchmarks.
xunit (or junit) provides a nice standard way of viewing only the test result (pass, fail, skip) and does allow for key values to be stored in properties.

Background

It seems like pytest supports record_property.
Many junit/xunit schemas include this in.
We currently are doing post processing on the output.xml file and have wrapper keyword using LOG

Example of xunit with properties
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
   <testsuite name="JUnitXmlReporter" errors="0" tests="0" failures="0" time="0" timestamp="2013-05-24T10:23:58" />
   <testsuite name="JUnitXmlReporter.constructor" errors="0" skipped="1" tests="3" failures="1" time="0.006" timestamp="2013-05-24T10:23:58">
      <properties>
         <property name="java.vendor" value="Sun Microsystems Inc." />
         <property name="compiler.debug" value="on" />
         <property name="project.jdk.classpath" value="jdk.classpath.1.6" />
      </properties>
      <testcase classname="JUnitXmlReporter.constructor" name="should default path to an empty string" time="0.006">
         <failure message="test failure">Assertion failed</failure>
      </testcase>
      <testcase classname="JUnitXmlReporter.constructor" name="should default consolidate to true" time="0">
         <skipped />
      </testcase>
      <testcase classname="JUnitXmlReporter.constructor" name="should default useDotNotation to true" time="0" />
   </testsuite>
</testsuites>

Thanks to https://stackoverflow.com/questions/4922867/what-is-the-junit-xml-format-specification-that-hudson-supports

Meat and Potatos

  • Is this feature something that fits in with the Robot Framework mentality?
  • Is there an alternative that allows simple test results with process values in some standard (or at least according to a schema) way?
  • Is there anyone else interested in having this features?
  • Is there anyone willing to work and provide this features?
  • If nobody wants to provide this, what are the chances of an external contributor (myself) getting something like this in?

Formalities

Thanks for taking the time to look into this.

Activity

  1. MrKevinWeiss commented on Apr 22, 2021

    @MrKevinWeiss
    Author

    ping @ozfox

  2. thuibr commented on May 14, 2021

    @thuibr

    I am interested. I would want to be able to modify properties on both testsuite and testcase. In addition to record_property, I would want something like Pytest's record_testsuite_property.

  3. thuibr commented on May 14, 2021

    @thuibr

    @MrKevinWeiss isn't record_property meant to be used on testcase not testsuite? I think that record_testsuite_property is meant for testsuite. Additionally, to prevent Pytest from generating a warning, I need to specify junit_family = "xunit1" instead of xunit2. I am not sure if that will matter for Robot Framework.

  4. MrKevinWeiss commented on May 14, 2021

    @MrKevinWeiss
    Author

    @MrKevinWeiss isn't record_property meant to be used on testcase not testsuite?

    Yup, it seems a copy pasta error, I do in fact want record_property in the testcase for benchmarks. Our real case might be a bit hard to read so I shortend it.

    Details
    <testsuite errors="0" failures="0" name="tests_xtimer_benchmarks" skipped="0" tests="8" time="260.863">
    <testcase classname="tests_xtimer_benchmarks.Timer Version" name="Save Timer Version" time="3.181">
    <properties>
    <property name="timer-version" value="xtimer"/>
    ...
    </properties>
    ...
    </testcase>
    <testcase classname="tests_xtimer_benchmarks.Timer Overhead" name="Measure GPIO" time="12.968">
    <properties>
    <property name="overhead-00-gpio" value="[0, 5.839999999979195e-07, 0.0010134029999999995, 5.830000000019153e-07, 0.0010135419999999992, 5.68999999998876e-07, 0.0010135420000000027, 5.68999999998876e-07, 0.0010135419999999992, 5.68999999998876e-07, 0.0010135560000000023, 5.68999999998876e-07, 0.0010135419999999992, 5.690000000023454e-07, 0.0010135419999999992, 5.68999999998876e-07, 0.0010135560000000023, 5.68999999998876e-07, 0.0010135419999999992, 5.70000000001819e-07, 0.0010135409999999997, 5.699999999983496e-07, 0.0010135409999999997, 5.839999999979195e-07, 0.0010135409999999997, 5.700000000052885e-07, 0.0010135409999999997, 5.699999999983496e-07, 0.0010135419999999992, 5.68999999998876e-07, 0.0010135559999999988, 5.690000000058149e-07, 0.0010135419999999992, 5.68999999998876e-07, 0.0010135419999999992, 5.68999999998876e-07, 0.0010135419999999992, 5.829999999984459e-07, 0.0010135420000000062, 5.68999999998876e-07, 0.0010135419999999992, 5.68999999998876e-07, 0.0010135419999999992, 5.829999999984459e-07, 0.0010135419999999992, 5.700000000052885e-07, 0.0010135409999999997, 5.699999999983496e-07, 0.0010135409999999997, 5.699999999983496e-07, 0.0010135549999999993, 5.700000000052885e-07, 0.0010135409999999997, 5.699999999983496e-07, 0.0010135419999999992, 5.68999999998876e-07, 0.0010135419999999992, 5.829999999984459e-07, 0.0010135420000000062, 5.68999999998876e-07, 0.0010135419999999992, 5.68999999998876e-07, 0.0010135419999999992, 5.68999999998876e-07, 0.0010135559999999988, 5.690000000058149e-07, 0.0010135419999999992, 5.68999999998876e-07, 0.0010135419999999992, 5.699999999983496e-07, 0.0010135549999999993, 5.700000000052885e-07, 0.0010135409999999997, 5.699999999983496e-07, 0.0010135409999999997, 5.699999999983496e-07, 0.0010135409999999997, 5.839999999979195e-07, 0.0010135409999999997, 5.700000000052885e-07, 0.0010135419999999992, 5.68999999998876e-07, 0.0010135419999999992, 5.829999999984459e-07, 0.0010135420000000062, 5.689999999919371e-07, 0.0010135420000000062, 5.689999999919371e-07, 0.0010135420000000062, 5.690000000058149e-07, 0.0010135419999999923, 5.829999999984459e-07, 0.0010135420000000062, 5.689999999919371e-07, 0.0010135420000000062, 5.700000000052885e-07, 0.0010135409999999928, 5.839999999979195e-07, 0.0010135410000000067, 5.699999999914107e-07]"/>
    <property name="overhead-00-gpio" value="[0, 5.68999999998876e-07, 0.001013987000000001, 5.68999999998876e-07, 0.0010135419999999992, 5.690000000023454e-07, 0.0010135419999999992, 5.829999999984459e-07, 0.0010135419999999992, 5.690000000023454e-07, 0.0010135419999999992, 5.68999999998876e-07, 0.0010135420000000027, 5.68999999998876e-07, 0.0010135559999999988, 5.690000000023454e-07, 0.0010135419999999992, 5.699999999983496e-07, 0.0010135409999999997, 5.70000000001819e-07, 0.0010135549999999993, 5.70000000001819e-07, 0.0010135409999999997, 5.699999999983496e-07, 0.0010135409999999997, 5.70000000001819e-07, 0.0010135549999999993, 5.699999999983496e-07, 0.0010135420000000027, 5.68999999998876e-07, 0.0010135419999999992, 5.68999999998876e-07, 0.0010135560000000023, 5.68999999998876e-07, 0.0010135419999999992, 5.68999999998876e-07, 0.0010135419999999992, 5.690000000058149e-07, 0.0010135419999999992, 5.829999999984459e-07, 0.0010135419999999992, 5.68999999998876e-07, 0.0010135419999999992, 5.700000000052885e-07, 0.0010135409999999997, 5.839999999979195e-07, 0.0010135409999999997, 5.699999999983496e-07, 0.0010135409999999997, 5.699999999983496e-07, 0.0010135409999999997, 5.700000000052885e-07, 0.0010135549999999993, 5.699999999983496e-07, 0.0010135419999999992, 5.68999999998876e-07, 0.0010135419999999992, 5.690000000058149e-07, 0.0010135559999999988, 5.68999999998876e-07, 0.0010135419999999992, 5.68999999998876e-07, 0.0010135419999999992, 5.68999999998876e-07, 0.0010135420000000062, 5.829999999984459e-07, 0.0010135419999999992, 5.68999999998876e-07, 0.0010135419999999992, 5.699999999983496e-07, 0.0010135409999999997, 5.840000000048584e-07, 0.0010135409999999997, 5.699999999983496e-07, 0.0010135409999999997, 5.699999999983496e-07, 0.0010135409999999997, 5.840000000048584e-07, 0.0010135409999999997, 5.699999999983496e-07, 0.0010135419999999992, 5.68999999998876e-07, 0.0010135419999999992, 5.68999999998876e-07, 0.0010135560000000057, 5.68999999998876e-07, 0.0010135419999999992, 5.68999999998876e-07, 0.0010135419999999992, 5.68999999998876e-07, 0.0010135560000000057, 5.68999999998876e-07, 0.0010135419999999992, 5.68999999998876e-07, 0.0010135419999999992, 5.700000000052885e-07, 0.0010135409999999928, 5.839999999979195e-07, 0.0010135410000000067, 5.699999999914107e-07]"/>
    <property name="hil-10-wakeup-time" value="[0.03236975, 0.042367625, 0.052368736, 0.062369889, 0.072371014, 0.082372167, 0.092373278, 0.102374458, 0.112375556, 0.122376736, 0.132377847, 0.142379, 0.152380111, 0.162381278, 0.172382389, 0.182383556, 0.192384667, 0.202385861, 0.212386944, 0.222388111, 0.232389222, 0.242390403, 0.2523915, 0.262392722, 0.272393833, 0.282394972, 0.292396056, 0.302397236, 0.312398333, 0.322399514, 0.332400611, 0.342401792, 0.352402903, 0.362404069, 0.372405181, 0.382406361, 0.392407444, 0.402408639, 0.412409736, 0.422410903, 0.432412014, 0.442413181, 0.452414306, 0.462415486, 0.472416569, 0.48241775, 0.492418847, 0.502420028, 0.512421125, 0.522422306, 0.532423403, 0.542424583, 0.552425694, 0.562426861, 0.572427972, 0.582429139, 0.592430264, 0.602431431, 0.612432542, 0.622433708, 0.632434806, 0.642435986, 0.652437083, 0.662438264, 0.672439403, 0.682440556, 0.692441653, 0.702442875, 0.712443903, 0.722445083, 0.732446181, 0.742447361, 0.752448472, 0.762449625, 0.772450708, 0.782451889, 0.792453, 0.802454153, 0.81245525, 0.822456417, 0.832457569, 0.842458681, 0.852459778, 0.862460958, 0.872462097, 0.882463236, 0.892464375, 0.9024655, 0.912466583, 0.922467778, 0.932468861, 0.942470028, 0.952471139, 0.962472306, 0.972473389, 0.982474556, 0.992475653, 1.002476875, 1.012477931, 1.022479111] # exclude start event"/>
    ...
    </properties>
    ...
    </testcase>
    ...
    </testsuite>

    Here we are saving benchmarks with the test.

    Having both would be nice, but I imagine updating the required xunit version would be a bit much.

    It also seems like this request did not gain much attention...

  5. thuibr commented on May 14, 2021

    @thuibr

    I see. Thanks for the update. Yes, it's not looking like there is much interest. Perhaps I should take the same approach that you did and parse the output.xml for information. I like your idea of using LOG. That would be good for information that you want to record at runtime. I need to record requirement ids. I was thinking that I'd using tags for that.

  6. MrKevinWeiss commented on May 14, 2021

    @MrKevinWeiss
    Author

    If there is a way around parsing the log I would recommend it. We just didn't want to touch anything. Probably the best would be to use a fork of RF that allows that so you can catch them in the code. Here is what we have. It looks like you already found the log (this was needed due to truncation of data in the output.xml)

  7. thuibr commented on May 17, 2021

    @thuibr

    Before I found this GitHub issue, I posted a forum question. I received a reply suggesting that an xunit file could be generated by using the listener interface. For my particular problem, I am going to try something else for now, but I may try this approach later. I thought that it might be a useful suggestion to pass along to you.

  8. MrKevinWeiss commented on May 18, 2021

    @MrKevinWeiss
    Author

    @thuibr Thanks, that probably is a better approach.

  9. thuibr commented on May 18, 2021

    @thuibr

    @MrKevinWeiss I changed my mind and decided to take a look at the Listener interface. I think that this is going to end up being easier than we thought. There is an xunit_file method that is called when the xunit file is ready. Through experimentation, I found out that the xunit file has already been written when this method is called. I plan to save off the data that I need to a class field using the end_test method then read, modify, and write the xunit file. I am using the Python junitparser package for this:

    """Listener that modifies an xunit file with custom properties."""
    from junitparser import JUnitXml, TestCase, TestSuite
    
    
    class XUnitListener:
        ROBOT_LISTENER_API_VERSION = 3
    
        def __init__(self):
            # Add some class field here
            pass
    
        def end_test(self, data, result):
            # Save data to some class field
            pass
    
        def xunit_file(self, path):
            # Read file that was just written
            xml = JUnitXml.fromfile(path)
    
            # For test suite:
            #     Add property
            #     For test case:
            #        Add property
    
            # Write back to file
            xml.write(path)
  10. pekkaklarck commented on Sep 1, 2021

    @pekkaklarck
    Member

    Adding more information to xunit outputs is definitely possible. I actually mentioned preperties along with timestamps (see issue #4072 linked above) in my last comment to #2982 that covers making the suite structure in xunit outputs nested.

    The biggest problem with making changes to xunit outputs is that there's no official schema for them. Due to that, our changes may break external tools that aren't expecting certain element or attributes. That's why I'd like to restrict these changes to major versions and would really appreciate if community members would test changes using different tools processing xunit outputs. We are now just about to start RF 5.0 development so now is a great time to get this change in! This is especially true because I'd like to get the aforementioned #2982 and #4074 into that release as well. Less work to test xunit outputs after all these changes than after each change separately.

    Could people interested in adding properties to xunit outputs explain what properties exactly you'd like to see? Once we agree on what to add, implementation ought to be really easy. External contributions would be appreciated! I'd be happy to review PRs and help also otherwise if needed.

  11. MrKevinWeiss commented on Sep 2, 2021

    @MrKevinWeiss
    Author

    The properties was more of a workaround for adding "useful" key/values (parsing through the logs is not that straightforward).
    We currently use it to record benchmarks that we can use for show graphs of test results.
    Things like calibration values would also be pretty useful to have in the test reports (simply pass/fail is not enough).

    Just my 2 cents...

    I don't know if I will have time to do any PRs, maybe in November I can take another look into it. I can do some V5 testing though to see how seamless it fits into our stuff.

    Thanks for looking into this @pekkaklarck

  12. pekkaklarck commented on Sep 16, 2021

    @pekkaklarck
    Member

    With suites we could simply use properties to record our suite metadata. Possibly also suite documentation if there isn't better place for in in xunit files.

  13. rikerfi commented on Dec 3, 2021

    @rikerfi
    Contributor

    Just made a fast tryout for XUnit output with properties. I place here a simple test script and XUnit output generated from it. It supports static properties as well as dynamic properties for suite. I am thinking, if test case properties are needed then above mentioned listener approach will do the job. What you think?

    *** Settings ***
    Metadata    SimpleVersion    2.0  # static
    
    *** Test Cases ***
    Let's Test Some Nop
        No Operation
    
    Metadata To XUnit Property
        ${data} =    What Time Is It
        Set Suite Metadata    ${TEST_NAME}:Time    ${data}  # dynamic
        Log    This Is My Dear Log
    
    *** Keywords ***
    What Time Is It
        ${wrapped_time} =  Get Time
        [Return]  ${wrapped_time}
    
    <?xml version="1.0" encoding="UTF-8"?>
    <testsuite name="Try" tests="2" errors="0" failures="0" skipped="0" time="0.026" timestamp="2021-12-03T14:16:18.664000">
        <testcase classname="Try" name="Let's Test Some Nop" time="0.001">
        </testcase>
        <testcase classname="Try" name="Metadata To XUnit Property" time="0.004">
        </testcase>
        <properties>
            <property name="Metadata To XUnit Property:Time" value="2021-12-03 14:16:18"/>
            <property name="SimpleVersion" value="2.0"/>
        </properties>
    </testsuite>
    
  14. pekkaklarck commented on Dec 7, 2021

    @pekkaklarck
    Member

    Mapping suite metadata to properties sounds good to me. Do xunit outputs have generic documentation? If not, perhaps we could add a property Documentation or possibly __doc__ that contains it?

  15. rikerfi commented on Dec 8, 2021

    @rikerfi
    Contributor

    We have a very simple generic documentation for xunit output within XUnitFileWriter class. Definitely we should improve that one. There are possibilities to add a generic xunit documentation to a property, but also provide suite documentation as well.

    I'll provide a draft PR to us play around the idea.

  16. rikerfi commented on Dec 8, 2021

    @rikerfi
    Contributor

    Above draft PR should output something like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <testsuite name="Try" tests="2" errors="0" failures="0" skipped="0" time="0.023" timestamp="2021-12-08T14:32:00.486000">
        <testcase classname="Try" name="Let's Test Some Nop" time="0.001">
        </testcase>
        <testcase classname="Try" name="Metadata To XUnit Property" time="0.004">
        </testcase>
        <properties>
            <property name="Suite Documentation" value="Demonstrate suite metadata to XUnit property element."/>
            <property name="Let's Test Some Nop:Nop" value="Hello NOP"/>
            <property name="Metadata To XUnit Property:Clock" value="2021-12-08 14:32:00"/>
            <property name="SimpleVersion" value="2.0"/>
            <property name="XUnit Documentation" value="Provides an xUnit-compatible result file.&#10;&#10;    Attempts to adhere to the de facto schema guessed by Peter Reilly, see:&#10; http://marc.info/?l=ant-dev&amp;m=123551933508682&#10;    "/>
        </properties>
    </testsuite>
    

    and related test script:

    *** Settings ***
    Documentation    Demonstrate suite metadata to XUnit property element.
    Metadata    SimpleVersion    2.0
    
    *** Test Cases ***
    Let's Test Some Nop
        Set Suite Metadata    ${TEST_NAME}:Nop    Hello NOP
        No Operation
    
    Metadata To XUnit Property
        ${data} =    What Time Is It
        Set Suite Metadata    ${TEST_NAME}:Clock    ${data}
        Log    This Is My Dear Log
    
    *** Keywords ***
    What Time Is It
        ${wrapped_time} =  Get Time
        [Return]  ${wrapped_time}
    
  17. pekkaklarck commented on Jan 21, 2022

    @pekkaklarck
    Member

    We decided to add existing suite documentation and metadata as properties to xUnit outputs and I submitted new issue (#4199) abou that. We considered that better than having a way to add some custom properties only to xUnit outputs like this issue initially proposed. A benefit of using existing documentation and metadata is that there are many existing ways to set them. Both can be specified directly in data, given from the command line (only for top level suite), and there are keywords for modifying them during execution.

    Although the exact enhancement proposed by this issue won't be implemented, this issue was the motivation for #4199 that hopefully serves the same purpose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions