Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/orta/danger-junit
Lets you report your test suite problems back to the PR elegantly
https://github.com/orta/danger-junit
Last synced: 12 days ago
JSON representation
Lets you report your test suite problems back to the PR elegantly
- Host: GitHub
- URL: https://github.com/orta/danger-junit
- Owner: orta
- License: mit
- Created: 2016-07-30T01:35:36.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2021-11-30T19:01:29.000Z (almost 3 years ago)
- Last Synced: 2024-04-24T15:13:39.578Z (7 months ago)
- Language: Ruby
- Size: 211 KB
- Stars: 57
- Watchers: 3
- Forks: 18
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-danger - danger-junit - Lets you report your test suite problems back to the PR elegantly. (Plugins / Ruby (danger))
README
# danger-junit
This Danger Plugin allows you to standardise the output for all of your testing runs. Most test runners include an ability to have a reporter that conforms to the JUnit XML standard. This plugin will understand that file and offer a way to introspect it, and to report on it.
![](img/example.png)
## Installation
$ gem install danger-junit
## Usage
### Ruby
For Rspec, add the gem `rspec_junit_formatter` to your project. Then use a `.rspec` file to configure your tests to have multiple reporters. This file looks like:
``` sh
...
--format documentation
--format RspecJunitFormatter --out junit-results.xml
...
```Then you can pass the `junit-results.xml` file to the plugin in your `Dangerfile`.
### JS
In a Jasmine, or Jest testing project, you want to install the module `jasmine-reporters`. Then as you are setting up your Jasmine runner, [add the following](https://github.com/larrymyers/jasmine-reporters#basic-usage):
```javascript
var junitReporter = new jasmineReporters.JUnitXmlReporter({
savePath: 'junit-results.xml',
consolidateAll: false
});
jasmine.getEnv().addReporter(junitReporter);
```Then you can pass the `junit-results.xml` file to the plugin in your `Dangerfile`.
### iOS
You have a lot of options:
* [trainer](https://github.com/krausefx/trainer) is the fastest way to generate the junit file.
* [xcpretty](https://github.com/supermarin/xcpretty#reporters) is used in both [fastlane](https://fastlane.tools), and a lot of standard setups.
* [xctool](https://github.com/facebook/xctool#included-reporters) includes it's own reporter for creating the file.### JUnit
Report, or inspect any JUnit XML formatted test suite report.
Testing frameworks have standardized on the JUnit XML format for
reporting results, this means that projects using Rspec, Jasmine, Mocha,
XCTest and more - can all use the same Danger error reporting. Perfect.You can see some examples on [this page from Circle CI](https://circleci.com/docs/test-metadata/) and on this [project's README](https://github.com/orta/danger-junit.git)
about how you can add JUnit XML output for your testing projects.Parse the XML file, and let the plugin do your reporting
junit.parse "/path/to/output.xml"
junit.reportLet the plugin parse the XML file, and report yourself
junit.parse "/path/to/output.xml"
fail("Tests failed") unless junit.failures.empty?Warn on a report about skipped tests
junit.parse "/path/to/output.xml"
junit.show_skipped_tests = true
junit.skipped_headers = [:name, :file]
junit.reportOnly show specific parts of your results
junit.parse "/path/to/output.xml"
junit.headers = [:name, :file]
junit.reportOnly show specific parts of your results
junit.parse "/path/to/output.xml"
all_test = junit.tests.map(&:attributes)
slowest_test = sort_by { |attributes| attributes[:time].to_f }.last
message "#{slowest_test[:time]} took #{slowest_test[:time]} seconds"#### Attributes
`tests` - All the tests for introspection
`passes` - An array of XML elements that represent passed tests.
`failures` - An array of XML elements that represent failed tests.
`errors` - An array of XML elements that represent passed tests.
`skipped` - An array of XML elements that represent skipped tests.
`show_skipped_tests` - An attribute to make the plugin show a warning on skipped tests.
`headers` - An array of symbols that become the columns of your tests,
if `nil`, the default, it will be all of the attributes.`skipped_headers` - An array of symbols that become the columns of your skipped tests,
if `nil`, the default, it will be all of the attributes for a single parse
or all of the common attributes between multiple files#### Methods
`parse` - Parses an XML file, which fills all the attributes,
will `raise` for errors`report` - Causes a build fail if there are test failures,
and outputs a markdown table of the results.## Development
1. Clone this repo
2. Run `bundle install` to setup dependencies.
3. Run `bundle exec rake spec` to run the tests.
4. Use `bundle exec guard` to automatically have tests run as you make changes.
5. Make your changes.