Problem/Motivation

This issue summary is based on a comment from here: https://www.drupal.org/node/2499239#comment-10520662 #2499239: Use test suite classes to discover different test types under phpunit, allow contrib harmony with run-tests where it seems that I alone am the only person who cares about being able to run unit tests from the command line for contrib with submodules.

Here's an issue that added a --directory option to the D8 run-tests.sh script: #2551981: Add --directory option to run-tests.sh test discovery

This means that when it comes time to discover tests, run-tests.sh and phpunit have different behaviors, because run-tests.sh ignores phpunit.xml.dist.

Similarly, SimpletTest in the UI finds some tests that phpunit doesn't, and phpunit finds some tests that SimpleTest in the UI doesn't.

I would wager that there is a discrepancy between the tests run by run-tests.sh and SimpleTest UI as well, but I don't have that information.

So that leaves us with the testbot finding files that I can't run locally, leading to a false positive locally.

From the issue for the patch above (#2551981: Add --directory option to run-tests.sh test discovery) @jthorson says:

However, instead of building this scanning capability into the new test runner, the maintainers assert that test discovery should be the responsibility of the test framework itself, not the individual runner ... i.e. the scanning for files should be the responsibility of run-tests.sh, not PIFR or DrupalCI.

Absolutely it should be the responsibility of the test framework, not the runner. But it shouldn't be up to run-tests.sh to ignore PHPUnit configuration.

So, just to tally, we have:

1) SimpleTest in the UI which *does* discover and run the submodule PHPUnit tests, according to.... policy?

2) run-tests.sh which uses phpunit.xml.dist for test configuration such as strict rules (I think) but which scans for tests everywhere, depending on calling mode.

Which leaves us with:

3) PHPUnit at the command line, which honors whitelist/blacklist from phpunit.xml.dist, meaning it *can't* run tests that the others *can*, for... reasons?

Sadly, the only useful information you'll get about PHPUnit tests comes from running phpunit at the console, which means you're SOL if you want to find out why a test failed. Here's what run-tests.sh tells you when you pass --verbose:

Detailed test results
---------------------


---- Drupal\Tests\phpunit_example\Unit\AddClassTest ----


Status    Group      Filename          Line Function                            
--------------------------------------------------------------------------------
Fail      Other      AddClassTest.php    55 Drupal\Tests\phpunit_example\Unit\A
    
Pass      Other      AddClassTest.php     0 Drupal\Tests\phpunit_example\Unit\A
    
Pass      Other      AddClassTest.php     0 Drupal\Tests\phpunit_example\Unit\A
    
Pass      Other      AddClassTest.php     0 Drupal\Tests\phpunit_example\Unit\A
    
Pass      Other      AddClassTest.php     0 Drupal\Tests\phpunit_example\Unit\A
    
Pass      Other      AddClassTest.php     0 Drupal\Tests\phpunit_example\Unit\A
    
Pass      Other      AddClassTest.php     0 Drupal\Tests\phpunit_example\Unit\A
    
Pass      Other      AddClassTest.php     0 Drupal\Tests\phpunit_example\Unit\A
    
Pass      Other      AddClassTest.php     0 Drupal\Tests\phpunit_example\Unit\A
    
Pass      Other      AddClassTest.php     0 Drupal\Tests\phpunit_example\Unit\A
    
Pass      Other      AddClassTest.php     0 Drupal\Tests\phpunit_example\Unit\A
    
Pass      Other      AddClassTest.php     0 Drupal\Tests\phpunit_example\Unit\A
    
Pass      Other      AddClassTest.php     0 Drupal\Tests\phpunit_example\Unit\A
    
Pass      Other      AddClassTest.php     0 Drupal\Tests\phpunit_example\Unit\A
    
Pass      Other      AddClassTest.php     0 Drupal\Tests\phpunit_example\Unit\A
    
Pass      Other      AddClassTest.php     0 Drupal\Tests\phpunit_example\Unit\A
    
Pass      Other      AddClassTest.php     0 Drupal\Tests\phpunit_example\Unit\A
    
Pass      Other      AddClassTest.php     0 Drupal\Tests\phpunit_example\Unit\A
    
Pass      Other      AddClassTest.php     0 Drupal\Tests\phpunit_example\Unit\A
    
Pass      Other      AddClassTest.php     0 Drupal\Tests\phpunit_example\Unit\A
    
Pass      Other      AddClassTest.php     0 Drupal\Tests\phpunit_example\Unit\A
    
Pass      Other      AddClassTest.php     0 Drupal\Tests\phpunit_example\Unit\A
    
Pass      Other      AddClassTest.php     0 Drupal\Tests\phpunit_example\Unit\A
    
Pass      Other      AddClassTest.php     0 Drupal\Tests\phpunit_example\Unit\A
    
Pass      Other      AddClassTest.php     0 Drupal\Tests\phpunit_example\Unit\A
    
Pass      Other      AddClassTest.php     0 Drupal\Tests\phpunit_example\Unit\A
    
Pass      Other      AddClassTest.php     0 Drupal\Tests\phpunit_example\Unit\A

$

Proposed resolution

Desired behavior:

$ ./vendor/bin/phpunit -c core --group my_contrib_submodule

Since @jthorson is right, and it should be up to D8 to determine what tests to run, we should design that.

We should have a way to determine what tests to run, both for core and contrib.

We might have a phpunit.xml.core and a phpunit.xml.contrib if needed.

Add your idea here.....

Remaining tasks

User interface changes

API changes

Data model changes

Comments

Mile23 created an issue. See original summary.

Mixologic’s picture

Just to throw something out there ./vendor/bin/phpunit is currently inferior to run-tests.sh, which is why the 'drupal way' is to use run-tests.sh.

The main problem is that phpunit does not currently offer any sort of graceful failures for when you are running a test and it segfaults or hits a parse/syntax error in a test. It just stops and moves on. Thats fine when 'running from the command line', however the requirements for running a test on the command line are very different from the requirements of a CI infrastructure. The CI infra has to know every test that is being attempted, and what the results of those tests are. It's perfectly fine for a dev to see, interactively, that a test is segfaulting when running locally and be able to respond. But when the testrunner is unattended in a CI workflow, it is not fine to not have any sort of signaling or return value that indicates something is borked. So we need some way for phpunit to report failure in those instances and not just crash.

The only way that we'll be able to get to a place where running phpunit from the command in is a *supported* thing, and not just a thing we wish we could do, is to fix phpunit upstream so that segfaults provide some sort of response when running in process isolation mode.

http://stackoverflow.com/questions/3841190/phpunit-fatal-error-handling

Mile23’s picture

I'm not complaining that phpunit is more desirable than run-tests.sh for the tesbot.

I'm saying that they both should run the same tests, which they currently don't.

This issue is a planning issue to discover what has to happen to move forward, so that I can use my phpunit locally and testbot can use run-tests.sh, and we get the same results.

This matters more for contrib than for core.

Mile23’s picture

Component: other » simpletest.module
Issue tags: +Testing system, +PHPUnit
larowlan’s picture

Would be nice, at the moment I'm using my own phpunit.xml.dist in my contrib projects to get around this - with my own code coverage filters (because the core ones are too slow).

Mile23’s picture

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.

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

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

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

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.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

Title: [meta] Drupal CI and Testing Config Is Messed Up » [meta] DrupalCI/run-tests.sh/phpunit not in harmony
Related issues: +#2878269: Modify TestDiscovery so the testbot runs all the tests
Mile23’s picture

Title: [meta] DrupalCI/run-tests.sh/phpunit not in harmony » [meta] DrupalCI/SimpletestUI/run-tests.sh/phpunit not in harmony

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

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

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

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

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

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

andypost’s picture

Btw why not replace run-tests.sh with composer command, then it will be able to detect php version and require-dev state?

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

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

mondrake’s picture

Component: simpletest.module » phpunit

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.