-
-
Notifications
You must be signed in to change notification settings - Fork 652
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
Junit reporter #318
Comments
Hi! About the subcases - I guess Catch2 has the same problems because they have sections - perhaps we can see how they handle that? I'd be happy if someone contributes the JUnit reporter - it should be placed in doctest.cpp right below the Currently all tests are executed twice - with the console reporter and the xml reporter - that can be seen here. The JUnit one should be added there as well (with a 3rd invocation) and a new |
@byzantic Can you post a link to your example implementation? I only require quite a limited featureset so just having the simple reporter would be fine for me. |
@onqtam I recall reading somewhere that you do not allow any imports of the standard library in doctest for compile-time reasons. Is that correct? it seems that there are some headers in EDIT: Just read the previous comments more thoroughly. I have not looked at how Catch2 handles subcases. My approach is as follows: when we hit a subcase, we stop the current test_case tag, store the test object on a stack and starts a new one corrosponding to the new subcase. When we exit a subcase we set the current testcase to the one on the top of the stack. As for the stats, I do not have a good idea ;) |
@Awia00 Sorry for the late reply - been really busy lately. The About the statistics which should be as attributes in the opening tags - I guess Catch2 buffers the results for each test case and emits the right opening tag after the test case has completely finished executing. If such an attribute is necessary for the root XML tag - then I guess everything can be buffered - we should do whatever Catch2 does in this regard. |
@onqtam While the reporter tool is wonderful for transforming output to data formats like xml or yaml, having a junit reporter in doctest is really a violation of separation of concern pattern. Junit xml is not formally defined and has many xml schema definitions to define it. Looking at Jenkins xUnit plugin (https://plugins.jenkins.io/xunit/), they went with accepting 2 Junit xml formats, but even that has cause some heartburn: https://issues.jenkins-ci.org/browse/JENKINS-52152. I would like to propose changing the roadmap to remove junit, but add a doctest xml schema definition (xsd) instead. This would allow for a clearly defined contract for downstream consumers to develop their own flavor of xml transformation. Example:
Users can lint and verify that the doctest output is valid. This helps downstream xml transform developers with troubleshooting issues (it's nice to know if the problem is on the transform side or doctest side). Now users can transform the xml using a XSL Transformations (xslt) and verify output:
This approach keeps doctest focused on doctest and not get bogged down in the discussion of what junit flavor(s) should doctest support. What are your thoughts about this approach? |
@dhoer I usually try to leave complexity outside of doctest and this approach sounds reasonable indeed, however I do think that there should be some default JUnit reporter. But it wouldn't hurt to define a schema for the XML format! Can't promise a date though... |
@onqtam I got started on looking at Junit when I had issues with getting doctest reporting to work with jenkins xunit plugin. Here is the jist of those issues: There is doctest-junit-report tool (https://github.com/ujiro99/doctest-junit-report) that takes raw output from docktest and converts it to xml . But there is a problem with the junit xml that causes the following errors:
So you will have to format the duration time to 3 decimal places, remove properties tag, and add errors attribute to testsuite element. Here is an example of calling doctest with doctest-junit-report and further formating with sed:
Now you can add a call to xunit in your Jenkins declarative pipeline script:
I started wondering if that issue would still be a problem with doctest 2.4. So I thought I would write an xslt this weekend (yes, I might have been guilty of suffering from cabin fever), but I ran into the problem of not knowing if the xml that is coming out from the code I'm working with would hold up as other users write their doctests. Having a formal xsd would help with that concern. I would even be willing to make it public for others to use and maybe work with jenkins xunit plugin peeps to get doctest officially supported in their plugin. I wish you good luck on supporting junit. I think it will be a headache since there is no formal definition of junit, only interpretations. BTW, I was pleasantly pleased how easy it was to do xslt (thanks to w3schools). I don't think that should be a problem for developers to write their own xslt, once there is a formal xsd. Especially if there is an xslt example for them to use. |
@onqtam are you planning to target a specific flavor of junit like ant-junit (https://github.com/windyroad/JUnit-Schema/blob/master/JUnit.xsd) or surefire (http://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd)? |
@dhoer I haven't thought about it yet - I'll most likely mimic what Catch2 is doing though... |
@onqtam thanks for the information. I started working with surefire since that is what jenkins xunit ingested doctest-junit-report output as. But then I realized that ant junit would be more appropriate. It seems that catch2 is using that as well. Here is the xsl that I started working on: https://github.com/dhoer/doctest-cpp-to-ant-junit. I wonder if I can be selfish and ask if doctest xml could be extended to include timestamp, errors, failures, and skipped attributes for testsuite element. It would make the transform logic cleaner and simpler. |
@dhoer I would love to, but I really don't have the capacity in the near term, so I wouldn't expect this anytime soon... I'm mostly fixing critical issues in doctest these days (and responding to issues/PRs) - still in the first month of a new job. |
@onqtam thanks, I understand. I have xsl done and tested against jenkins via xunit: https://github.com/dhoer/doctest-cpp-to-ant-junit. When you start working on the junit reporter, feel free to reach out to me to talk about the nuances of junit and jenkins. I tried to document it with the caveats, known issues, and references. |
@phil-zxx wrote an initial version for a JUnit reporter - I might integrate it into the next release (along with tests and CI and whatnot). I'd be happy if others chimed in and gave some feedback as in what's missing and what could be improved with concrete suggestions/code (ping @dhoer ) - I still have little bandwidth for development but it would be great to finally get this JUnit thing done. |
@phil-zxx 's implementation (#376) seems good enough for me. My requirement was just to have a simple implementation, such that it be correctly recognised and parsed by GitLab. As many people have pointed out, JUnit is not a well-specified format, so unfortunately, we probably need to wait and see whether it also meets the requirements for Jenkins and maybe a smattering of other CI systems. Or not. Just putting it in as-is at least gets it out there, and if anyone has a problem, they are likely to complain here. |
…few TODOs right above the JUnit reporter class definition which would need to be addressed + the output hasn't been inspected if it's correct or stable across compilers/platforms - WIP! relates #376 and #318 - thanks to @phil-zxx for the implementation and to @byzantic , @ARCRL and @dhoer for their inputs!
…few TODOs right above the JUnit reporter class definition which would need to be addressed + the output hasn't been inspected if it's correct or stable across compilers/platforms - WIP! relates #376 and #318 - thanks to @phil-zxx for the implementation and to @byzantic , @ARCRL and @dhoer for their inputs!
Just pushed a finished version of it in the |
I would just like to add some weight to the requirement for a Junit reporter; I know it's scheduled for the 2.4 release, but currently it is what is stopping me from moving to doctest from Catch2. Otherwise I'm very impressed with doctest.
Junit is a very useful format for interacting with CI systems like Team City, Jenkins, and in my case GitLab.
As such, the output format does NOT need to support all of the Junit schema, in fact it is better to provide the absolute minimum that will be parsed by these systems. By the way, the one that seems to cause the most issues is the 'classname' attribute which needs to be present, even though its not much use if the source language is not Java.
The tricky issues would seem to be:
My thoughts on these points:
failure
tag.In any event, if we need to emit attribute tags, it is fairly straightforward to build a post-processor program that can be run over the file. I built a simple one using a python package I found somewhere (can't remember the name now).
It looks as though it should be possible to provide a Junit reporter by modifying the example XML reporter; in fact by dropping about 90% of the code! I did a quick trial to confirm this, but it's not suitable for a PR as my understanding of the API and subcases is poor.
The text was updated successfully, but these errors were encountered: