tuneup_js
tuneup_js copied to clipboard
Basic setup teardown functionality
I would like to add basic setup teardown functionality to the tests. I have a working code which checks if there is a setup, teardown function is defined it calls them before the execution, which is similar to the other unit test frameworks. Any thoughts on this ? If we have to support for suite level setup teardown what should be the preferred approach ?
I think we could maybe add two functions setup() and teardown() in the beginning and end of the test function. So it could be something like this
var noop = function (){};
var setupTest = noop;
var tearDownTest = noop;
function test(title, f, options) {
if (typeof TUNEUP_ONLY_RUN !== 'undefined') {
for (var i = 0; i < TUNEUP_ONLY_RUN.length; i++) {
if (new RegExp("^" + TUNEUP_ONLY_RUN[i] + "$").test(title)) {
break;
}
if (i == TUNEUP_ONLY_RUN.length -1) {
return;
}
}
}
if (!options) {
options = testCreateDefaultOptions();
}
target = UIATarget.localTarget();
application = target.frontMostApp();
UIALogger.logStart(title);
try {
setupTest();
f(target, application);
UIALogger.logPass(title);
tearDownTest();
}
catch (e) {
UIALogger.logError(e.toString());
if (options.logStackTrace) UIALogger.logError(e.stack);
if (options.logTree) target.logElementTree();
if (options.logTreeJSON) application.mainWindow().logElementTreeJSON();
if (options.screenCapture) target.captureScreenWithName(title + '-fail');
UIALogger.logFail(title);
}
}
In documentation we could ask them to modify setupTest()
and tearDownTest()
so that the function is overridden for the test or group of tests in a single file. If it sounds good I can create a pull request with the above mentioned functionality.
Hi @anoopknayak, This requires few more checks where traditional setupTest or tearDownTest if fails, the test won't run, but we should log it properly that fixture failed. Please go ahead and raise a pull request with your changes and I shall review.