How do I programmatically render a view with contextual filters? How do I programmatically render a view with contextual filters in Drupal 8?

In Drupal 7, I generally use the following code.

$view = views_get_view('test_view'); //test_view is the view machine name
$view-&gt;set_display("block"); //block is the view display name
$view-&gt;set_arguments($tid); //$tid is the argument to pass
$view-&gt;pre_execute();
$view-&gt;execute();
$content = $view-&gt;render();


Is there any alternative way to achieve this in Drupal 8?
Basing on the code used by views_get_view_result(), I would use the following code, as code equivalent to the one you show in the question.

  $args = [$tid];
  $view = Views::getView('test_view');
  if (is_object($view)) {
    $view-&gt;setArguments($args);
    $view-&gt;setDisplay('block');
    $view-&gt;preExecute();
    $view-&gt;execute();
    $content = $view-&gt;buildRenderable('block', $args);
  }