Repository navigation
Closed
Labels
Description
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>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.
Reacted by Tom Huibregtse
Activity
MrKevinWeiss commentedon Apr 22, 2021
ping @ozfox
thuibr commentedon May 14, 2021
I am interested. I would want to be able to modify properties on both
testsuiteandtestcase. In addition torecord_property, I would want something like Pytest's record_testsuite_property.thuibr commentedon May 14, 2021
@MrKevinWeiss isn't
record_propertymeant to be used ontestcasenottestsuite? I think thatrecord_testsuite_propertyis meant fortestsuite. Additionally, to prevent Pytest from generating a warning, I need to specifyjunit_family = "xunit1"instead ofxunit2. I am not sure if that will matter for Robot Framework.MrKevinWeiss commentedon May 14, 2021
Yup, it seems a copy pasta error, I do in fact want
record_propertyin thetestcasefor benchmarks. Our real case might be a bit hard to read so I shortend it.Details
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...
thuibr commentedon May 14, 2021
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.xmlfor information. I like your idea of usingLOG. 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.MrKevinWeiss commentedon May 14, 2021
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)
thuibr commentedon May 17, 2021
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.
MrKevinWeiss commentedon May 18, 2021
@thuibr Thanks, that probably is a better approach.
thuibr commentedon May 18, 2021
@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_filemethod 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 theend_testmethod then read, modify, and write the xunit file. I am using the Python junitparser package for this:pekkaklarck commentedon Sep 1, 2021
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.
MrKevinWeiss commentedon Sep 2, 2021
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
pekkaklarck commentedon Sep 16, 2021
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.
rikerfi commentedon Dec 3, 2021
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?
pekkaklarck commentedon Dec 7, 2021
Mapping suite metadata to properties sounds good to me. Do xunit outputs have generic documentation? If not, perhaps we could add a property
Documentationor possibly__doc__that contains it?rikerfi commentedon Dec 8, 2021
We have a very simple generic documentation for xunit output within
XUnitFileWriterclass. 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.
rikerfi commentedon Dec 8, 2021
Above draft PR should output something like this:
and related test script:
pekkaklarck commentedon Jan 21, 2022
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.