The scripts/run-tests.sh script has matured a lot during D8, and become the preferred way to run tests (docs). It's main advantage is that there can be no leakage between the parent Drupal site and child Drupal site (because there is no child site when --sqlite is used). This vastly simplifies debugging test failures, and vastly simplifies the test runner itself. However, many folks still appreciate having a UI for choosing tests to run.

This issue proposes to change what happens when the simpletest form is submitted. Instead of actually running the tests, we print out a bash command which calls run-tests.sh with the parameters for chosen by the user in the GUI. More importantly, we can finally rip out all of the code in Drupal which deals with isolation/leakage. We are one step closer to using phpunit as our test runner.

Comments

dawehner’s picture

I really like the idea! Do you think it would make sense to also show the phpunit test command in case you run one of those?

alexpott’s picture

@dawehner yes if only phpunit tests are selected.

tim.plunkett’s picture

Version: 8.x-dev » 8.0.x-dev
chx’s picture

what i think of this is irrelevant but most definitely get YesCT and webchick approval before doing this.

tim.plunkett’s picture

StatusFileSize
new52.74 KB
new78.2 KB

Until I can reliably see the HTML output of pages via the command line, I don't think this will work.

For example, here's what I got via the CLI:

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

Tests to be run:
  - Drupal\link\Tests\LinkFieldUITest

Test run started:
  Saturday, August 2, 2014 - 10:25

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

Drupal\link\Tests\LinkFieldUITest                             17 passes   4 fails   1 exceptions             

Test run duration: 19 sec

Here's what I got from qa.drupal.org:

And here's what I got from the simpletest UI results:

Guess which one of these helped me find the bug fastest?

dawehner’s picture

@tim.plunkett
Doesn't --verbose gives you the link when things failed? If not we should certainly add it independent from this issue.

tim.plunkett’s picture

Nope.

$ php core/scripts/run-tests.sh --verbose --url http://d8 --color --class "Drupal\link\Tests\LinkFieldUITest"

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

Tests to be run:
  - Drupal\link\Tests\LinkFieldUITest

Test run started:
  Saturday, August 2, 2014 - 12:44

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

Drupal\link\Tests\LinkFieldUITest                             17 passes   4 fails   1 exceptions   5 messages

Test run duration: 1 min 12 sec

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


---- Drupal\link\Tests\LinkFieldUITest ----


Status    Group      Filename          Line Function                            
--------------------------------------------------------------------------------
Pass      Other      LinkFieldUITest.p   27 Drupal\link\Tests\LinkFieldUITest->
    Enabled modules: node, link, field_ui
Pass      Role       LinkFieldUITest.p   29 Drupal\link\Tests\LinkFieldUITest->
    Created role ID 'i7k8zfbt' with name '?JsYFl7<'.
Pass      Role       LinkFieldUITest.p   29 Drupal\link\Tests\LinkFieldUITest->
    Created permissions: administer content types, administer node fields,
    administer node display
Pass      User login LinkFieldUITest.p   29 Drupal\link\Tests\LinkFieldUITest->
    User created with name meDFdHG6 and pass zxDkk9H8kj
Pass      Browser    LinkFieldUITest.p   30 Drupal\link\Tests\LinkFieldUITest->
    GET http://d8/user returned 200 (3.53 KB).
Pass      Browser    LinkFieldUITest.p   30 Drupal\link\Tests\LinkFieldUITest->
    Valid HTML found on "http://d8/user"
Pass      Browser    LinkFieldUITest.p   30 Drupal\link\Tests\LinkFieldUITest->
    GET http://d8/user/2 returned 200 (3.88 KB).
Pass      Browser    LinkFieldUITest.p   30 Drupal\link\Tests\LinkFieldUITest->
    Valid HTML found on "http://d8/user/2"
Pass      User login LinkFieldUITest.p   30 Drupal\link\Tests\LinkFieldUITest->
    User meDFdHG6 successfully logged in.
Pass      Other      LinkFieldUITest.p   38 Drupal\link\Tests\LinkFieldUITest->
    Created content type rujiuex7.
Pass      Browser    LinkFieldUITest.p   49 Drupal\link\Tests\LinkFieldUITest->
    GET http://d8/admin/structure/types/manage/rujiuex7/fields returned 200
    (10.31 KB).
Pass      Browser    LinkFieldUITest.p   49 Drupal\link\Tests\LinkFieldUITest->
    Valid HTML found on "http://d8/admin/structure/types/manage/rujiuex7/fields"
Exception Notice     FormSubmitter.php  160 Drupal\Core\Form\FormSubmitter->red
    Undefined offset: 0
Pass      Browser    LinkFieldUITest.p   49 Drupal\link\Tests\LinkFieldUITest->
    GET http://d8/user/2 returned 200 (5.07 KB).
Pass      Browser    LinkFieldUITest.p   49 Drupal\link\Tests\LinkFieldUITest->
    Valid HTML found on "http://d8/user/2"
Fail      Other      LinkFieldUITest.p   51 Drupal\link\Tests\LinkFieldUITest->
    Found the Save field settings button
Fail      Other      LinkFieldUITest.p   51 Drupal\link\Tests\LinkFieldUITest->
    Found the requested form fields at
Fail      Other      LinkFieldUITest.p   53 Drupal\link\Tests\LinkFieldUITest->
    Found the Save settings button
Fail      Other      LinkFieldUITest.p   53 Drupal\link\Tests\LinkFieldUITest->
    Found the requested form fields at
Pass      Browser    LinkFieldUITest.p   58 Drupal\link\Tests\LinkFieldUITest->
    GET http://d8/admin/structure/types/manage/rujiuex7/display returned 200
    (18.17 KB).
Pass      Browser    LinkFieldUITest.p   58 Drupal\link\Tests\LinkFieldUITest->
    Valid HTML found on
    "http://d8/admin/structure/types/manage/rujiuex7/display"
Pass      Other      LinkFieldUITest.p   59 Drupal\link\Tests\LinkFieldUITest->
    "Link text trimmed to 80 characters" found

alexpott’s picture

Yep we need to be able to use run-tests.sh and end up with a browser window open with the test results and the ability to see any pages visited by the simpletest browser. I think #2253999-3: Provide a way to keep test results and verbose messages as artifacts is the issue to do that. So postponing this on that issue.

sun’s picture

In general, I fully agree with the premise of this issue. Especially the parent/child site environment leakage is a fundamental problem of our current testing framework.

That said, I'd like to throw an alternative option into the discussion, which still achieves the same, but retains the UI as-is:

---
Change the (front-end) batch.js to request a custom and minimal test front-controller PHP file, which does NOT boot Drupal, executes a test, and returns test results in a response in the format expected by Batch API.

That will execute the test in a clean and cleanly isolated environment, identically to CLI, merely invoked by a different SAPI.
---

The idea was born when I worked on a cleanup of run-tests.sh some months ago, with the goal of removing all Drupal dependencies from the script. Truth is, even the run-tests.sh CLI script environment leaks, because it boots Drupal prior to executing a test. The prototype successfully worked, but wasn't complete, and it (obviously) revealed that many tests are currently "relying" on leaked environment aspects. Need to grep my sources to find that code.

Of course, the web-based front-controller script would not be run-tests.sh, because that's explicitly designed for CLI. But the task is the same: Bootstrap the most minimal environment possible to execute a test.

This most minimal environment is expressed/resembled by /core/tests/bootstrap.php already, which thus presents the benchmark: (1) ClassLoader, (2) Register namespaces, (3) Minimally required constants + PHP INI settings, (4) Done (Run test).

Existing Web UIs for PHPUnit are using the identical approach to run tests from a browser. Obviously, as a standalone application, their unique benefit is that they cannot run into the trap of unintentionally priming the environment with application-specific state/aspects, because they're not aware of your custom code in the first place.

However, it should be easily possible to mimic that behavior in a custom UI. In fact, that's relatively simple and not the challenge. The challenge is to fix our existing tests to no longer rely on the environment primed by the test runner.

If we were to pursue this approach, then the necessary roadmap would roughly be:

  1. Enhance Batch API to allow to specify a custom batch processing endpoint URI. (unless that is possible already)
  2. Fix run-tests.sh to no longer boot Drupal in any way.
  3. Fix WebTestBase to no longer assume a parent site.
  4. Fix (plenty of) tests that are unintentionally/unknowingly relying on the test runner environment currently.
  5. Based on 2), create a test front-controller script (batch endpoint) that executes one test (or ideally multiple, depending on test type).

The test front-controller script simply outputs the test results into the response. We can choose from any serialization format natively supported by PHPUnit (JSON, XML/JUnit, TAP) and re-use its code to generate test result responses for legacy Simpletest tests (until its gone).

The UI simply consumes and processes the response data, purely in the front-end. When running tests through the UI, test results will not be written to any file nor stored anywhere — The test runner/dispatcher/logger is the browser (page) only.

Consequently, the test results page of the UI would be dynamically composed via JS; de facto a micro app in the front-end. Quite possibly, it would even make sense to remove Batch API altogether from the equation, in favor of asynchronous requests to execute multiple tests and/or test suites in parallel. We have plenty of JS/front-end talent that can be leveraged.

I'm fairly confident that this presents a viable alternative solution that still resolves the problems, while retaining a nice UX for newcomers/developers who are intimidated by CLI operations or those who just simply prefer to look at rich HTML output. Thoughts?

moshe weitzman’s picture

I'd be OK with this. It sounds like more work, but if someone wants to pursue it that's great. I'd love if this HTML+js test runner were developed in its own repo thats not strictly part of Drupal. Drupal would just embed it.

sun’s picture

Indeed, good point. In essence, it's a new phpunit_ui.module that strictly focuses on providing a UI for executing PHPUnit. It may happen to have a temporary BC layer for legacy Simpletest tests, but that should be an afterthought.

However, I'm not sure whether it's possible to achieve this outside of core — unless we'd independently remove the current Simpletest UI(!) upfront + adjust run-tests.sh + WebTestBase accordingly.

dawehner’s picture

We now have --browser and --verbose which gives you pretty much all you need already. The result page certainly has all the information you'll ever need.

wim leers’s picture

OMG PLEASE YES

dawehner’s picture

Status: Postponed » Active
StatusFileSize
new4.62 KB

Here is a start.

mile23’s picture

Good idea as a shortcut around the complexity of maintaining the UI testing page.

Good idea in that there are (at least) two testing systems people use regularly, and there should only be one.

Bad idea in that run-tests.sh is really cumbersome, and this issue locks us into its arguments and options, which really need some improvement.

In a better universe, we'd refactor both run-tests.sh and simpletest module to share test-running infrastructure.

mile23’s picture

Issue tags: +run-tests.sh

In the money-where-my-mouth-is department: #2624926: Refactor run-tests.sh for Console component.

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

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

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

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

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). 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.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now 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.

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

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

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

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.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.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.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.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now 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.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now 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: 10.1.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, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mile23’s picture

Project: Drupal core » SimpleTest
Version: 11.x-dev » 8.x-3.x-dev
Component: simpletest.module » Code

Moving to Simpletest contrib issue space.

mondrake’s picture

Issue tags: -run-tests.sh