Closed amcsi closed 3 years ago
I tried to reproduce the bug:
In TestSuiteSorter I see this, which indicates the tests are being sorted, and not individually wrapped:
The final firing order I observe is also indicating the tests were properly sorted before running.
So maybe somewhere along the line this issue already got fixed.
Ok, it seems to work for me too... assuming ordering of tests only happen within a TestCase. I may have wrongly assumed that ordering test execution by duration (or anything else) would be per test across the testsuite, meaning PHPUnit would switch back and forth between TestCases depending on which tests run faster. My test was the only test in its TestCase (just not the only test in the test suite).
Summary
I noticed while debugging a little that for some reason PHPUnit seems to take the list of tests in a testsuite and further wrap each test in another testsuite. So you get this hierarcy:
You can see here this list of "testsuites". They're actually supposed to be the "tests", but each is wrapped in a testsuite:
The problem is that the logic for sorting the execution order seems to be done locally to the testsuite. Since each test ends up along wrapped in a single dedicated "test suite", what ends up happening is each test gets "sorted" alone separately, so basically nothing gets sorted. Here is an example of "sorting" about to happen for a single test (I have 10+ tests).
I'm expecting for
Current behavior
Each test gets wrapped in its own test suite, and thus sorting does not work.
How to reproduce
Create any two PHPUnit tests under the same test suite. Run them with
--order-by=duration
. Debug at\PHPUnit\Runner\TestSuiteSorter::sortByDuration()
and see that the tests array always has a single element in it. So sorting would do nothing.Expected behavior
The tree should appear like so:
Without the additional wrapping of tests into testsuites. And putting a breakpoint at a sorting method, multiple tests should appear, not only just one.