Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
sunAll 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.
Comment #2
alberto56 CreditAttribution: alberto56 commented@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.
Comment #3
alberto56 CreditAttribution: alberto56 commentedSetting as a duplicate of #2234479: Deprecate hook_test_* hooks in simpletest.