Skip to content

Customizing Omnis TAP

Alex Clay edited this page Sep 4, 2017 · 3 revisions

You may want to add functionality to your test classes or additional assertion to ioTAP. If these are enhancements that would be useful to all Omnis developers, please consider submitting a pull request to add them to OmnisTAP!

However, some enhancements may be linked to your particular codebase and you need to simply add them to your project only. OmnisTAP is designed to make customizing the test classes and test methods easy.

Adding a custom test superclass

The following techniques rely on subclassing omnistap.ogTAPSuper in your project, then subclassing your test classes from the intermediate superclass. Be sure to call Do inherited in any class-specific $setup() and $teardown() methods.

The Jump to Counterpart command on the TAP menu will automatically add a Do inherited call to $setup(). However, it will continue to make subclasses of omnistap.ogTAPSuper. You can customize the superclass new test classes by subclassing omnistap.ogTAPMenuController and overriding $_getSuperclassForTestClass () to return the name of your superclass.

In your project you need to replace the TAP menu controller with your subclass. This is ideally done in your startup task after omnistap.lbs is opened.

Do $itasks.omnistap.$getOmnisTAPMenu() Returns lirOmnisTAPMenu
Do lirOmnisTAPMenu.$getMenuController().$deleteref()

Do $objects.[your TAP menu controller].$newref(lirOmnisTAPMenu) Returns lorTAPMenuController
Do lirOmnisTAPMenu.$setMenuController(lorTAPMenuController)

Adding standard test metrics

$setup() and $teardown() provide convenient hooks to adding additional metrics to each of your test. For example, you could assert that #FD doesn't change, that no SQL is executed during a unit test, or that the transaction state for your database session doesn't change. In $setup() take a baseline reading and store it in an instance variable, then in $teardown() assert the current value versus the baseline.

$setup() {
  Calculate icFD as #FD
}

$teardown() {
  If #FD<>icFD
    Do ioTAP.$fail(con("#FD changed from ",icFD," to ",#FD"))
  End if
}

Note we only generate TAP output on failure. This will avoid excessive output that can slow down the test run.

Adding test helpers

If you need to frequently set up a your environment for tests but not so often it should done for every test, consider adding some helper methods to your test superclass. For example, you could add a $createDummyUser() to replace a task variable for the current user object with a known stub. Or, add a method to start and end a testing state on your database session objects that wraps $begin() and $rollback() calls.

Adding custom assertions

You can override the ioTAP object on your test with a subclass that adds extra assertions. Subclass omnistap.ogTAPMethods and add your assertions. In your testing superclass, add a $construct() and instantiate your test methods into ioTAP:

Do $objects.[your test method class].$new() Returns ioTAP

Customizing the display name for your tests

You can control how a test class appears in the OmnisTAP window by overriding $getDisplayName() on your testing class.