Simpletest is a legacy testing framework which comes out of the Drupal 6 days, was in core in Drupal 7, and is supported in Drupal 8 alongside PHPUnit-based frameworks.

Defining Some Terms

When we refer to 'simplest', we could be referring to a few distinct-but-overlapping things:

  1. The simpletest module, AKA 'Testing'. This module is in core, and is a hard dependency of all tests, PHPUnit or otherwise. It also provides a way to run tests in the user interface, through a form. We call this feature the 'simpletest UI.'
  2. The simpletest framework, AKA TestBase and WebTestBase (aka WTB). This framework lives in the simpletest module. Most WTB tests have been converted to their PHPUnit equivalents. The remaining core tests which use this framework are tests of the framework itself, marked with @group WebTestBase.
  3. The test runner, AKA run-tests.sh. This is a script which can run PHPUnit-based tests as well as WTB ones.

Moving forward to Drupal 9, the simpletest framework and the simpletest UI should be phased out in a reasonable way.

We currently have an initiative to convert core's tests to use PHPUnit-based frameworks, and not use Simpletest-based ones. This initiative has completed. #2807237: PHPUnit initiative

This still leaves us with many legacy tests in contrib for Drupal 8, which we must still support, but which we'd rather not maintain.

The Testbot

DrupalCI testbot currently runs all the tests by invoking the run-tests.sh script.

The obvious reason for this is that there should be as few points of contact as possible between the test runner and the system under test. But there are other reasons as well:

  • PHPUnit has an undefined behavior if the test process has a fatal error. That is, if a test crashes, the phpunit tool does not continue running other tests, and in fact does not generate a report of the tests that did run.
  • PHPUnit does not support concurrent test runs. This means that all tests must be run sequentially, leading to long CI times.

These factors mean that we should keep the behavior of run-tests.sh. It provides us with features we can't easily get from other libraries, and will be consistent for backwards-compatibility.

The Users

Some users want to keep the simpletest UI. Others want to remove it, including a general consensus from maintainers. The current issue for this is #3028663: Split up simpletest into simpletest and testing_ui to enable easier decisions for Drupal 9 where we are teasing the UI portions out of the simpletest module into a testing_ui module, so that we can decide later.

The Maintainers

Core maintainers and others who wish to work on the testing subsystem are frequently frustrated with the fragile nature of the simpletest testing system.

It is difficult to test the testing system without refactoring, and is difficult to refactor without testing, and the quality of the rest of the code depends on the code that is demonstrated to work. Thus it is difficult to work on the testing subsystem from both the old-crusty-code perspective, as well as the reluctance-to-change perspective.

Note that most of the simpletest module is not marked as deprecated. There are two categories of things which have been deprecated:

  • The simpletest framework: TestBase and its children. These are the test types we wish to quit supporting.
  • Global-level functions which have been replaced by the test_discovery service.

This means a deprecation process will be needed if any modernizing changes are to happen in simpletest, or if it is to be removed once and for all.

The Internals

run-tests.sh and the simpletest module contain many shims that convert one thing to another in order to provide output that is known to be necessary. This includes converting PHPUnit JUnit test results to the simpletest db table schema and then from that table to JUnit again, and similar operations.

The path of execution for these processes extend between global-level functions in run-tests.sh and simpletest.module. Note that neither of these files has a .php extension. That aside, this creates a dependency between the script and the module, which makes it increasingly unmaintainable.

Suffice it to say that our goal is to keep run-tests.sh for the foreseeable future, and so we should refactor towards that end.

The Plan

So those are some of the problems in this space.

The solution seems to look like the following:

Consistency in Drupal 8

For the rest of the Drupal 8 lifecycle, we should provide the same behaviors from simpletest and run-tests.sh as we have now. We should provide the normal BC layer that we'd expect from any deprecated Drupal 8 code.

Drupal 8 should still be able to run Simpletest-based tests. While there is an initiative to phase out these tests in core, we're still promising to be able to run them. We need to fulfill this promise so that the testbot can still run contrib tests.

Drupal 8 should still have the Simpletest test runner UI. This form should be present and should be useable as it is now. It might be enhanced in some ways, but this should not be our focus. Whether to keep this UI in Drupal 9 can be an open conversation.

For Drupal 8, top-level functions in simpletest.module and run-tests.sh should be deprecated. Their functionality should be moved to helper classes which can be unit-tested with relative ease.

Drupal 8's simpletest hook APIs should be deprecated. They are only currently supported for the Simpletest UI at this point, which is an inconsistency that will need to be maintained for the D8 life cycle. We can examine whether these hooks should be implemented within run-tests.sh, but since we're trying to move away from simpletest-isms, and since PHPUnit-based test listeners and alternate test suites are better available workarounds, this seems unlikely.

Radical changes to Drupal 8, with BC

In the near future, the simpletest UI form should be refactored into the testing_ui module: #3028663: Split up simpletest into simpletest and testing_ui to enable easier decisions for Drupal 9

All test-running behavior should be factored into a core namespace. This would mean taking all behaviors out of the simpletest module and placing them into the \Drupal\Tests\ namespace.

All of run-tests.sh's behavior would also be refactored into this namespace, except the script itself which would then use these classes to run the tests.

This namespace should not be autoloaded unless it's test-running time. This means the code should be refactored into the core/tests/ directory. Whatever test-running UI is available from testing_ui can autoload test-running code from this directory if it is enabled and running tests.

Once the code is moved in a consistent process into the core/tests/ directory, it could be turned into Composer-based subtree split. This would allow the testing infrastructure to be a dev dependency of core, removing it from the codebase of production sites.

This is the ideal goal for the simpletest refactor: That one could remove it from a production codebase using Composer, by issuing this command: composer install --no-dev Any point along the line between where things stand now, and this complete removal would be a step in the right direction.

Drupal 9

The Drupal 9 process would remove the deprecated top-level functions from the simpletest infrastructure itself.

The conversation over whether to keep the test runner UI would hopefully happen before the 9.0.0 release.

Since the other refactoring would have already occurred, the decision to remove the UI would be the same as deciding to remove the module from core. All other testing infrastructure provided by core would remain.

Comments

Mile23 created an issue. See original summary.

mile23’s picture

mile23’s picture

Issue summary: View changes
neclimdul’s picture

run-tests.sh calls exec() in order to run phpunit for a single test.

This has always been brain dead in my opinion and obviously a lot slower. Is it up for discussion here?

mile23’s picture

Sure, up for discussion. We should probably have a more specific meta for what-to-do-with-run-tests.sh eventually.

Reasons to exec(): Isolating a fatal (which PHPUnit doesn't do) and concurrency. If phpunit craps out on a test it won't generate a report, so we have to account for that.

tim.plunkett’s picture

#2867818: Create version of run-tests.sh tuned for running PHPUnit could be an issue for discussing that, or closed if there is already a better place.

mile23’s picture

mile23’s picture

mile23’s picture

Title: [plan] Roadmap for Simpletest? » [plan] Roadmap for Simpletest

It's been long enough that we can remove the question mark. :-)

mile23’s picture

Issue summary: View changes

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

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now 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.

mile23’s picture

wim leers’s picture

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

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now 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.

mile23’s picture

mile23’s picture

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

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now 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.

mile23’s picture

Issue tags: +Drupal 9

Adding Drupal 9 tag. If this is inappropriate please amend.

larowlan’s picture

Copying comment from #2735005: Convert all Simpletest web tests to BrowserTestBase (or UnitTestBase/KernelTestBase)

Committers discussed our priorities for D9 and it was unanimous that we don't want to support WebTestBase in D9...

so finalizing the conversion of the last tests is a priority

jibran’s picture

Title: [plan] Roadmap for Simpletest » [Plan] Roadmap for Simpletest

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

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.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

Updated IS with some new stuff and to remove some cruft.

mile23’s picture

Issue summary: View changes

Don't you hate it when you command-c instead of command-v?

mile23’s picture

In today's D9 readiness meeting, we discussed the future of the set of interdependent systems collectively known as 'simpletest'.

The agenda is here: #3063790: Drupal 9 readiness meeting / 8 July 2019, not updated with chat log at this point.

There was some discussion about comment #20 above, where @xjm expressed that perhaps the unanimity is not quite as unanimous as that comment might imply.

Core committers in that conversation were able to say that this issue is the best place to continue talking about how to slice and dice the simpletest system and what parts to deprecate for D9 and/or D10.

It would be very helpful if core committers and/or subsystem maintainers could comment on the steps outlined in the IS and whether or not they might represent a reasonable path moving forward.

Other ideas floated by core committers included turning the simpletest module back into a contrib module. If this is the case, then we'd still need to refactor out the parts that are used by run-tests.sh.

We already have an issue to separate concerns for the simpletest UI: #3028663: Split up simpletest into simpletest and testing_ui to enable easier decisions for Drupal 9

What we don't have is leadership decisions or momentum.

mile23’s picture

There seems to be some forward motion on this issue with narrower scope: #3057420: [meta] How to deprecate Simpletest with minimal disruption

mile23’s picture

xjm’s picture

Priority: Normal » Major

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.

catch’s picture

Status: Active » Closed (duplicate)

SimpleTest has just been moved to contrib, so marking this a duplicate of #3057420: [meta] How to deprecate Simpletest with minimal disruption.