Affects Version/s: 3.9.6, 3.10.3, 3.11, 4.0
Fix Version/s: None
Component/s: Unit tests
Affected Branches:MOODLE_310_STABLE, MOODLE_311_STABLE, MOODLE_39_STABLE, MOODLE_400_STABLE
This was detected @
MDL-69102 but there maybe other places where the same is happening.
All our tests-cases are descendants of base_testcase, then basic and advanced, then others, that can also have descendants... and so on. See partial map below:
This inheritance tree/schema is useful to be able to provide similar testing facilities by component, say questions, say an activity...
But it has a trade-off that we must avoid at all costs:
The intermediate test-cases (being parents) in the tree/schema cannot have unit-tests by themselves (aka, cannot have test_xxxx methods). Only "final" test-cases (those not being parents, can.
Why? Because if a test-case has one test_xxxx method... and it's the parent of, say, 10 children test-cases.... then the test_xxxx unit-test will be executed 11 times in total. A complete waste of process and time.
The problem is really easy to reproduce, just crate new test-cases extending some existing test-case, run tests and compare the number of unit-tests executed... magically they will increase by the number of unit-tests in the parent test-case.
A current existing example of the problem is, for example:
If you run with the --filter option any of the unit-tests you will see that, always, 2 tests are executed: the original in badgeslib_test and the "inherited" in events_test.
So, this issue is about:
1) generate the complete tree/class-map of all the existing test-cases in core.
2) find parents in the tree having unit tests (test_xxxx methods)
3) move them away from parents to new child.
4) ideally, keep this controlled in a continuous way.