Kernel::Test::Role::IsTestCase::Generic

NAME

Kernel::Test::Role::IsTestCase::Generic – base role for all test cases.

DESCRIPTION

This role needs to be consumed in all test cases, either directly or by a derived role like Kernel::Test::Role::IsTestCase::Selenium, which also calls this role to be pulled in.

USAGE

HANDLING STATIC TEST DATA

Every test case should store any needed sample files in a sub-folder with the suffix .files, like this:

    Kernel/Test/Case/EmailParser/FilenameWithNewline.pm
    Kernel/Test/Case/EmailParser/FilenameWithNewline.pm.files/FilenameWithNewline.box
    ...

This can then be easily accessed from the test to use the file contents using the __FILE__ macro to keep the code readable:

    my $EmailRef = $Kernel::OM->Get('Kernel::System::Main')->FileRead(
        Location => __FILE__ . ".files/FilenameWithNewline.box",
    );

PUBLIC INTERFACE

BUILD()

This method can be modified in roles to perform early initialization code.

SkipTest()

Override this method in tests and/or roles to perform an early exit, without even calling the other hooks or test code.

StartHook()

This method can be modified in roles to perform pre-test setup code, such as starting a database transaction.

PreRun()

Tests can implement this method to provide code that will always be called before the test run.

Run()

All tests MUST implement this method to provide the actual test code.

HandleException()

This method is called in case of exceptions during test execution.

Override or modify it to add custom behaviour, e. g. taking screenshots in Selenium tests.

PostRun()

Tests can implement this method to provide clean-up code that will always be called after the test, even in case of exceptions.

FinishHook()

This method can be modified in roles to perform post-test cleanup code, such as aborting a database transaction.

Execute()

This method runs the different test phases, and reports the results back to the main process.

_UnitTestSettingsSet()

Sets needed settings for unit testing.

    $Self->_UnitTestSettingsSet();
Scroll to Top