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.....
Comments
Comment #2
MixologicJust 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
Comment #3
Mile23I'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.
Comment #4
Mile23Comment #5
larowlanWould 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).
Comment #6
Mile23@larowlan: Great. So it's something you have to work around. Let's fix it.
#2427191: Test-runner ignores @group annotations for PHPUnit-based tests in modules.
#2499239: Use test suite classes to discover different test types under phpunit, allow contrib harmony with run-tests
#2608532: Simpletest UI munges PHPUnit-based test output
#2641632: Refactor simpletest's *_phpunit_*() (and junit) functions etc. to a class, deprecate
Comment #10
Mile23Most of the complaints here are fixed in #2499239: Use test suite classes to discover different test types under phpunit, allow contrib harmony with run-tests (Change record: https://www.drupal.org/node/2799437 ) and #2809117: Integrate PHPUnit verbose output in Simpletest UI
We still have some outliers: #2296615: Accurately support multiple @groups per test class
Also, we'll end up fixing some of this during the Simpletest deprecation: #2866082: [Plan] Roadmap for Simpletest
Comment #11
Mile23This one too: #2878269: Modify TestDiscovery so the testbot runs all the tests
Comment #12
Mile23Comment #16
andypostBtw why not replace run-tests.sh with composer command, then it will be able to detect php version and require-dev state?
Comment #19
mondrakeComment #21
quietone CreditAttribution: quietone at PreviousNext commented