xunit.js
2.52 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
/*global casper*/
/*jshint strict:false*/
var tester = require('tester');
var testpage = require('webpage').create();
casper.test.begin('XUnitReporter() initialization', 1, function suite() {
var xunit = require('xunit').create();
var results = new tester.TestSuiteResult();
xunit.setResults(results);
this.assertTruthy(xunit.getXML());
this.done();
});
casper.test.begin('XUnitReporter() can hold test suites', 4, function suite() {
var xunit = require('xunit').create();
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);
casper.start().setContent(xunit.getXML());
this.assertEvalEquals(function() {
return __utils__.findAll('testsuite').length;
}, 2);
this.assertExists('testsuites[duration]');
this.assertExists('testsuite[name="foo"][package="foo"]');
this.assertExists('testsuite[name="bar"][package="bar"]');
this.done();
});
casper.test.begin('XUnitReporter() can hold a suite with a succesful test', 1, function suite() {
var xunit = require('xunit').create();
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);
casper.start().setContent(xunit.getXML());
this.assertExists('testsuite[name="foo"][package="foo"][tests="1"][failures="0"] testcase[name="footext"]');
casper.test.done();
});
casper.test.begin('XUnitReporter() can handle a failed test', 2, function suite() {
var xunit = require('xunit').create();
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);
casper.start().setContent(xunit.getXML());
this.assertExists('testsuite[name="foo"][package="foo"][tests="1"][failures="1"] testcase[name="footext"] failure[type="footype"]');
this.assertEquals(casper.getElementInfo('failure[type="footype"]').text, 'footext');
casper.test.done();
});