diff --git a/spec/e2e_spec.coffee b/spec/e2e_spec.coffee index 683311c..29c2f60 100755 --- a/spec/e2e_spec.coffee +++ b/spec/e2e_spec.coffee @@ -23,7 +23,7 @@ describe 'JUnit Report builder', -> builder.testCase().className("root.test.Class1") suite1 = builder.testSuite().name("first.Suite") suite1.testCase().name("Second test") - suite1.testCase().className("suite1.test.Class2").name("Third test").file("./path-to/the-test-file.coffee") + suite1.testCase().className("suite1.test.Class2").name("Third test").file("./path-to/the-test-file.coffee").property("property name", "property value") suite2 = builder.testSuite().name("second.Suite") suite2.testCase().failure("Failure message") suite2.testCase().stacktrace("Stacktrace") diff --git a/spec/expected_report.xml b/spec/expected_report.xml index 3bf4d31..5ef522d 100755 --- a/spec/expected_report.xml +++ b/spec/expected_report.xml @@ -3,7 +3,11 @@ - + + + + + @@ -16,4 +20,4 @@ - + \ No newline at end of file diff --git a/spec/test_case_spec.coffee b/spec/test_case_spec.coffee index d6afec0..8f95337 100755 --- a/spec/test_case_spec.coffee +++ b/spec/test_case_spec.coffee @@ -4,6 +4,7 @@ TestCase = require '../src/test_case' describe 'Test Case builder', -> testCase = null parentElement = null + propertiesElement = null testCaseElement = null failureElement = null skippedElement = null @@ -21,6 +22,7 @@ describe 'Test Case builder', -> skippedElement = createElementMock('skippedElement') systemOutElement = createElementMock('systemOutElement') systemErrElement = createElementMock('systemErrElement') + propertiesElement = createElementMock('propertiesElement') parentElement.ele.and.callFake (elementName) -> switch elementName @@ -32,6 +34,7 @@ describe 'Test Case builder', -> when 'skipped' then return skippedElement when 'system-out' then return systemOutElement when 'system-err' then return systemErrElement + when 'properties' then return propertiesElement systemErrElement.cdata.and.callFake (stdError) -> switch stdError @@ -82,6 +85,15 @@ describe 'Test Case builder', -> file: './path-to/the-test-file.coffee' }) + it 'should add the provided property as elements', -> + testCase.property 'property name', 'property value' + + testCase.build parentElement + + expect(propertiesElement.ele).toHaveBeenCalledWith('property', { + name: 'property name', + value: 'property value' + }) it 'should add a failure node when test failed', -> testCase.failure() diff --git a/src/test_case.js b/src/test_case.js index 0e5e766..915fb21 100755 --- a/src/test_case.js +++ b/src/test_case.js @@ -1,3 +1,4 @@ +var _ = require('lodash'); function TestCase() { this._error = false; this._failure = false; @@ -10,6 +11,7 @@ function TestCase() { this._failureAttributes = {}; this._errorAttachment = undefined; this._errorContent = undefined; + this._properties = []; } TestCase.prototype.className = function (className) { @@ -95,10 +97,27 @@ TestCase.prototype.errorAttachment = function (path) { return this; }; +TestCase.prototype.property = function (name, value) { + this._properties.push({ name: name, value: value }); + return this; +}; + TestCase.prototype.build = function (parentElement) { var testCaseElement = parentElement.ele('testcase', this._attributes); + if (this._properties.length) { + var propertiesElement = testCaseElement.ele('properties'); + _.forEach(this._properties, function (property) { + propertiesElement.ele('property', { + name: property.name, + value: property.value, + }); + }); + } if (this._failure) { - var failureElement = testCaseElement.ele('failure', this._failureAttributes); + var failureElement = testCaseElement.ele( + 'failure', + this._failureAttributes + ); if (this._stacktrace) { failureElement.cdata(this._stacktrace); } @@ -119,7 +138,7 @@ TestCase.prototype.build = function (parentElement) { if (this._standardError) { systemError = testCaseElement.ele('system-err').cdata(this._standardError); - if(this._errorAttachment) { + if (this._errorAttachment) { systemError.txt('[[ATTACHMENT|' + this._errorAttachment + ']]'); } }