renamed test result container classes, added tests for them
Showing
7 changed files
with
165 additions
and
55 deletions
... | @@ -82,7 +82,7 @@ var Tester = function Tester(casper, options) { | ... | @@ -82,7 +82,7 @@ var Tester = function Tester(casper, options) { |
82 | this.queue = []; | 82 | this.queue = []; |
83 | this.running = false; | 83 | this.running = false; |
84 | this.started = false; | 84 | this.started = false; |
85 | this.suites = new TestSuite(); | 85 | this.suiteResults = new TestSuiteResult(); |
86 | this.options = utils.mergeObjects({ | 86 | this.options = utils.mergeObjects({ |
87 | failFast: false, // terminates a suite as soon as a test fails? | 87 | failFast: false, // terminates a suite as soon as a test fails? |
88 | failText: "FAIL", // text to use for a succesful test | 88 | failText: "FAIL", // text to use for a succesful test |
... | @@ -729,7 +729,7 @@ Tester.prototype.begin = function begin(description, suiteFn) { | ... | @@ -729,7 +729,7 @@ Tester.prototype.begin = function begin(description, suiteFn) { |
729 | } | 729 | } |
730 | description = description || "Untitled suite in " + this.currentTestFile; | 730 | description = description || "Untitled suite in " + this.currentTestFile; |
731 | this.comment(description); | 731 | this.comment(description); |
732 | this.currentSuite = new TestSuiteResult({ | 732 | this.currentSuite = new TestCaseResult({ |
733 | name: description, | 733 | name: description, |
734 | file: this.currentTestFile | 734 | file: this.currentTestFile |
735 | }); | 735 | }); |
... | @@ -800,7 +800,7 @@ Tester.prototype.done = function done(planned) { | ... | @@ -800,7 +800,7 @@ Tester.prototype.done = function done(planned) { |
800 | this.dubious(planned, this.executed); | 800 | this.dubious(planned, this.executed); |
801 | } | 801 | } |
802 | if (this.currentSuite) { | 802 | if (this.currentSuite) { |
803 | this.suites.push(this.currentSuite); | 803 | this.suiteResults.push(this.currentSuite); |
804 | this.currentSuite = undefined; | 804 | this.currentSuite = undefined; |
805 | this.executed = 0; | 805 | this.executed = 0; |
806 | } | 806 | } |
... | @@ -947,7 +947,7 @@ Tester.prototype.pass = function pass(message) { | ... | @@ -947,7 +947,7 @@ Tester.prototype.pass = function pass(message) { |
947 | Tester.prototype.processAssertionResult = function processAssertionResult(result) { | 947 | Tester.prototype.processAssertionResult = function processAssertionResult(result) { |
948 | "use strict"; | 948 | "use strict"; |
949 | if (!this.currentSuite) { | 949 | if (!this.currentSuite) { |
950 | this.currentSuite = new TestSuiteResult({ | 950 | this.currentSuite = new TestCaseResult({ |
951 | name: "Untitled suite in " + this.currentTestFile, | 951 | name: "Untitled suite in " + this.currentTestFile, |
952 | file: this.currentTestFile | 952 | file: this.currentTestFile |
953 | }); | 953 | }); |
... | @@ -976,7 +976,7 @@ Tester.prototype.processAssertionResult = function processAssertionResult(result | ... | @@ -976,7 +976,7 @@ Tester.prototype.processAssertionResult = function processAssertionResult(result |
976 | */ | 976 | */ |
977 | Tester.prototype.renderFailureDetails = function renderFailureDetails() { | 977 | Tester.prototype.renderFailureDetails = function renderFailureDetails() { |
978 | "use strict"; | 978 | "use strict"; |
979 | var failures = this.suites.getAllFailures(); | 979 | var failures = this.suiteResults.getAllFailures(); |
980 | if (failures.length === 0) { | 980 | if (failures.length === 0) { |
981 | return; | 981 | return; |
982 | } | 982 | } |
... | @@ -1001,9 +1001,9 @@ Tester.prototype.renderResults = function renderResults(exit, status, save) { | ... | @@ -1001,9 +1001,9 @@ Tester.prototype.renderResults = function renderResults(exit, status, save) { |
1001 | "use strict"; | 1001 | "use strict"; |
1002 | /*jshint maxstatements:20*/ | 1002 | /*jshint maxstatements:20*/ |
1003 | save = save || this.options.save; | 1003 | save = save || this.options.save; |
1004 | var failed = this.suites.countFailed(), | 1004 | var failed = this.suiteResults.countFailed(), |
1005 | passed = this.suites.countPassed(), | 1005 | passed = this.suiteResults.countPassed(), |
1006 | total = this.suites.countTotal(), | 1006 | total = this.suiteResults.countTotal(), |
1007 | statusText, | 1007 | statusText, |
1008 | style, | 1008 | style, |
1009 | result, | 1009 | result, |
... | @@ -1021,7 +1021,7 @@ Tester.prototype.renderResults = function renderResults(exit, status, save) { | ... | @@ -1021,7 +1021,7 @@ Tester.prototype.renderResults = function renderResults(exit, status, save) { |
1021 | style = 'GREEN_BAR'; | 1021 | style = 'GREEN_BAR'; |
1022 | } | 1022 | } |
1023 | result = f('%s %s tests executed in %ss, %d passed, %d failed.', | 1023 | result = f('%s %s tests executed in %ss, %d passed, %d failed.', |
1024 | statusText, total, utils.ms2seconds(this.suites.calculateDuration()), | 1024 | statusText, total, utils.ms2seconds(this.suiteResults.calculateDuration()), |
1025 | passed, failed); | 1025 | passed, failed); |
1026 | } | 1026 | } |
1027 | this.casper.echo(result, style, this.options.pad); | 1027 | this.casper.echo(result, style, this.options.pad); |
... | @@ -1114,7 +1114,7 @@ Tester.prototype.runTest = function runTest(testFile) { | ... | @@ -1114,7 +1114,7 @@ Tester.prototype.runTest = function runTest(testFile) { |
1114 | Tester.prototype.saveResults = function saveResults(filepath) { | 1114 | Tester.prototype.saveResults = function saveResults(filepath) { |
1115 | "use strict"; | 1115 | "use strict"; |
1116 | var exporter = require('xunit').create(); | 1116 | var exporter = require('xunit').create(); |
1117 | exporter.setResults(this.suites); | 1117 | exporter.setResults(this.suiteResults); |
1118 | try { | 1118 | try { |
1119 | fs.write(filepath, exporter.getXML(), 'w'); | 1119 | fs.write(filepath, exporter.getXML(), 'w'); |
1120 | this.casper.echo(f('Result log stored in %s', filepath), 'INFO', 80); | 1120 | this.casper.echo(f('Result log stored in %s', filepath), 'INFO', 80); |
... | @@ -1164,16 +1164,16 @@ Tester.prototype.uncaughtError = function uncaughtError(error, file, line, backt | ... | @@ -1164,16 +1164,16 @@ Tester.prototype.uncaughtError = function uncaughtError(error, file, line, backt |
1164 | * Test suites array. | 1164 | * Test suites array. |
1165 | * | 1165 | * |
1166 | */ | 1166 | */ |
1167 | function TestSuite() {} | 1167 | function TestSuiteResult() {} |
1168 | TestSuite.prototype = []; | 1168 | TestSuiteResult.prototype = []; |
1169 | exports.TestSuite = TestSuite; | 1169 | exports.TestSuiteResult = TestSuiteResult; |
1170 | 1170 | ||
1171 | /** | 1171 | /** |
1172 | * Returns the number of tests. | 1172 | * Returns the number of tests. |
1173 | * | 1173 | * |
1174 | * @return Number | 1174 | * @return Number |
1175 | */ | 1175 | */ |
1176 | TestSuite.prototype.countTotal = function countTotal() { | 1176 | TestSuiteResult.prototype.countTotal = function countTotal() { |
1177 | "use strict"; | 1177 | "use strict"; |
1178 | return this.countPassed() + this.countFailed(); | 1178 | return this.countPassed() + this.countFailed(); |
1179 | }; | 1179 | }; |
... | @@ -1183,7 +1183,7 @@ TestSuite.prototype.countTotal = function countTotal() { | ... | @@ -1183,7 +1183,7 @@ TestSuite.prototype.countTotal = function countTotal() { |
1183 | * | 1183 | * |
1184 | * @return Number | 1184 | * @return Number |
1185 | */ | 1185 | */ |
1186 | TestSuite.prototype.countFailed = function countFailed() { | 1186 | TestSuiteResult.prototype.countFailed = function countFailed() { |
1187 | "use strict"; | 1187 | "use strict"; |
1188 | return this.map(function(result) { | 1188 | return this.map(function(result) { |
1189 | return result.failed; | 1189 | return result.failed; |
... | @@ -1197,7 +1197,7 @@ TestSuite.prototype.countFailed = function countFailed() { | ... | @@ -1197,7 +1197,7 @@ TestSuite.prototype.countFailed = function countFailed() { |
1197 | * | 1197 | * |
1198 | * @return Number | 1198 | * @return Number |
1199 | */ | 1199 | */ |
1200 | TestSuite.prototype.countPassed = function countPassed() { | 1200 | TestSuiteResult.prototype.countPassed = function countPassed() { |
1201 | "use strict"; | 1201 | "use strict"; |
1202 | return this.map(function(result) { | 1202 | return this.map(function(result) { |
1203 | return result.passed; | 1203 | return result.passed; |
... | @@ -1211,7 +1211,7 @@ TestSuite.prototype.countPassed = function countPassed() { | ... | @@ -1211,7 +1211,7 @@ TestSuite.prototype.countPassed = function countPassed() { |
1211 | * | 1211 | * |
1212 | * @return Array | 1212 | * @return Array |
1213 | */ | 1213 | */ |
1214 | TestSuite.prototype.getAllFailures = function getAllFailures() { | 1214 | TestSuiteResult.prototype.getAllFailures = function getAllFailures() { |
1215 | "use strict"; | 1215 | "use strict"; |
1216 | var failures = []; | 1216 | var failures = []; |
1217 | this.forEach(function(result) { | 1217 | this.forEach(function(result) { |
... | @@ -1225,7 +1225,7 @@ TestSuite.prototype.getAllFailures = function getAllFailures() { | ... | @@ -1225,7 +1225,7 @@ TestSuite.prototype.getAllFailures = function getAllFailures() { |
1225 | * | 1225 | * |
1226 | * @return Array | 1226 | * @return Array |
1227 | */ | 1227 | */ |
1228 | TestSuite.prototype.getAllPasses = function getAllPasses() { | 1228 | TestSuiteResult.prototype.getAllPasses = function getAllPasses() { |
1229 | "use strict"; | 1229 | "use strict"; |
1230 | var passes = []; | 1230 | var passes = []; |
1231 | this.forEach(function(result) { | 1231 | this.forEach(function(result) { |
... | @@ -1239,7 +1239,7 @@ TestSuite.prototype.getAllPasses = function getAllPasses() { | ... | @@ -1239,7 +1239,7 @@ TestSuite.prototype.getAllPasses = function getAllPasses() { |
1239 | * | 1239 | * |
1240 | * @return Array | 1240 | * @return Array |
1241 | */ | 1241 | */ |
1242 | TestSuite.prototype.getAllResults = function getAllResults() { | 1242 | TestSuiteResult.prototype.getAllResults = function getAllResults() { |
1243 | "use strict"; | 1243 | "use strict"; |
1244 | return this.getAllPasses().concat(this.getAllFailures()); | 1244 | return this.getAllPasses().concat(this.getAllFailures()); |
1245 | }; | 1245 | }; |
... | @@ -1250,7 +1250,7 @@ TestSuite.prototype.getAllResults = function getAllResults() { | ... | @@ -1250,7 +1250,7 @@ TestSuite.prototype.getAllResults = function getAllResults() { |
1250 | * | 1250 | * |
1251 | * @return Number | 1251 | * @return Number |
1252 | */ | 1252 | */ |
1253 | TestSuite.prototype.calculateDuration = function calculateDuration() { | 1253 | TestSuiteResult.prototype.calculateDuration = function calculateDuration() { |
1254 | "use strict"; | 1254 | "use strict"; |
1255 | return this.getAllResults().map(function(result) { | 1255 | return this.getAllResults().map(function(result) { |
1256 | return result.time; | 1256 | return result.time; |
... | @@ -1264,7 +1264,7 @@ TestSuite.prototype.calculateDuration = function calculateDuration() { | ... | @@ -1264,7 +1264,7 @@ TestSuite.prototype.calculateDuration = function calculateDuration() { |
1264 | * | 1264 | * |
1265 | * @param Object options | 1265 | * @param Object options |
1266 | */ | 1266 | */ |
1267 | function TestSuiteResult(options) { | 1267 | function TestCaseResult(options) { |
1268 | "use strict"; | 1268 | "use strict"; |
1269 | this.name = options && options.name; | 1269 | this.name = options && options.name; |
1270 | this.file = options && options.file; | 1270 | this.file = options && options.file; |
... | @@ -1274,7 +1274,7 @@ function TestSuiteResult(options) { | ... | @@ -1274,7 +1274,7 @@ function TestSuiteResult(options) { |
1274 | this.passes = []; | 1274 | this.passes = []; |
1275 | this.failures = []; | 1275 | this.failures = []; |
1276 | } | 1276 | } |
1277 | exports.TestSuiteResult = TestSuiteResult; | 1277 | exports.TestCaseResult = TestCaseResult; |
1278 | 1278 | ||
1279 | /** | 1279 | /** |
1280 | * Adds a success record and its execution time to their associated stacks. | 1280 | * Adds a success record and its execution time to their associated stacks. |
... | @@ -1282,7 +1282,7 @@ exports.TestSuiteResult = TestSuiteResult; | ... | @@ -1282,7 +1282,7 @@ exports.TestSuiteResult = TestSuiteResult; |
1282 | * @param Object success | 1282 | * @param Object success |
1283 | * @param Number time | 1283 | * @param Number time |
1284 | */ | 1284 | */ |
1285 | TestSuiteResult.prototype.addSuccess = function addSuccess(success, time) { | 1285 | TestCaseResult.prototype.addSuccess = function addSuccess(success, time) { |
1286 | "use strict"; | 1286 | "use strict"; |
1287 | success.suite = this.name; | 1287 | success.suite = this.name; |
1288 | success.time = time; | 1288 | success.time = time; |
... | @@ -1297,7 +1297,7 @@ TestSuiteResult.prototype.addSuccess = function addSuccess(success, time) { | ... | @@ -1297,7 +1297,7 @@ TestSuiteResult.prototype.addSuccess = function addSuccess(success, time) { |
1297 | * @param Object failure | 1297 | * @param Object failure |
1298 | * @param Number time | 1298 | * @param Number time |
1299 | */ | 1299 | */ |
1300 | TestSuiteResult.prototype.addFailure = function addFailure(failure, time) { | 1300 | TestCaseResult.prototype.addFailure = function addFailure(failure, time) { |
1301 | "use strict"; | 1301 | "use strict"; |
1302 | failure.suite = this.name; | 1302 | failure.suite = this.name; |
1303 | failure.time = time; | 1303 | failure.time = time; |
... | @@ -1311,7 +1311,7 @@ TestSuiteResult.prototype.addFailure = function addFailure(failure, time) { | ... | @@ -1311,7 +1311,7 @@ TestSuiteResult.prototype.addFailure = function addFailure(failure, time) { |
1311 | * | 1311 | * |
1312 | * @return Number | 1312 | * @return Number |
1313 | */ | 1313 | */ |
1314 | TestSuiteResult.prototype.calculateDuration = function calculateDuration() { | 1314 | TestCaseResult.prototype.calculateDuration = function calculateDuration() { |
1315 | "use strict"; | 1315 | "use strict"; |
1316 | function add(a, b) { | 1316 | function add(a, b) { |
1317 | return a + b; | 1317 | return a + b; | ... | ... |
... | @@ -32,6 +32,7 @@ | ... | @@ -32,6 +32,7 @@ |
32 | 32 | ||
33 | var utils = require('utils'); | 33 | var utils = require('utils'); |
34 | var fs = require('fs'); | 34 | var fs = require('fs'); |
35 | var TestSuiteResult = require('tester').TestSuiteResult; | ||
35 | 36 | ||
36 | /** | 37 | /** |
37 | * Generates a value for 'classname' attribute of the JUnit XML report. | 38 | * Generates a value for 'classname' attribute of the JUnit XML report. |
... | @@ -95,7 +96,7 @@ exports.XUnitExporter = XUnitExporter; | ... | @@ -95,7 +96,7 @@ exports.XUnitExporter = XUnitExporter; |
95 | */ | 96 | */ |
96 | XUnitExporter.prototype.getXML = function getXML() { | 97 | XUnitExporter.prototype.getXML = function getXML() { |
97 | "use strict"; | 98 | "use strict"; |
98 | if (!(this.results instanceof require('tester').TestSuite)) { | 99 | if (!(this.results instanceof TestSuiteResult)) { |
99 | throw new CasperError('Results not set, cannot get XML.'); | 100 | throw new CasperError('Results not set, cannot get XML.'); |
100 | } | 101 | } |
101 | this.results.forEach(function(result) { | 102 | this.results.forEach(function(result) { |
... | @@ -147,7 +148,7 @@ XUnitExporter.prototype.getXML = function getXML() { | ... | @@ -147,7 +148,7 @@ XUnitExporter.prototype.getXML = function getXML() { |
147 | */ | 148 | */ |
148 | XUnitExporter.prototype.setResults = function setResults(results) { | 149 | XUnitExporter.prototype.setResults = function setResults(results) { |
149 | "use strict"; | 150 | "use strict"; |
150 | if (!(results instanceof require('tester').TestSuite)) { | 151 | if (!(results instanceof TestSuiteResult)) { |
151 | throw new CasperError('Invalid results type.'); | 152 | throw new CasperError('Invalid results type.'); |
152 | } | 153 | } |
153 | return this.results = results; | 154 | return this.results = results; | ... | ... |
... | @@ -3,25 +3,7 @@ | ... | @@ -3,25 +3,7 @@ |
3 | var fs = require('fs'); | 3 | var fs = require('fs'); |
4 | var t = casper.test; | 4 | var t = casper.test; |
5 | 5 | ||
6 | casper.start(); | 6 | casper.start('tests/site/index.html', function() { |
7 | |||
8 | t.comment('Tester.sortFiles()'); | ||
9 | var testDirRoot = fs.pathJoin(phantom.casperPath, 'tests', 'testdir'); | ||
10 | var files = t.findTestFiles(testDirRoot); | ||
11 | var expected = [ | ||
12 | "01_a/abc.js", | ||
13 | "01_a/def.js", | ||
14 | "02_b/abc.js", | ||
15 | "03_a.js", | ||
16 | "03_b.js", | ||
17 | "04/01_init.js", | ||
18 | "04/02_do.js" | ||
19 | ].map(function(entry) { | ||
20 | return fs.pathJoin.apply(fs, [testDirRoot].concat(entry.split('/'))); | ||
21 | }); | ||
22 | t.assertEquals(files, expected, 'findTestFiles() find test files and sort them'); | ||
23 | |||
24 | casper.thenOpen('tests/site/index.html', function() { | ||
25 | t.comment('Tester.assertTextExists()'); | 7 | t.comment('Tester.assertTextExists()'); |
26 | t.assertTextExists('form', 'Tester.assertTextExists() checks that page body contains text'); | 8 | t.assertTextExists('form', 'Tester.assertTextExists() checks that page body contains text'); |
27 | 9 | ||
... | @@ -201,5 +183,5 @@ casper.reload(function() { | ... | @@ -201,5 +183,5 @@ casper.reload(function() { |
201 | }); | 183 | }); |
202 | 184 | ||
203 | casper.run(function() { | 185 | casper.run(function() { |
204 | t.done(55); | 186 | t.done(54); |
205 | }); | 187 | }); | ... | ... |
tests/suites/tester/test-order.js
0 → 100644
1 | /*jshint strict:false*/ | ||
2 | /*global CasperError casper console phantom require*/ | ||
3 | var fs = require('fs'); | ||
4 | |||
5 | casper.test.begin('Tester.sortFiles()', function suite(test) { | ||
6 | var testDirRoot = fs.pathJoin(phantom.casperPath, 'tests', 'testdir'); | ||
7 | var files = test.findTestFiles(testDirRoot); | ||
8 | var expected = [ | ||
9 | "01_a/abc.js", | ||
10 | "01_a/def.js", | ||
11 | "02_b/abc.js", | ||
12 | "03_a.js", | ||
13 | "03_b.js", | ||
14 | "04/01_init.js", | ||
15 | "04/02_do.js" | ||
16 | ].map(function(entry) { | ||
17 | return fs.pathJoin.apply(fs, [testDirRoot].concat(entry.split('/'))); | ||
18 | }); | ||
19 | test.assertEquals(files, expected, 'findTestFiles() find test files and sort them'); | ||
20 | test.done(1); | ||
21 | }); |
tests/suites/tester/testcase.js
0 → 100644
1 | /*jshint strict:false maxstatements:99 maxcomplexity:99 */ | ||
2 | /*global CasperError casper console phantom require*/ | ||
3 | |||
4 | var TestCaseResult = require('tester').TestCaseResult; | ||
5 | |||
6 | casper.test.begin('TestCaseResult.constructor() tests', function(test) { | ||
7 | var caseResult1 = new TestCaseResult(); | ||
8 | test.assertType(caseResult1.name, "undefined", 'TestCaseResult.constructor() name is undefined by default'); | ||
9 | test.assertType(caseResult1.file, "undefined", 'TestCaseResult.constructor() file is undefined by default'); | ||
10 | var caseResult2 = new TestCaseResult({name: 'foo', file: '/tmp/foo'}); | ||
11 | test.assertEquals(caseResult2.name, "foo", 'TestCaseResult.constructor() can set name'); | ||
12 | test.assertEquals(caseResult2.file, "/tmp/foo", 'TestCaseResult.constructor() can set file'); | ||
13 | test.done(4); | ||
14 | }); | ||
15 | |||
16 | casper.test.begin('TestCaseResult.addSuccess() and TestCaseResult.addFailure() tests', function(test) { | ||
17 | var caseResult = new TestCaseResult({name: 'foo', file: '/tmp/foo'}); | ||
18 | test.assertEquals(caseResult.assertions, 0, 'test case result counts no assertion by default'); | ||
19 | test.assertEquals(caseResult.passed, 0, 'test case result counts no success by default'); | ||
20 | test.assertEquals(caseResult.failed, 0, 'test case result counts no failure by default'); | ||
21 | test.assertEquals(caseResult.calculateDuration(), 0, | ||
22 | 'TestCaseResult.calculateDuration() computes initial tests duration'); | ||
23 | var success = {}; | ||
24 | caseResult.addSuccess(success, 1337); | ||
25 | test.assertEquals(caseResult.assertions, 1, 'test case result counts one assertion'); | ||
26 | test.assertEquals(caseResult.passed, 1, 'test case result counts one success'); | ||
27 | test.assertEquals(caseResult.failed, 0, 'test case result counts no failure'); | ||
28 | test.assertEquals(caseResult.passes[0], success, 'TestCaseResult.addSuccess() added a success to the stack'); | ||
29 | test.assertEquals(caseResult.passes[0].time, 1337, 'TestCaseResult.addSuccess() added test duration'); | ||
30 | test.assertEquals(caseResult.passes[0].suite, 'foo', 'TestCaseResult.addSuccess() added suite name'); | ||
31 | test.assertEquals(caseResult.calculateDuration(), 1337, | ||
32 | 'TestCaseResult.calculateDuration() computes tests duration'); | ||
33 | var failure = {}; | ||
34 | caseResult.addFailure(failure, 42); | ||
35 | test.assertEquals(caseResult.assertions, 2, 'test case result counts two assertions'); | ||
36 | test.assertEquals(caseResult.passed, 1, 'test case result counts one success'); | ||
37 | test.assertEquals(caseResult.failed, 1, 'test case result counts no failure'); | ||
38 | test.assertEquals(caseResult.failures[0], failure, 'TestCaseResult.addFailure() added a failure to the stack'); | ||
39 | test.assertEquals(caseResult.failures[0].time, 42, 'TestCaseResult.addFailure() added test duration'); | ||
40 | test.assertEquals(caseResult.failures[0].suite, 'foo', 'TestCaseResult.addFailure() added suite name'); | ||
41 | test.assertEquals(caseResult.calculateDuration(), 1337 + 42, | ||
42 | 'TestCaseResult.calculateDuration() computes new tests duration'); | ||
43 | caseResult.addSuccess({}, 1000); | ||
44 | test.assertEquals(caseResult.assertions, 3, 'test case result counts three assertions'); | ||
45 | test.assertEquals(caseResult.passed, 2, 'test case result counts two successes'); | ||
46 | test.assertEquals(caseResult.failed, 1, 'test case result counts no failure'); | ||
47 | test.assertEquals(caseResult.calculateDuration(), 1337 + 42 + 1000, | ||
48 | 'TestCaseResult.calculateDuration() computes new tests duration'); | ||
49 | test.done(22); | ||
50 | }); |
tests/suites/tester/testsuite.js
0 → 100644
1 | /*jshint strict:false*/ | ||
2 | /*global CasperError casper console phantom require*/ | ||
3 | |||
4 | var TestCaseResult = require('tester').TestCaseResult, | ||
5 | TestSuiteResult = require('tester').TestSuiteResult; | ||
6 | |||
7 | function generateCaseResult(options) { | ||
8 | var i, | ||
9 | nPasses = options && ~~options.nPasses, | ||
10 | nFailures = options && ~~options.nFailures, | ||
11 | caseResult = new TestCaseResult(options); | ||
12 | for (i = 0; i < nFailures; i++) { | ||
13 | caseResult.addFailure({}, i * 1000); | ||
14 | } | ||
15 | for (i = 0; i < nPasses; i++) { | ||
16 | caseResult.addSuccess({}, i * 1000); | ||
17 | } | ||
18 | return caseResult; | ||
19 | } | ||
20 | |||
21 | casper.test.begin('TestSuiteResult() basic tests', function(test) { | ||
22 | var suiteResult = new TestSuiteResult(); | ||
23 | test.assertEquals(suiteResult.constructor.name, 'Array', 'TestSuiteResult() is derived from Array'); | ||
24 | test.assertEquals(suiteResult.countTotal(), 0); | ||
25 | test.assertEquals(suiteResult.countFailed(), 0); | ||
26 | test.assertEquals(suiteResult.countPassed(), 0); | ||
27 | test.assertEquals(suiteResult.getAllFailures(), []); | ||
28 | test.assertEquals(suiteResult.getAllPasses(), []); | ||
29 | test.assertEquals(suiteResult.getAllResults(), []); | ||
30 | test.assertEquals(suiteResult.calculateDuration(), 0); | ||
31 | test.done(); | ||
32 | }); | ||
33 | |||
34 | casper.test.begin('TestSuiteResult() accumulation tests', function(test) { | ||
35 | var suiteResult = new TestSuiteResult(); | ||
36 | suiteResult.push(generateCaseResult({ | ||
37 | name: 'foo', | ||
38 | file: '/tmp/foo', | ||
39 | nPasses: 4, | ||
40 | nFailures: 1 | ||
41 | })); | ||
42 | suiteResult.push(generateCaseResult({ | ||
43 | name: 'bar', | ||
44 | file: '/tmp/bar', | ||
45 | nPasses: 3, | ||
46 | nFailures: 0 | ||
47 | })); | ||
48 | test.assertEquals(suiteResult.countTotal(), 8); | ||
49 | test.assertEquals(suiteResult.countFailed(), 1); | ||
50 | test.assertEquals(suiteResult.countPassed(), 7); | ||
51 | test.assertEquals(suiteResult.getAllFailures().length, 1); | ||
52 | test.assertEquals(suiteResult.getAllPasses().length, 7); | ||
53 | test.assertEquals(suiteResult.getAllResults().length, 8); | ||
54 | test.assertEquals(suiteResult.calculateDuration(), 9000); | ||
55 | test.done(); | ||
56 | }); |
... | @@ -5,7 +5,7 @@ var testpage = require('webpage').create(); | ... | @@ -5,7 +5,7 @@ var testpage = require('webpage').create(); |
5 | 5 | ||
6 | casper.test.begin('XUnitReporter() initialization', function suite() { | 6 | casper.test.begin('XUnitReporter() initialization', function suite() { |
7 | var xunit = require('xunit').create(); | 7 | var xunit = require('xunit').create(); |
8 | var results = new tester.TestSuite(); | 8 | var results = new tester.TestSuiteResult(); |
9 | xunit.setResults(results); | 9 | xunit.setResults(results); |
10 | this.assertTruthy(xunit.getXML()); | 10 | this.assertTruthy(xunit.getXML()); |
11 | this.done(1); | 11 | this.done(1); |
... | @@ -13,13 +13,13 @@ casper.test.begin('XUnitReporter() initialization', function suite() { | ... | @@ -13,13 +13,13 @@ casper.test.begin('XUnitReporter() initialization', function suite() { |
13 | 13 | ||
14 | casper.test.begin('XUnitReporter() can hold test suites', function suite() { | 14 | casper.test.begin('XUnitReporter() can hold test suites', function suite() { |
15 | var xunit = require('xunit').create(); | 15 | var xunit = require('xunit').create(); |
16 | var results = new tester.TestSuite(); | 16 | var results = new tester.TestSuiteResult(); |
17 | var suite1 = new tester.TestSuiteResult({ | 17 | var suite1 = new tester.TestCaseResult({ |
18 | name: 'foo', | 18 | name: 'foo', |
19 | file: '/foo' | 19 | file: '/foo' |
20 | }); | 20 | }); |
21 | results.push(suite1); | 21 | results.push(suite1); |
22 | var suite2 = new tester.TestSuiteResult({ | 22 | var suite2 = new tester.TestCaseResult({ |
23 | name: 'bar', | 23 | name: 'bar', |
24 | file: '/bar' | 24 | file: '/bar' |
25 | }); | 25 | }); |
... | @@ -37,8 +37,8 @@ casper.test.begin('XUnitReporter() can hold test suites', function suite() { | ... | @@ -37,8 +37,8 @@ casper.test.begin('XUnitReporter() can hold test suites', function suite() { |
37 | 37 | ||
38 | casper.test.begin('XUnitReporter() can hold a suite with a succesful test', function suite() { | 38 | casper.test.begin('XUnitReporter() can hold a suite with a succesful test', function suite() { |
39 | var xunit = require('xunit').create(); | 39 | var xunit = require('xunit').create(); |
40 | var results = new tester.TestSuite(); | 40 | var results = new tester.TestSuiteResult(); |
41 | var suite1 = new tester.TestSuiteResult({ | 41 | var suite1 = new tester.TestCaseResult({ |
42 | name: 'foo', | 42 | name: 'foo', |
43 | file: '/foo' | 43 | file: '/foo' |
44 | }); | 44 | }); |
... | @@ -57,8 +57,8 @@ casper.test.begin('XUnitReporter() can hold a suite with a succesful test', func | ... | @@ -57,8 +57,8 @@ casper.test.begin('XUnitReporter() can hold a suite with a succesful test', func |
57 | 57 | ||
58 | casper.test.begin('XUnitReporter() can handle a failed test', function suite() { | 58 | casper.test.begin('XUnitReporter() can handle a failed test', function suite() { |
59 | var xunit = require('xunit').create(); | 59 | var xunit = require('xunit').create(); |
60 | var results = new tester.TestSuite(); | 60 | var results = new tester.TestSuiteResult(); |
61 | var suite1 = new tester.TestSuiteResult({ | 61 | var suite1 = new tester.TestCaseResult({ |
62 | name: 'foo', | 62 | name: 'foo', |
63 | file: '/foo' | 63 | file: '/foo' |
64 | }); | 64 | }); | ... | ... |
-
Please register or sign in to post a comment