I'm not sure if there is an official policy, but it seems fairly common to use hardcoded values in unit tests in Moodle, for example:
Hardcoded values cause us problems at Totara because we have to customise Moodle tests to get them passing.
It also makes the tests brittle to changes in Moodle itself, if the number of default roles are updated then the tests need to be updated to pass.
In cases where you want to check data is being created it is possible to refactor this to assert against the difference before/after an action, which removes the dependency on the absolute number of items.
Are the use of hardcoded values like this encouraged or discouraged? Would Moodle be open to accepting a patch that converted them into relative values?