Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic setup teardown functionality #90

Open
vkolgi opened this issue Jul 12, 2016 · 2 comments
Open

Basic setup teardown functionality #90

vkolgi opened this issue Jul 12, 2016 · 2 comments

Comments

@vkolgi
Copy link
Owner

vkolgi commented Jul 12, 2016

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 ?

@anoopknayak
Copy link

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.

@vkolgi
Copy link
Owner Author

vkolgi commented Sep 23, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants