Problem/Motivation

All PHPUnit tests are now grouped together in the group "PHPUnit". If I make a change to the block module and I want to check to see if all the tests for the group "block" still pass, the PHPUnit tests that tests block functionality are not run.

This bug occurs fundamentally in TestDiscovery::getTestInfo(), which obliterates the @group annotation and substitutes 'PHPUnit.' This behavior is undocumented and is a side-effect of parsing the test class' docblock.

getTestInfo() is used by a number of different test runner systems to determine whether a test should be run by native simpletest means or by executing phpunit. Restated: The undocumented side-effect of getTestInfo() is the basis for determining which testing system should be used to run the test (in some test runs, but not all).

Proposed resolution

  • Remove the side-effect behavior of TestDiscovery::getTestInfo().

Remaining tasks

#2608532: Simpletest UI munges PHPUnit-based test output
#2605664: [Needs change record updates] Align TestDiscovery and bootstrap.php's non-permissive loading of PSR-4 namespaces for traits
#2296615: Accurately support multiple @groups per test class

User interface changes

PHPUnit group in the Simpletest UI now reflects only tests belonging to that group, rather than ALL PHPUnit-based tests.

API changes

Data model changes

CommentFileSizeAuthor
#8 2427191_8.patch1.75 KBMile23
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alexpott’s picture

Status: Active » Closed (duplicate)
Berdir’s picture

I guess you meant #2301481: Mark test groups as belonging to modules in UI, but I'm not so sure, depends on what we end up doing? This is about having a huge PHPUnit test group, instead of splitting this up. The other one is about action vs. Action test groups and how they are sorted...

xjm’s picture

Status: Closed (duplicate) » Active

Reopening per #2.

Just a note on the beta eval -- there is some disruption, because it would require changes in many patches and subsystems for core to be consistent. (See https://www.drupal.org/core/beta-changes#disruption). Probably not a big deal, but we should be explicit. :)

Thanks for giving it some thought already though!

xjm’s picture

Category: Bug report » Task

Also not really sure it's a bug actually. It's a design behavior. Whether it's a good one is another question. ;) But also improvements to testing are less frozen than other things so worth exploring.

xjm’s picture

kevinquillen’s picture

Ah... I must have spent 2 hours trying to determine why my unit tests were not grouping under my module name instead of get dumped under PHPUnit. Right now it is not clear at all why that is, when all other tests look nicely grouped.

Would it be unreasonable to have an integration test list and a unit test list? I can foresee that PHPUnit group being enormous when you start adding in contrib.

alexpott’s picture

Ideally we'd solve #2297541: [policy, no patch] Secondary/additional test @group names

@kevinquillen tbh PHPUnit tests are best run using the PHPUnit runner rather than simpletest.

Mile23’s picture

Title: Group PHPUnit tests by what they test, not group them for how they test. » Test-runner ignores @group annotations for PHPUnit-based tests in modules.
Category: Task » Bug report
Issue summary: View changes
Status: Active » Needs review
Issue tags: -Needs issue summary update +Testing system
Related issues: +#2296615: Accurately support multiple @groups per test class, +#2608532: Simpletest UI munges PHPUnit-based test output
FileSize
1.75 KB

Also not really sure it's a bug actually.

Bug.

Definitely bug.

Try this: Find a module with PHPUnit tests in it.

Run run-tests.sh with that module name as the group.

Note that the unit tests were not run even if they were annotated as @group modulename.

Then use the --module option with the module name.

Note that the unit tests *are* run.

For instance:

$ php ./core/scripts/run-tests.sh action

Drupal test run
---------------

Tests to be run:
  - Drupal\action\Tests\ActionUninstallTest
  - Drupal\action\Tests\BulkFormTest
  - Drupal\action\Tests\ConfigurationTest
  - Drupal\action\Tests\Migrate\d7\MigrateActionsTest

Test run started:
  Monday, February 1, 2016 - 06:13

Test summary
------------

Note that it misses Drupal\Tests\action\Unit\Menu\ActionLocalTasksTest and Drupal\Tests\action\Unit\Plugin\migrate\source\ActionTest, both of which are annotated with @group action.

You can run either of those tests individually using --class, and you can also run all the tests including those ones with --module action:

$ php ./core/scripts/run-tests.sh --module action

Drupal test run
---------------

Tests to be run:
  - Drupal\action\Tests\ActionUninstallTest
  - Drupal\action\Tests\BulkFormTest
  - Drupal\action\Tests\ConfigurationTest
  - Drupal\action\Tests\Migrate\d7\MigrateActionsTest
  - Drupal\action\Tests\Migrate\d6\MigrateActionConfigsTest
  - Drupal\action\Tests\Migrate\d6\MigrateActionsTest
  - Drupal\Tests\action\Unit\Menu\ActionLocalTasksTest
  - Drupal\Tests\action\Unit\Plugin\migrate\source\ActionTest

Test run started:
  Monday, February 1, 2016 - 06:18

Test summary
------------

Note that this finds *all* tests in the module, regardless of annotation, which is reasonable. However, this also proves that the unit tests are discovered but filtered out despite their group annotation in the previous example.

This is inconsistent behavior. Bug.

The problem is that TestDiscovery OBLITERATES the group annotation while building the list and arbitrarily assigns it to @group PHPUnit so that it looks pretty in the SimpleTest UI. run-tests.sh uses this same discovery path for groups (but obviously not for modules). Which is inconsistent and thus buggy.

The way to solve this is to fix the bug that lives right here: http://cgit.drupalcode.org/drupal/tree/core/modules/simpletest/src/TestD...

The reason that bug is there is so that you can group PHPUnit-based tests in one place in the SimpleTest UI and exclude them from running in SimpleTest. That was to avoid early problems running PHPUnit-based tests alongside SimpleTest ones.

Fixing this bug, combined with #2608532: Simpletest UI munges PHPUnit-based test output would mean everyone could run phpunit based tests happily and usefully from run-tests.sh and also from the SimpleTest UI.

Updating issue summary and title to reflect the actual problem. Step-by-step instructions to solve this problem are included. And what the heck, here's a patch.

You'll see that the patch isn't very big at all, is it?

It still flakes out in the SimpleTest UI for running the action group. It only runs the 4 SimpleTest-based tests, and misses the 2 phpunit tests despite their being checked to run in the form. This is a consequence of an error in how the UI runs unit tests. But that's outside the scope of this issue and inside the scope of: #2608532: Simpletest UI munges PHPUnit-based test output

It does fix the issue with run-tests.sh noted above.

Mile23’s picture

Branch and patch both ran 14,475 tests, so we're not dropping or adding any.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Mile23’s picture

Status: Needs review » Closed (won't fix)