Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291521

Convert all Simpletest web tests to BrowserTestBase (or UnitTestBase/KernelTestBase)

$
0
0

Problem/Motivation

We want to get rid of simpletest.module in Drupal 9. We want to prepare the latest Drupal 8 development branch as much as possible before opening the Drupal 9 development branch (see #2608062: [META] Requirements for opening the Drupal 9 branch). Therefore we need to convert all web tests to BrowserTestBase or UnitTestBase or KernelTestBase and deprecate WebTestBase.

Proposed resolution

1) Convert a small part of Drupal core web tests to Browser tests to get them battle tested. See all the conversion child issues that have been opened here before 2016-Sept-01.
2) Implement a backward compatibility layer as AssertLegacyTrait used by BrowserTestBase. Ideally a test conversion should only be the change of the namespace and used base class. Everything else should be covered by backwards compatible methods as far as possible/reasonable.
3) Prepare one big bang patch of test conversions in #2770921: Feb 21st: Convert chunk of WTB to BTB by just moving classes, changing use statements adding traits. Commit it during code freeze of the next Drupal minor release (likely March 2017 for 8.3).
4) In the meantime open child issues to convert web tests for each core module. While doing so we should also check if the test cases actually require a browser or can be converted to unit/kernel tests. They will be postponed until #2770921: Feb 21st: Convert chunk of WTB to BTB by just moving classes, changing use statements adding traits is committed.

Instructions for converting a Simpletest web test

  1. Read https://www.drupal.org/phpunit and all subpages, especially https://www.drupal.org/node/2783189 .
  2. Do not bulk move all the test files but move and work on one test at a time.
  3. Move the test file to a tests/src/Functional folder in the module.
  4. Rename the namespace, make the class extend BrowserTestBase and fix the use statement.
  5. If there is a test method which does not perform any web request (for example no ->drupalGet() or ->drupalPostForm() calls) then that method should be extracted to a unit test or kernel test. $this->setRawContent() generally means the test should be converted to a Kernel test
  6. $this->drupalPostAjaxForm(); means the test should be converted to a Javascript test. There most likely already is an issue for it, see #2809161: Convert Javascript/AJAX testing to use JavascriptTestBase
  7. Otherwise try to change as little as possible in the converted web test. Do not get tempted to "improve" or "tidy up" the tests - the conversion should be easy to review with only the minimum necessary changes. Further cleanup can be done in a follow-up issue.
  8. Run the single test file with phpunit (replace the path with the file you converted):
    cd core
    ../vendor/bin/phpunit   modules/help/tests/src/Functional/HelpTest.php --stop-on-failure
    
  9. Regularly upload a patch to see if the tests pass on the testbot as well.
  10. If the conversion starts to involve complex changes, please reach out to people or search the other conversion issues. Occasionally it can be helpful to skip tricky tests, in which case update the issue summry stating which tests are not converted yet.
  11. Create follow-up issues to deal with blockers so that progress can continue with converting the majority of tests in a module. Update the "Conversions blocked by another" section on this page.
  12. Any TestBase or Trait which is in the old /src/Tests/ location should remain there and be deprecated. Copy the TestBase or Trait file into the new location and alter the tests to use the new version. The deprecated class must not "use" the newly-moved class, but remain exactly as it is. Create a change record for the deprecation notice - one CR can cover all deprecations within a module.

Hints and Tips

  • Simpletest allowed typecasting of elements. BrowserTestBase does not. Instead of (string) $element use $element->getText() or $element->getHtml();
  • Views tests need the new constructor format with $import_test_views = TRUE as the first parameter in the setUp() method.
  • Attributes are fetched with $item->getAttribute('value'); now, previously it was $item->value or $item->attributes()->value.
  • Not all legacy assertion methods are implemented yet, for example you may get Fatal error: undefined function assertNoLink(). Check #2750941: Additional BC assertions from WebTestBase to BrowserTestBase to borrow from there.

Remaining tasks

Resolve all the child issues. Convert web tests in child issues per module/component in Drupal core.

Issue creation

Please add the tag 'phpunit initiative' to every issue and add the issue to the correct Component (if it's a test for the comment module, add it to comment.module).

Remaining simpletests

Check http://simpletest-countdown.org/simpletestcount/simpletests

Progress report

Want to know how we are doing? Check: http://simpletest-countdown.org

API changes

Simpletest and WebTestBase will be deprecated.


Viewing all articles
Browse latest Browse all 291521

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>