How to force cron to use config saved during a SimpleTest? I write a test using Drupal\simpletest\WebTestBase for a custom module, which implements hook_cron(). The test saves a configuration object, which should be used by the cron, and then runs the cron:

function testCron()
{
    $config = \Drupal::service('config.factory')-&gt;getEditable('mymodule.settings');
    $config
      -&gt;set('some_setting', 'some value')
      -&gt;set('another_setting', 'another value');
    \Drupal::service('cron')-&gt;run();
}


The settings are saved and can be used during the test. But when I want to use them in the cron (in mymodule.module):

/**
 * Implements hook_cron().
 */
function mymodule_cron()
{
    $config = \Drupal::config('mymodule.settings');
    ...
}


then instead of the saved values, the default settings from config/import/mymodule.settings.yml are used.

How can I force the cron to use the settings saved in the test?
As commented, you were missing the save call in the test.

That means that the change is only in the runtime object returned by getEditable() and since get() and getEditable() do not share the static cache, you didn't see the change.