Previous Topic: Companion ToolbarNext Topic: Complex Object Editor (COE)


DevTest Hooks

DevTest hooks are an automatic global means to execute logic at start/end of a test case. Hooks apply that logic to all test cases in the environment where the hook is deployed.

Hooks work similarly to companions; they run before a test starts and after a test finishes.

The difference is, hooks are defined at the application level, and every test case in DevTest runs the hooks. If a hook exists, it is used for every test case.

A hook is a mechanism that allows for the automatic inclusion of test setup logic or teardown logic, or both, for all the tests running in DevTest. An alternate definition of a hook is a system-wide companion. Anything that a hook can perform can be modeled as a companion.

Hooks are used to configure test environments, prevent tests that are improperly configured or do not follow defined best practices from executing, and provide common operations.

Hooks are Java classes that are on the DevTest class path. Hooks are NOT defined in .lisaextensions file, but in local.properties or lisa.properties as

lisa.hooks=com.mypackage1.MyHook1, com.mypackage2.MyHook2

A hook is executed or invoked at the start and end of all subprocesses in a test case in addition to the test case itself. If a test case has three subprocesses, the hook logic is executed four times. The logic is executed once for the main test and once for each of three subprocesses.

To prevent a subprocess from executing startHook, endHook, or both, include the following action:

String marker = (String)testExec.getStateValue(TestExec.FROM_PARENT_TEST_MARKER_KEY)
"marker" is set to "true" only when it is a subprocess.
if (!"true".equals(marker))
all start/end Hook logic here that should not be executed when in sub process

Differences between Hooks and Companions