For the moment the only hooks I found in Simpletest are hook_test_group_started() and hook_test_group_finished(), which despite their name are invoked before and after test classes are run.

For a module I'm writing, I would need to run some code before and after all selected tests run. The test run can include several test groups, classes and cases.

Perhaps:

hook_tests_started($tests)
hook_tests_finished($results)

Comments

sun’s picture

Version: 7.x-dev » 8.x-dev

All changes go into the development version first.

I was actually considering to remove all of these hooks, because I cannot really see a use-case for them...

For that simpletest_turbo use-case, I think that a hook is not the right architecture. You should rather introduce a custom base test class, and make tests explicitly extend that. — Otherwise, it wouldn't be guaranteed that the test environment works as expected and is identical to WebTestBase.

alberto56’s picture

@sun thanks for your reply.

If I provide a custom base class as suggested, my setUp() function needs some way of knowing if it's the first time it is called or not, within a test run. I have not found a way of doing this: static functions, session variables, the cache: everything is reset between calls to a parent's setUp() from subclasses.

That is why i came to the conclusion that I needed some way of knowing when my test run (which can contain several test cases) begins and ends: a hook system is the only way I can think of.

Cheers,

Albert.

alberto56’s picture

Status: Active » Closed (duplicate)