xunit.js
5.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*eslint strict:0*/
var tester = require('tester');
casper.test.begin('XUnitReporter() initialization', 1, function suite(test) {
var xunit = require('xunit').create();
var results = new tester.TestSuiteResult();
xunit.setResults(results);
test.assertTruthy(xunit.getSerializedXML(), "XML can be generated");
test.done();
});
casper.test.begin('XUnitReporter() can hold test suites', 4, function suite(test) {
var xunit = require('xunit').create();
var xmlDocument;
var results = new tester.TestSuiteResult();
var suite1 = new tester.TestCaseResult({
name: 'foo',
file: '/foo'
});
results.push(suite1);
var suite2 = new tester.TestCaseResult({
name: 'bar',
file: '/bar'
});
results.push(suite2);
xunit.setResults(results);
xmlDocument = xunit.getXML();
casper.start();
test.assertEquals(xmlDocument.querySelectorAll('testsuite').length, 2, "2 test suites exist");
test.assertTruthy(xmlDocument.querySelector('testsuites[time]'), "Element 'testsuites' has time attribute");
test.assertTruthy(xmlDocument.querySelector('testsuite[name="foo"][package="foo"]'), "Package foo exists");
test.assertTruthy(xmlDocument.querySelector('testsuite[name="bar"][package="bar"]'), "Package bar exists");
test.done();
});
casper.test.begin('XUnitReporter() can hold a suite with a successful test', 1, function suite(test) {
var xunit = require('xunit').create();
var xmlDocument;
var results = new tester.TestSuiteResult();
var suite1 = new tester.TestCaseResult({
name: 'foo',
file: '/foo'
});
suite1.addSuccess({
success: true,
type: "footype",
message: "footext",
file: "/foo"
});
results.push(suite1);
xunit.setResults(results);
xmlDocument = xunit.getXML();
casper.start();
test.assertTruthy(xmlDocument.querySelector('testsuite[name="foo"][package="foo"][tests="1"][failures="0"] testcase[name="footext"]'), "Successful test case exists");
test.done();
});
casper.test.begin('XUnitReporter() can handle a failed test', 2, function suite(test) {
var xunit = require('xunit').create();
var xmlDocument;
var results = new tester.TestSuiteResult();
var suite1 = new tester.TestCaseResult({
name: 'foo',
file: '/foo'
});
suite1.addFailure({
success: false,
type: "footype",
message: "footext",
file: "/foo"
});
results.push(suite1);
xunit.setResults(results);
xmlDocument = xunit.getXML();
casper.start();
test.assertTruthy(xmlDocument.querySelector('testsuite[name="foo"][package="foo"][tests="1"][failures="1"] testcase[name="footext"] failure[type="footype"]'), "Failure node exists");
test.assertEquals(xmlDocument.querySelector('failure[type="footype"]').textContent, 'footext');
test.done();
});
casper.test.begin('XUnitReporter() can handle custom name attribute for a test case', 2, function suite(test) {
var xunit = require('xunit').create();
var xmlDocument;
var results = new tester.TestSuiteResult();
var suite1 = new tester.TestCaseResult({
name: 'foo',
file: '/foo'
});
suite1.addFailure({
success: false,
type: "footype",
message: "footext",
file: "/foo",
name: "foo bar baz"
});
results.push(suite1);
xunit.setResults(results);
xmlDocument = xunit.getXML();
casper.start();
test.assertTruthy(xmlDocument.querySelector('testsuite[name="foo"][package="foo"][tests="1"][failures="1"] testcase[name="foo bar baz"] failure[type="footype"]'), "Failure node exists");
test.assertEquals(xmlDocument.querySelector('failure[type="footype"]').textContent, 'footext');
test.done();
});
casper.test.begin('XUnitReporter() does not have default XML namespace', 1, function suite(test) {
var xunit = require('xunit').create();
var xmlDocument;
var results = new tester.TestSuiteResult();
var suite1 = new tester.TestCaseResult({
name: 'foo',
file: '/foo'
});
results.push(suite1);
xunit.setResults(results);
xmlDocument = xunit.getXML();
casper.start();
test.assertFalsy(xmlDocument.querySelector('testsuites[xmlns]'), "No default namespace");
test.done();
});
casper.test.begin('XUnitReporter() can handle markup in nodes', 4, function suite(test) {
var xunit = require('xunit').create();
var xmlDocument;
var results = new tester.TestSuiteResult();
var suite1 = new tester.TestCaseResult({
name: 'foo',
file: '/foo'
});
suite1.addFailure({
success: false,
type: "footype",
message: "<b>foo</b> <i>bar</i> and <a href=''>baz</a>",
file: "/foo",
name: "foo bar baz"
});
suite1.addError({
name: 'foo',
message: "<b>foo</b> <i>bar</i> and <a href=''>baz</a>"
});
suite1.addWarning("<b>some warning markup</b>");
results.push(suite1);
xunit.setResults(results);
xmlDocument = xunit.getXML();
casper.start();
test.assertTruthy(xmlDocument.querySelector('testsuite[name="foo"][package="foo"][tests="1"][failures="1"] testcase[name="foo bar baz"] failure[type="footype"]'), "Node exists");
test.assertEquals(xmlDocument.querySelector('failure[type="footype"]').textContent, "<b>foo</b> <i>bar</i> and <a href=''>baz</a>", "Handles markup in failure node");
test.assertEquals(xmlDocument.querySelector('error[type="foo"]').textContent, "<b>foo</b> <i>bar</i> and <a href=''>baz</a>", "Handles markup in error node");
test.assertEquals(xmlDocument.querySelector('system-out').textContent, "<b>some warning markup</b>", "Handles markup in error node")
test.done();
});