1

Fifteen years writing Drupal code and yet I have never written unit tests. I have recently posted a couple core patches which require tests to be written for them - so good time to learn how to write PHPUnit tests.

I have a test environmnet set up and am able to successfully run core unit tests. I need to extend these tests which I can see is not very difficult; but I need to run against the "test db". I can see core Views test modules like views_test_config and views_test_data which have everything I need - but I cannot enable them (manually so I can verify what my test content is).

Is there a way to get a copy of the D9 default test database that is used for running core (kernel) tests against? Or, alternatively, some way to enable these modules?

2 Answers 2

1

I'm not sure if I understand your question correctly, but there is no "test db" as such other than what your test creates. The core test system installs a minimal Drupal site from scratch (the database URL for this can be set in the phpunit.xml file, a default template of which is in core/phpunit.xml.dist). This is independent of any existing sites, uses the "simpletest" installation profile and is created from scratch every time the test runs.

Your test's ::setUp() method then creates things like test users, content etc in this site.

If you extend the KernelTestBase or the BrowserTestBase class, you will see there is a class property named $requiredModules. If you set this to an array of module names, they will automatically be enabled as part of the setup process.

2
  • Yes, thank you, but i know all this. I know if i add the views test modules to my #requireModules i can use this test data and config (which is what i need) in my tests. But, I want to "look" at that data with the existing test views to see what is there - so that I can write (and debug) my tests accordingly. But, I need a way to manually install those modules to see what it builds out for test data/config. Does this help?
    – liquidcms
    Oct 23, 2021 at 21:03
  • 1
    So yes, i suspected no core test db (although would be helpful), so perhaps worded my question wrong? What i really need is a way to enable the core test modules like views_test_data and views_test_config. Why i am not able to manually install these?
    – liquidcms
    Oct 23, 2021 at 21:05
0

To allow installing test modules you need to set this in your $settings.php:

$settings['extension_discovery_scan_tests'] = TRUE;

[EDIT] - this does allow seeing all the test modules and i can now enabled them - but the test data and view is still not run.. ughh!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.