How can I get module configuration for testing I write tests for a form in a custom module using Drupal\simpletest\WebTestBase. I want to test, if the module settings are displayed in the configuration form. But the problem is, that I can not get the saved settings:

$config = $this-&gt;config('mymodule.settings');
debug($config-&gt;get(), 'Configuration object'); // Returns an empty array


I have found, that the same problem is e.g. in the demo module described in an article  on Sitepoint, see: https://github.com/upchuk/d8-demo-modules/blob/master/demo/src/Tests/DemoTest.php#L59


  E.g. $config->get('demo.email_address') returns always ''.


The tests seem to work well, but when I add debug($config->get()), then I also receive an empty array. It means, that all the test cases use empty variables and return false positive results.

I have also tried:

debug(\Drupal::config('mymodule.settings')-&gt;get()); // Empty array
debug(\Drupal::configFactory()-&gt;getEditable('mymodule.settings')-&gt;get()); // Empty array
debug(\Drupal::config('system.site')-&gt;get()); // Correct array with site settings




The module and the form are working correctly and all the settings are stored in the database.
The tests do not care about the settings, which are saved in the database. They work with settings in config/import/mymodule.settings.yml

The file can look like this:

var1: 'Some text'
var2: 1
var3: http://example.org


More info: https://www.drupal.org/docs/8/creating-custom-modules/include-default-configuration-in-your-drupal-8-module