Cherry pick from 5838fde95e: Partial refactoring fix of tests dependency tree