Adding more variables to menu for use in menu.html.twig
Here is an example from a real project I had done:
mytheme.theme:
/**
 * Implements hook_theme_registry_alter().
 * @param $theme_registry
 */
function mytheme_theme_registry_alter(&amp;$theme_registry) {
  $theme_registry['menu']['variables']['top_parent'] = [];
}

/**
 * Implements hook_preprocess_block__menu_block().
 * @param $variables
 */
function mytheme_preprocess_block__menu_block(&amp;$variables) {
  // set the top parent on the left nav
  if ($variables['elements']['#id'] == 'left_navigation' &amp;&amp; !empty($variables['elements']['content']['#items'])) {
    // code removed

    $variables['content']['#top_parent'] = [
      'title' =&gt; $menu_content-&gt;getTitle(),
      'url' =&gt; $menu_content-&gt;getUrlObject(),
      'is_current' =&gt; ($current_path == $item_path)
    ];
  }

  // code removed
  }
}

In Twig:
  {% if menu_level == 0 %}
    &lt;li class=&quot;left-nav__item active-trail is-active {% if top_parent.is_current %}is-current{% endif %}&quot;&gt;
      {{ link(top_parent.title, top_parent.url) }}
    &lt;/li&gt;
  {% endif %}

You are likely missing the part where you add test_var key to the content array:
$variables['content']['#test_var'] = &quot;whatever&quot;;
With exception to flagging is-current, it looks like you're trying to do the same thing I did. You should strive to use the link function in Twig instead of a hard coded anchor unless there is no way around it.