Skip to content

Commit

Permalink
Merge branch 'xunit-reporting' of github.com:localmed/dredd into loca…
Browse files Browse the repository at this point in the history
…lmed-xunit-reporting
  • Loading branch information
Adam Kliment committed Oct 21, 2013
2 parents e74b5eb + 531813a commit cc51817
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 22 deletions.
26 changes: 24 additions & 2 deletions README.md
Expand Up @@ -13,14 +13,36 @@ Dredd is a command-line tool for testing API documentation written in [API Bluep
## Get Started Testing Your API

$ dredd blueprint.md http://api.myservice.tld

## Installation
[Node.js][] and [NPM][] is required.

$ npm install -g dredd

[Node.js]: https://npmjs.org/
[Node.js]: https://npmjs.org/
[NPM]: https://npmjs.org/

## Command Line Options

$ dredd -h

Usage:
dredd <path to blueprint> <api_endpoint> [OPTIONS]

Example:
dredd ./apiary.md http://localhost:3000 --dry-run

Options:
-d, --dry-run Run without performing tests.
-s, --silent Suppress all command line output
-r, --reporter STRING Output additional report format. Options: junit
-o, --output FILE Specifies output file when using additional
reporter
-k, --no-color Omit color from output
--debug Show debug information
-v, --version Display the current version
-h, --help Display help and usage details

## API Blueprint testability
Dredd can test only API resources specified by *well defined transaction*. Any Non specific resources in the Blueprint e. g. with URI template or query parameters without default or example values are considered as *ambiguous transaction* thus they are resulting in a *warning* during the test run and are skipped.

Expand Down
13 changes: 4 additions & 9 deletions src/cli-reporter.coffee
Expand Up @@ -15,8 +15,9 @@ class CliReporter extends Reporter
logger.pass test.title
when 'fail'
logger.fail test.title

logger.info test.message
logger.fail test.message
logger.expected "\n" + (JSON.stringify test.expected, null, 4) + "\n"
logger.actual "\n" + (JSON.stringify test.actual, null, 4) + "\n\n"

return callback()

Expand All @@ -25,13 +26,7 @@ class CliReporter extends Reporter
return callback(error) if error

if @stats.tests > 0
logger.complete "Tests Complete\n" \
+ "tests: #{@stats.tests} \n" \
+ "failures: #{@stats.failures} \n" \
+ "errors: #{@stats.failures} \n" \
+ "skip: #{@stats.tests - @stats.failures - @stats.passes} \n" \
+ "timestamp: #{(new Date).toUTCString()} \n" \
+ "time: #{@stats.duration / 1000} \n"
logger.complete "#{@stats.passes} passing, #{@stats.failures} failing, #{@stats.tests - @stats.failures - @stats.passes} skipped"
return callback()

module.exports = CliReporter
5 changes: 5 additions & 0 deletions src/execute-transaction.coffee
Expand Up @@ -93,6 +93,11 @@ executeTransaction = (transaction, callback) ->
status: "fail",
title: options['method'] + ' ' + options['path'],
message: message
actual: real
expected: expected
cli.debug "REAL: " + JSON.stringify real
cli.debug "EXPECTED: " + JSON.stringify expected
cli.debug "RESULT: " + JSON.stringify result
configuration.reporter.addTest test, (error) ->
return callback error if error
return callback()
Expand Down
23 changes: 15 additions & 8 deletions src/logger.coffee
Expand Up @@ -2,17 +2,24 @@ winston = require 'winston'

config =
levels:
test: 0,
info: 1,
pass: 2,
fail: 3,
test: 0
info: 1
pass: 2
fail: 3
complete: 4
actual: 5
expected: 6
diff: 7
colors:
test: 'yellow',
info: 'blue',
pass: 'green',
fail: 'red',
test: 'yellow'
info: 'blue'
pass: 'green'
fail: 'red'
complete: 'green'
actual: 'red'
expected: 'red'
diff: 'red'


logger = new (winston.Logger) ({
transports: [
Expand Down
3 changes: 2 additions & 1 deletion src/x-unit-reporter.coffee
Expand Up @@ -39,10 +39,11 @@ class XUnitReporter extends Reporter
attrs =
classname: test.title
name: test.title
time: test.duration ? test.duration / 1000 : 0

if 'fail' is test.status
attrs.message = test.message
attrs.expected = JSON.stringify test.expected
attrs.actual = JSON.stringify test.actual
appendLine(path, toTag('testcase', attrs, false, toTag('failure', attrs, false, cdata(test.errorMessage))))
else
appendLine(path, toTag('testcase', attrs, true) )
Expand Down
2 changes: 1 addition & 1 deletion test/unit/cli-reporter-test.coffee
Expand Up @@ -44,7 +44,7 @@ describe 'CliReporter', () ->
it 'should write fail to the console', (done) ->
cliReporter = new CliReporter()
cliReporter.addTest test, ()->
assert.ok loggerStub.fail.calledOnce
assert.ok loggerStub.fail.called
done()


Expand Down
4 changes: 3 additions & 1 deletion test/unit/x-unit-reporter-test.coffee
Expand Up @@ -16,7 +16,7 @@ describe 'XUnitReporter', () ->

describe 'when creating report', () ->
beforeEach () ->
sinon.spy fsStub, 'appendFileSync'
sinon.spy fsStub, 'appendFileSync'

afterEach () ->
fsStub.appendFileSync.restore()
Expand All @@ -29,6 +29,7 @@ describe 'XUnitReporter', () ->
xUnitReporter.addTest { status: 'pass', title: 'Passing Test' }, () ->
xUnitReporter.createReport () ->
assert.ok fsStub.appendFileSync.called
fsStub.unlinkSync(xUnitReporter.path)
done()

describe 'when there are no tests', () ->
Expand All @@ -37,4 +38,5 @@ describe 'XUnitReporter', () ->
xUnitReporter = new XUnitReporter()
xUnitReporter.createReport () ->
assert.ok fsStub.appendFileSync.calledTwice
fsStub.unlinkSync(xUnitReporter.path)
done()

0 comments on commit cc51817

Please sign in to comment.