How do I change the current language in a Kernel test? I'm writing a test for something that returns a Url from an entity. This should be language-aware, so the test needs to change the current language.
I started off writing a Kernel test for this, because they're faster, but I can't figure out how to make the test code change the current language:
  public static $modules = [
    'system',
    'user',
    'language',
    'content_translation',
    [SNIP]
  ];

  protected function setUp() {
    parent::setUp();

    $this-&gt;installConfig(['language']);
    $this-&gt;installEntitySchema('configurable_language');


    $this-&gt;languages['de'] = ConfigurableLanguage::createFromLangcode('de');
    $this-&gt;languages['de']-&gt;save();

    $config = $this-&gt;config('language.negotiation');
    $config-&gt;set('url.prefixes', [
      'en' =&gt; 'en',
      'de' =&gt; 'de',
    ])-&gt;save();

    \Drupal::service('kernel')-&gt;rebuildContainer();
    \Drupal::service('router.builder')-&gt;rebuild();
    $this-&gt;languageManager = $this-&gt;container-&gt;get('language_manager');
    $this-&gt;languageManager-&gt;reset();

    [SNIP]
  }

  public function testCurrentLanguageChange() {
    // Change the site's current language.
    dump(\Drupal::languageManager()-&gt;getCurrentLanguage());

    \Drupal::service('language.default')-&gt;set($this-&gt;languages['de']);

    dump(\Drupal::languageManager()-&gt;getCurrentLanguage());
  }

}

In the test code above, both dump() calls output the 'English' language object.
Looks like I needed to call:
    \Drupal::languageManager()-&gt;reset();


No, wait, that doesn't seem to be the whole story.... ARGH.
EDIT:
For the entity to be treated as translatable and so return the right URL, I also needed to set the bundle as translatable:
    $this-&gt;entityTypeManager-&gt;getStorage('language_content_settings')-&gt;create([
      'target_entity_type_id' =&gt; 'node',
      'target_bundle' =&gt; 'page',
    ])-&gt;save();
    $this-&gt;container-&gt;get('content_translation.manager')-&gt;setEnabled('node', 'page', TRUE);