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

Add support for adding file attachments in junit report format #4666

Closed

Conversation

trakos
Copy link

@trakos trakos commented May 10, 2021

Soon, gitlab will add ability to show images attached in junit report file on merge request/pipeline view:

This was also possible in jenkins, with junit-attachments plugins and supported by some libraries like mocha:

The format is a bit weird, because it's simply supposed to be added to system-out element, example from gitlab:

<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="rspec" tests="1" skipped="0" failures="1" errors="0" time="0.017557" timestamp="2020-03-09T15:16:55-04:00" hostname="Maximes-MacBook-Pro.local">
  <properties>
    <property name="seed" value="9386"/>
  </properties>
  <testcase classname="spec.hello_world_spec" name="the home page return hello world" file="./spec/hello_world_spec.rb" time="0.016340">
    <failure message="" type="RuntimeError">Failure/Error: raise
RuntimeError:
./spec/hello_world_spec.rb:8:in `block (2 levels) in &lt;top (required)&gt;'</failure>
    <system-out>[[ATTACHMENT|tmp/capybara/screenshot_return-hello-world.html]]</system-out>
  </testcase>
</testsuite>

Example use-case for phpunit would be with library like symfony/panther: it already has option to make screenshots on failed assertions, but for now they are not linked in any way in the report: symfony/panther#392

It is possible to achieve that simply by echoing the attachment during the phpunit test, but I find this way flawed: it interferes with tests that have to check stdout and with --disallow-test-output option, it also pollutes job output in CI, and has to be done in the test itself or in tearDown.

I submit a proposition for basic interface that could be implemented by TestCases to attach files to junit report. For now it would only be used by junit format, since I'm not aware of other formats requiring such feature.

I think it's simple enough, and doesn't introduce any BC, WDYT?

@sebastianbergmann
Copy link
Owner

I am reluctant to touch the JUnit logger.

@sebastianbergmann sebastianbergmann added feature/logging Issues related to logging test results type/enhancement A new idea that should be implemented labels May 10, 2021
@shaedrich
Copy link

@trakos Could you make it a package or something so it can still be of use?

@trakos
Copy link
Author

trakos commented Jan 13, 2023

Hey @shaedrich, since then, I've implemented it directly in to symfony/panther in PR symfony/panther#474. It's possible to simply echo the screenshot file path in the right format to get it to the junit output. You can check that symfony/panther PR to see how to implement it.

It's not as nice, but gets the job done.

@shaedrich
Copy link

Okay, thanks, @trakos 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/logging Issues related to logging test results type/enhancement A new idea that should be implemented
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants