Follow-up to #697760: Replace getInfo() in tests with native phpDoc + annotations (following PHPUnit)
Objective
-
Test classes may declare multiple
@groups now, but Simpletest only uses the first @group on discovery. -
The Simpletest UI needs to be updated to support multiple groups per test.
-
Affects both the web/UI table/list of tests as well as the CLI
run-tests.sh --list [group].
Proposed solution (Test discovery mechanism)
Modify TestDiscovery so that it keeps an association between all group annotations and test classes/files.
Add a 'groups' key (plural) to the output of getTestInfo(), so that multiple groups can be described while leaving the 'group' key to work the same as before.
Proposed solution (Web UI)
Moved to follow-up: #2858652: Support multiple @group test annotations in Simpletest UI
TestDiscovery should still support the 'group' key in the same way, so BC can be preserved for the UI form.
Proposed solution (CLI)
Allow the group parameter to find tests based on multiple @group annotations. run-tests.sh already allows a comma-separated list of groups.
| Comment | File | Size | Author |
|---|---|---|---|
| #56 | 2296615-56.patch | 467 bytes | lendude |
| #47 | 2296615_47.patch | 16.01 KB | mile23 |
| #43 | interdiff.txt | 712 bytes | mile23 |
| #43 | 2296615_43.patch | 14.39 KB | mile23 |
Comments
Comment #1
tim.plunkettComment #2
yesct commentedLocaleTranslateStringTourTest changed @group from Tour to locale in #697760: Replace getInfo() in tests with native phpDoc + annotations (following PHPUnit)
so when we can have two, it should probably have both.
Comment #6
mile23Comment #7
mile23This is a bug because you're trying to run tests that belong to an annotated
@group, but you won't get all the tests in that group.This is an 8.3.x bug because it improves the testing system, seems like it'd be allowed under alpha.
This resurfaces an older bug, because I had to run the tests under PHPUnit's parallel discovery mechanism in order to discover whether the change breaks test discovery. #2722731: Mark MissingDependentModuleUnitTest as incomplete
Comment #8
mile23Comment #9
mile23Comment #10
mile23Comment #11
mile23Moved the UI portion of this issue to a follow-up: #2858652: Support multiple @group test annotations in Simpletest UI
This allows a pure test system change for 8.3.x with UI changes moved to 8.4.x.
Updated issue summary.
Comment #12
mile23Patch still applies. Re-running test.
Comment #13
mile23Patch still applies. Re-running test.
Comment #14
mile23Patch still applies. re-running test.
Comment #16
mile23Needed a re-do after #2893371: Several methods theoretically added to TestInfoParsingTest were actually not so I guess that shows me for finding other bugs. :-)
Comment #17
dawehnerI like us being able to finally do that! Well, technically we are able already for phpunit based tests, so this just syncs the capability.
🤔 I'm a bit confused as I don't see an actual annotation test class with multiple
@groupor a@groupsstatement. Maybe its enough to write an example in a change record?Note: I'm using emoji based code review, see https://gist.github.com/pfleidi/4422a5cac5b04550f714f1f886d2feea
Comment #18
mile23The emoji just shows up as a little square to me.
There's no such annotation as
@groups. We use multiple@groupannotations.I'm adding a 'groups' array key to the test info so that we can keep BC with 'group' for Simpletest UI.
OK, so I added some test cases to TestDiscoveryTest: One unit test of getTestInfo() with more @groups than anyone will probably ever use, and some for getTestClasses() that prove that we're adding more groups during a file system scan.
Comment #19
mile23Needed a re-roll.
This is still a bug, since it allows for false passes when you use run-tests.sh and specify a group. So it's still targeted to 8.4.x, but I'd understand if others don't see it that way. Also it's not an API change.
Comment #20
dawehnerFor me at least arguing for the current minor always adds effort, from individual contributors, subsystem maintainers and finally from core committers. I think from my point of view this absolutely nice developer experience improvement.
Comment #21
mile23Well, it's a bug and it might be causing false positives on test runs, which is why I aimed it at 8.4.x at the time.
Rerunning the test from #19.
Comment #22
dawehner+1 Nice catch that this is totally unused.
Should we use a "===" here / in_array(, , TRUE)
Comment #23
jibranAddressed #22.
Comment #24
mile23+1. :-)
Comment #25
dawehnerThank you @jibran!
Comment #26
mile23Comment #28
mile23Unrelated fail, setting back to RTBC.
Comment #29
larowlannit: missing a space here, fails phpcs
Comment #31
chr.fritschRerolled the test and fixed the #29
Comment #33
chr.fritschTestbot hickup
Comment #34
mile23I'd RTBC but I wrote the original patch.
Comment #35
tstoecklerSince this was already RTBC before and #31 fixes the only minor complaint raised I think this can be RTBC again. Also read through the patch and couldn't find anything to complain about, but this is not really my area of expertise.
Comment #36
alexpottThis can be one loop and not two. Ie:
Comment #37
alexpottAlso this isn't quite what is happening here. If a class has the annotation:
and another class has
they will both be in the config group because the config group is printed first. It's not it's first group.
Comment #38
borisson_Fixes #36 & #37.
Comment #39
mile23After this issue is fixed, the only (core) reason we need to present that historical list is so that the testbot can have a list of test classes to use for converting {simpletest} entries into JUnit. It discards the group info.
Eventually it won't be doing this for PHPUnit: #2943340: Process PHPUnit junit reports separately
Anyway: Better code, yay! More +1 from me, except I can't RTBC.
Comment #40
dawehnerI have one small question: When you do something like:
run-tests.sh node entity, potentially the same test might be executed multiple times, wouldn't it?Maybe we need the same logic in the execution as we need when we list the available tests.
Comment #41
mile23That is a bit of an oversight, isn't it?
Note that we have to write code like this:
...because TestDiscovery is discovering tests *for the Simpletest UI.* #2945465: Make TestDiscovery find info we need, not info we don't need
Comment #42
dawehnerThank you for fixing that @Mile23!
Nice find!
Comment #43
mile23We don't really need this here, do we? Nope!
Comment #46
andypostThis is really confusing, you can always get first element of array so "for historical reasons" could be replaced with proper implementation - "provider" as all discovery stuff set and groups!
Comment #47
mile23Re: #46: That's true. But we can't deprecate an array key, we have to keep 'group.' And we can't change the expectation for 'group' to be an array instead a string. It'd be an API break. So we're better off providing both and documenting why.
If we're getting rid of the UI form, we can get rid of most of this code anyway: #2945465: Make TestDiscovery find info we need, not info we don't need
Here's a re-roll. Also, I encountered #3034015: Class to test deprecation error for deprecated trait triggers deprecation error itself along the way.
Dialing this in to 8.7.x because it's a test improvement.
Comment #48
mile23This should only really be added back for issues like #2847678: Deprecate WebTestBase and its required classes in favour of BrowserTestBase when/if we end up calling
@trigger_error()in those classes.Comment #49
lendudeWhile I agree that could be removed for now, it feels a little out of scope here? But other then that, I see no problems here anymore, all feedback has been addressed.
Comment #50
alexpottCrediting dawehner, andypost and myself for code review.
Comment #51
alexpottCommitted and pushed 2af907ca36 to 8.8.x and 9e8d9b73dd to 8.7.x. Thanks!
I tested this locally and seen that run-tests.sh can discover tests in multiple groups and picks then when limited to any group the test is in.
Comment #54
mile23Cool, thanks. Now we've unblocked #2858652: Support multiple @group test annotations in Simpletest UI and #2021077: make search also match the test groups on the test overview page
Comment #55
lendudeCrap, this is causing all tests with multiple groups to be run multiple times :(
Search for Drupal\Tests\user\Kernel\UserServiceProviderTest in the test log
Comment #56
lendudethis might fix it....
Comment #57
alexpott@Lendude +1 to going forward - let's open a followup and go forwards if that works.
Comment #58
alexpottI can confirm that #56 fixes the problem.
Comment #59
lendudeHere is the follow up #3039572: Prevent tests with multiple groups running multiple times