testsuite.js
2.01 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
/*jshint strict:false*/
/*global CasperError, casper, console, phantom, require*/
var TestCaseResult = require('tester').TestCaseResult,
TestSuiteResult = require('tester').TestSuiteResult;
function generateCaseResult(options) {
var i,
nPasses = options && ~~options.nPasses,
nFailures = options && ~~options.nFailures,
caseResult = new TestCaseResult(options);
for (i = 0; i < nFailures; i++) {
caseResult.addFailure({}, i * 1000);
}
for (i = 0; i < nPasses; i++) {
caseResult.addSuccess({}, i * 1000);
}
return caseResult;
}
casper.test.begin('TestSuiteResult() basic tests', 8, function(test) {
var suiteResult = new TestSuiteResult();
test.assertEquals(suiteResult.constructor.name, 'Array', 'TestSuiteResult() is derived from Array');
test.assertEquals(suiteResult.countTotal(), 0);
test.assertEquals(suiteResult.countFailed(), 0);
test.assertEquals(suiteResult.countPassed(), 0);
test.assertEquals(suiteResult.getAllFailures(), []);
test.assertEquals(suiteResult.getAllPasses(), []);
test.assertEquals(suiteResult.getAllResults(), []);
test.assertEquals(suiteResult.calculateDuration(), 0);
test.done();
});
casper.test.begin('TestSuiteResult() accumulation tests', 7, function(test) {
var suiteResult = new TestSuiteResult();
suiteResult.push(generateCaseResult({
name: 'foo',
file: '/tmp/foo',
nPasses: 4,
nFailures: 1
}));
suiteResult.push(generateCaseResult({
name: 'bar',
file: '/tmp/bar',
nPasses: 3,
nFailures: 0
}));
test.assertEquals(suiteResult.countTotal(), 8);
test.assertEquals(suiteResult.countFailed(), 1);
test.assertEquals(suiteResult.countPassed(), 7);
test.assertEquals(suiteResult.getAllFailures().length, 1);
test.assertEquals(suiteResult.getAllPasses().length, 7);
test.assertEquals(suiteResult.getAllResults().length, 8);
test.assertEquals(suiteResult.calculateDuration(), 9000);
test.done();
});