Skip to content

Commit

Permalink
Improved statistics for test case and test suite results
Browse files Browse the repository at this point in the history
  • Loading branch information
samitbadle committed Sep 14, 2014
1 parent e997aaf commit 5e7f885
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 11 deletions.
35 changes: 28 additions & 7 deletions ide/main/src/content/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -845,15 +845,22 @@ Editor.prototype.showInBrowser = function (url, newWindow) {
};

Editor.prototype.playCurrentTestCase = function (next, index, total) {
var start = Date.now();
var self = this;
self.getUserLog().info("Playing test case " + (self.app.getTestCase().getTitle() || ''));
self.app.notify("testCasePlayStart", self.app.getTestCase());
this.selDebugger.start(function (failed) {
self.log.debug("finished execution of test case: failed=" + failed);
var testCase = self.suiteTreeView.getCurrentTestCase();
if (testCase) {
testCase.testResult = failed ? "failed" : "passed";
self.getUserLog().info("Test case " + testCase.testResult);
testCase.testResult = {
summary: failed ? "failed" : "passed",
// remember all in milliseconds
start: start,
end: Date.now(),
dur: Date.now() - start
};
self.getUserLog().info("Test case " + testCase.testResult.summary);
self.app.notify("testCasePlayDone", testCase);
} else {
self.getUserLog().error("current test case not found");
Expand All @@ -872,25 +879,39 @@ Editor.prototype.playTestSuite = function (startIndex) {
startIndex = 0;
}
var index = startIndex - 1;
this.app.getTestSuite().tests.forEach(function (test) {
var testSuite = this.app.getTestSuite();
testSuite.tests.forEach(function (test) {
if (test.testResult) {
delete test.testResult;
}
});
this.suiteTreeView.refresh();
this.testSuiteProgress.reset();
var start = Date.now();
testSuite.testSuiteProgress = this.testSuiteProgress;
var self = this;
self.app.notify("testSuitePlayStart");
var total = this.app.getTestSuite().tests.length - startIndex;
var total = testSuite.tests.length - startIndex;
(function () {
if (++index < self.app.getTestSuite().tests.length) {
if (++index < testSuite.tests.length) {
self.suiteTreeView.scrollToRow(index);
self.app.showTestCaseFromSuite(self.app.getTestSuite().tests[index]);
self.app.showTestCaseFromSuite(testSuite.tests[index]);
self.playCurrentTestCase(arguments.callee, index, total);
} else {
//Suite done
testSuite.suiteResult = {
summary: total == self.testSuiteProgress.runs && self.testSuiteProgress.failures == 0 ? 'passed' : 'failed',
total: total,
ran: self.testSuiteProgress.runs,
failed: self.testSuiteProgress.failures,
passed: self.testSuiteProgress.runs - self.testSuiteProgress.failures,
// remember all in milliseconds
start: start,
end: Date.now(),
dur: Date.now() - start
};
self.getUserLog().info("Test suite completed: " + self.testSuiteProgress.runs + " played, " + (self.testSuiteProgress.failures ? self.testSuiteProgress.failures + " failed" : " all passed!"));
self.app.notify("testSuitePlayDone", total, self.testSuiteProgress.runs, self.testSuiteProgress.failures);
self.app.notify("testSuitePlayDone", testSuite.suiteResult);
}
})();
};
Expand Down
2 changes: 2 additions & 0 deletions ide/main/src/content/selenium-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ objectExtend(IDETestLoop.prototype, {
LOG.error(result.failureMessage);
testCase.debugContext.failed = true;
testCase.debugContext.currentCommand().result = 'failed';
testCase.debugContext.currentCommand().failureMessage = result.failureMessage;
} else if (result.passed) {
testCase.debugContext.currentCommand().result = 'passed';
} else {
Expand All @@ -256,6 +257,7 @@ objectExtend(IDETestLoop.prototype, {
LOG.debug("commandError");
testCase.debugContext.failed = true;
testCase.debugContext.currentCommand().result = 'failed';
testCase.debugContext.currentCommand().failureMessage = errorMessage;
editor.view.rowUpdated(testCase.debugContext.debugIndex);
}
},
Expand Down
6 changes: 3 additions & 3 deletions ide/main/src/content/suiteTreeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ objectExtend(SuiteTreeView.prototype, {
getRowProperties: function(row, props) {
if (this.selection.isSelected(row)) return;
var testCase = this.getTestSuite().tests[row];
if (testCase.testResult) {
if (testCase.testResult == 'passed') {
if (testCase.testResult && testCase.testResult.summary) {
if (testCase.testResult.summary == 'passed') {
return XulUtils.setProperty(props, "commandPassed");
} else if (testCase.testResult == 'failed') {
} else if (testCase.testResult.summary == 'failed') {
return XulUtils.setProperty(props, "commandFailed");
}
}
Expand Down
2 changes: 2 additions & 0 deletions ide/main/src/content/testCase.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ function TestCase(tempTitle) {
this.failed = false;
this.started = false;
this.debugIndex = -1;
this.runTimeStamp = 0;
},

nextCommand: function() {
Expand All @@ -364,6 +365,7 @@ function TestCase(tempTitle) {
for (; this.debugIndex < testCase.commands.length; this.debugIndex++) {
var command = testCase.commands[this.debugIndex];
if (command.type == 'command') {
this.runTimeStamp = Date.now();
return command;
}
}
Expand Down
37 changes: 36 additions & 1 deletion ide/main/src/content/testSuite.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

function TestSuite() {
this.tests = [];
this.title = "Test Suite";
this.modified = false; //Samit: Enh: Support for change detection
}

Expand Down Expand Up @@ -153,6 +154,19 @@ TestSuite.prototype = {
return content;
},

result: function() {
var r = {
title: "Test Suite",
result: this.suiteResult,
//TODO progress and baseURL and maybe real title?
tests: []
};
r.tests = this.tests.map(function(test) {
return test.result();
});
return r;
},

generateNewTestCaseTitle: function() {
if (this.tests.some(function(test) { return /^Untitled/.test(test.getTitle()) })) {
var max = 1;
Expand Down Expand Up @@ -261,7 +275,28 @@ TestSuite.TestCase.prototype = {
format: function() {
return "<tr><td><a href=\"" + this.getRelativeFilePath() + "\">" +
this.getTitle() + "</a></td></tr>\n";
},

result: function() {
var r = {
title: this.getTitle(),
result: this.testResult,
commands: []
};
if (this.content) {
r.baseURL = this.content.baseURL;
r.commands = this.content.commands.map(function(cmd) {
if (cmd.type == 'comment') {
return { type: cmd.type, comment: cmd.comment };
} else if (cmd.type == 'command') {
return { type: cmd.type, command: cmd.command, target: cmd.target, value: cmd.value, result: cmd.result, error: cmd.failureMessage };
}
return { type: cmd.type };
});
}
}
return r;
}

};

observable(TestSuite);

0 comments on commit 5e7f885

Please sign in to comment.