Skip to content
This repository has been archived by the owner on Apr 29, 2021. It is now read-only.

Add a JUnit output formatter compatible with Jenkins #161

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

calj
Copy link

@calj calj commented Apr 20, 2016

  • Added the parameter --junit to bats which output into JUnit XML format, the purpose was to integrate the report into Jenkins
  • I had to add the suite name into the extended report format so I can classify tests by file
  • I added --extended parameter to bats command so you can run the test suite once and format the output into several format (ie: pretty for the console and junit into a result.xml file)

Please advise if you see anything to change!

@schrepfler
Copy link

This is awesome!

@harschware
Copy link

harschware commented Jul 28, 2016

As noted by the Travis build, the tests fail with this PR.

I was interested in merging this PR into my harschware/cactus branch (which is where I keep a merge of all the PRs I'm interested in, since PRs are not being merged into the sstephenson/bats repo for sometime now).

The main thing I'm interested in from this PR was the timing information, since I see you added it to the TAP test status lines, for extended syntax. But after looking at the code I don't think it work well as a starting point for my purpose. I am looking to test duration in millseconds to the TAP output via YAML extension.

Be aware that the TAP13 specification does not provide for a way to indicate time, but the issue of supporting that in the spec has been discussed. No TAP14 spec exists today, but it essentially comes down to two methods being discussed.
add # time=NNN to the test line
add YAML to the test. e.g.

1..1
ok YAML time with duration
  ---
    duration_ms: 45293
  ...

The YAML extension is supported by Jenkins TAP Plugin (https://wiki.jenkins-ci.org/display/JENKINS/TAP+Plugin), incidentally JUnit isn't strictly required to use BATS in Jenkins if you use the TAP plugin instead of JUnit.

Not all TAP consumers respect the YAML extension, but at minimum tap4j does.

I will probably want to at minimum, ammend the extended format in BATS to include time in milliseconds rather than seconds. When it comes time to merge our two PRs to this repo (if ever) there will be a slight divergence there.

@harschware
Copy link

See PR #177 for details about TAP with YAML extension.

@calj
Copy link
Author

calj commented Aug 4, 2016

Here is the fix for tests.

Your work looks great, I didn't found any way to calculate the time in milliseconds in pure "bash", I used this framework because it's highly portable, for example the usage of the command date is different on AIX and on Solaris 10, so I simplified the problem by displaying the time in seconds.

Suggestions are welcome :)

@astorije
Copy link

astorije commented Sep 3, 2016

What's the status of this?

FYI, Solano CI parser does not support TAP, sadly, so having a JUnit formatter is the only alternative.

@sstephenson or @mislav, is this project still being looked at? Thanks for your great work!

@@ -20,6 +20,8 @@ help() {
echo " -h, --help Display this help message"
echo " -p, --pretty Show results in pretty format (default for terminals)"
echo " -t, --tap Show results in TAP format"
echo " -x, --extended Show results in extended TAP format"
echo " -u, --junit Show results in JUnit format, hudson compatible"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be more explicit and future-proof to name them -x, --extended-tap and -j, --junit .

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to say Jenkins or Jenkins/Hudson here as most people use Jenkins. Additionally it's a personal name so caps are grammatically correct.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd remove what's after the comma entirely. Whether it's for Hudson, Jenkins or whatever, it's a JUnit format, and it's all that matters :)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, we can do so.
I have specified Hudson here because I noticed difference with the JUnit specifications.

@nvgoldin
Copy link

Any news on this? Would love to see this gets in.

@matt-land
Copy link

Would also like this in. PR Contributor did the work and fixed the tests.

@jasonkarns
Copy link

I rather feel that supporting multiple output formats is outside the role of bats.

TAP output is (or is becoming?) a near lingua-franca of test report formats. TAP can be consumed and converted to virtually any other format (dot, spec, xunit, etc)

If all that is desired is TAP consumption by jenkins/hudson, I would advocate for the TAP plugin: https://wiki.jenkins.io/display/JENKINS/TAP+Plugin

Separately, though, I would advocate for any other test report formats to consume the TAP output on STDIN, and transform to the desired output by piping. For example: https://github.com/aghassemi/tap-xunit (which could be used as-is to convert Bats' TAP output to xunit without needing the option supported in bats.)

As it stands, the current formatter could be shipped as a standalone TAP converter that just receives Bats' TAP output. Creating a separate bats-xunit project would be a fine repo for future inclusion in a potential bats-core github org. I just don't think it should necessarily be bundled within bats itself.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants