Skip to content

Commit 5e7f885

Browse files
committedSep 14, 2014
Improved statistics for test case and test suite results
1 parent e997aaf commit 5e7f885

File tree

5 files changed

+71
-11
lines changed

5 files changed

+71
-11
lines changed
 

Diff for: ‎ide/main/src/content/editor.js

+28-7
Original file line numberDiff line numberDiff line change
@@ -845,15 +845,22 @@ Editor.prototype.showInBrowser = function (url, newWindow) {
845845
};
846846

847847
Editor.prototype.playCurrentTestCase = function (next, index, total) {
848+
var start = Date.now();
848849
var self = this;
849850
self.getUserLog().info("Playing test case " + (self.app.getTestCase().getTitle() || ''));
850851
self.app.notify("testCasePlayStart", self.app.getTestCase());
851852
this.selDebugger.start(function (failed) {
852853
self.log.debug("finished execution of test case: failed=" + failed);
853854
var testCase = self.suiteTreeView.getCurrentTestCase();
854855
if (testCase) {
855-
testCase.testResult = failed ? "failed" : "passed";
856-
self.getUserLog().info("Test case " + testCase.testResult);
856+
testCase.testResult = {
857+
summary: failed ? "failed" : "passed",
858+
// remember all in milliseconds
859+
start: start,
860+
end: Date.now(),
861+
dur: Date.now() - start
862+
};
863+
self.getUserLog().info("Test case " + testCase.testResult.summary);
857864
self.app.notify("testCasePlayDone", testCase);
858865
} else {
859866
self.getUserLog().error("current test case not found");
@@ -872,25 +879,39 @@ Editor.prototype.playTestSuite = function (startIndex) {
872879
startIndex = 0;
873880
}
874881
var index = startIndex - 1;
875-
this.app.getTestSuite().tests.forEach(function (test) {
882+
var testSuite = this.app.getTestSuite();
883+
testSuite.tests.forEach(function (test) {
876884
if (test.testResult) {
877885
delete test.testResult;
878886
}
879887
});
880888
this.suiteTreeView.refresh();
881889
this.testSuiteProgress.reset();
890+
var start = Date.now();
891+
testSuite.testSuiteProgress = this.testSuiteProgress;
882892
var self = this;
883893
self.app.notify("testSuitePlayStart");
884-
var total = this.app.getTestSuite().tests.length - startIndex;
894+
var total = testSuite.tests.length - startIndex;
885895
(function () {
886-
if (++index < self.app.getTestSuite().tests.length) {
896+
if (++index < testSuite.tests.length) {
887897
self.suiteTreeView.scrollToRow(index);
888-
self.app.showTestCaseFromSuite(self.app.getTestSuite().tests[index]);
898+
self.app.showTestCaseFromSuite(testSuite.tests[index]);
889899
self.playCurrentTestCase(arguments.callee, index, total);
890900
} else {
891901
//Suite done
902+
testSuite.suiteResult = {
903+
summary: total == self.testSuiteProgress.runs && self.testSuiteProgress.failures == 0 ? 'passed' : 'failed',
904+
total: total,
905+
ran: self.testSuiteProgress.runs,
906+
failed: self.testSuiteProgress.failures,
907+
passed: self.testSuiteProgress.runs - self.testSuiteProgress.failures,
908+
// remember all in milliseconds
909+
start: start,
910+
end: Date.now(),
911+
dur: Date.now() - start
912+
};
892913
self.getUserLog().info("Test suite completed: " + self.testSuiteProgress.runs + " played, " + (self.testSuiteProgress.failures ? self.testSuiteProgress.failures + " failed" : " all passed!"));
893-
self.app.notify("testSuitePlayDone", total, self.testSuiteProgress.runs, self.testSuiteProgress.failures);
914+
self.app.notify("testSuitePlayDone", testSuite.suiteResult);
894915
}
895916
})();
896917
};

Diff for: ‎ide/main/src/content/selenium-runner.js

+2
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ objectExtend(IDETestLoop.prototype, {
237237
LOG.error(result.failureMessage);
238238
testCase.debugContext.failed = true;
239239
testCase.debugContext.currentCommand().result = 'failed';
240+
testCase.debugContext.currentCommand().failureMessage = result.failureMessage;
240241
} else if (result.passed) {
241242
testCase.debugContext.currentCommand().result = 'passed';
242243
} else {
@@ -256,6 +257,7 @@ objectExtend(IDETestLoop.prototype, {
256257
LOG.debug("commandError");
257258
testCase.debugContext.failed = true;
258259
testCase.debugContext.currentCommand().result = 'failed';
260+
testCase.debugContext.currentCommand().failureMessage = errorMessage;
259261
editor.view.rowUpdated(testCase.debugContext.debugIndex);
260262
}
261263
},

Diff for: ‎ide/main/src/content/suiteTreeView.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ objectExtend(SuiteTreeView.prototype, {
195195
getRowProperties: function(row, props) {
196196
if (this.selection.isSelected(row)) return;
197197
var testCase = this.getTestSuite().tests[row];
198-
if (testCase.testResult) {
199-
if (testCase.testResult == 'passed') {
198+
if (testCase.testResult && testCase.testResult.summary) {
199+
if (testCase.testResult.summary == 'passed') {
200200
return XulUtils.setProperty(props, "commandPassed");
201-
} else if (testCase.testResult == 'failed') {
201+
} else if (testCase.testResult.summary == 'failed') {
202202
return XulUtils.setProperty(props, "commandFailed");
203203
}
204204
}

Diff for: ‎ide/main/src/content/testCase.js

+2
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ function TestCase(tempTitle) {
352352
this.failed = false;
353353
this.started = false;
354354
this.debugIndex = -1;
355+
this.runTimeStamp = 0;
355356
},
356357

357358
nextCommand: function() {
@@ -364,6 +365,7 @@ function TestCase(tempTitle) {
364365
for (; this.debugIndex < testCase.commands.length; this.debugIndex++) {
365366
var command = testCase.commands[this.debugIndex];
366367
if (command.type == 'command') {
368+
this.runTimeStamp = Date.now();
367369
return command;
368370
}
369371
}

Diff for: ‎ide/main/src/content/testSuite.js

+36-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
function TestSuite() {
1818
this.tests = [];
19+
this.title = "Test Suite";
1920
this.modified = false; //Samit: Enh: Support for change detection
2021
}
2122

@@ -153,6 +154,19 @@ TestSuite.prototype = {
153154
return content;
154155
},
155156

157+
result: function() {
158+
var r = {
159+
title: "Test Suite",
160+
result: this.suiteResult,
161+
//TODO progress and baseURL and maybe real title?
162+
tests: []
163+
};
164+
r.tests = this.tests.map(function(test) {
165+
return test.result();
166+
});
167+
return r;
168+
},
169+
156170
generateNewTestCaseTitle: function() {
157171
if (this.tests.some(function(test) { return /^Untitled/.test(test.getTitle()) })) {
158172
var max = 1;
@@ -261,7 +275,28 @@ TestSuite.TestCase.prototype = {
261275
format: function() {
262276
return "<tr><td><a href=\"" + this.getRelativeFilePath() + "\">" +
263277
this.getTitle() + "</a></td></tr>\n";
278+
},
279+
280+
result: function() {
281+
var r = {
282+
title: this.getTitle(),
283+
result: this.testResult,
284+
commands: []
285+
};
286+
if (this.content) {
287+
r.baseURL = this.content.baseURL;
288+
r.commands = this.content.commands.map(function(cmd) {
289+
if (cmd.type == 'comment') {
290+
return { type: cmd.type, comment: cmd.comment };
291+
} else if (cmd.type == 'command') {
292+
return { type: cmd.type, command: cmd.command, target: cmd.target, value: cmd.value, result: cmd.result, error: cmd.failureMessage };
293+
}
294+
return { type: cmd.type };
295+
});
264296
}
265-
}
297+
return r;
298+
}
299+
300+
};
266301

267302
observable(TestSuite);

0 commit comments

Comments
 (0)
Please sign in to comment.