How can I mock a service?
This is probably a unit test (not mentioned in the OP). If so, the intention should be to test the methods of the TempTarget class, which means, that the first thing needed would be to instantiate an instance of that class, e.g.

/**
 * Instantiates and returns a TempTarget object.
 */
protected function getTempTargetInstance()
{
  $id = $this-&gt;generateId();
  $def = $this-&gt;generateDef();
  // This is where you mock the constructor dependencies/services.
  // You probably will need to create a mock like this:
  //   $this-&gt;getMockBuilder('Drupal\Core\Entity\EntityTypeManager')
  //     -&gt;disableOriginalConstructor()
  //     -&gt;getMock();
  $this-&gt;entityTypeManager = $this-&gt;getEntityTypeManagerMock();
  $this-&gt;entityFieldManager = $this-&gt;getEntityFieldManagerMock();

  // You can now call the constructor.
  $tempTarget = new TempTarget($id, $def, $this-&gt;entityTypeManager, $this-&gt;entityFieldManager);
  return $tempTarget;
}


At this point, your object should be instantiated and you can call methods on it to assert the assumptions you want to be testing. For example:

public function testDefaultConfigurationMethod()
{
  $tempTarget = $this-&gt;getTempTargetInstance();
  $formConfiguration = $tempTarget-&gt;defaultConfiguration();
  // Test different assertions given the $formConfiguration object.  
}


However, at the time you call defaultConfiguration() you know that you need a container available that holds an entry for plugin.manager.feeds.target, so, you have to have that prepared in advance. The right place for that would be your setUp() method in your class, for example:

/**
 * {@inheritdoc}
 */
public function setUp() {
  parent::setUp();

  // Provide a mock service container, for the services our module uses.
  $container = new ContainerBuilder();
  $container-&gt;set('plugin.manager.feeds.target', $this-&gt;getFeedsTargetPluginManagerMock());
  \Drupal::setContainer($container);
  ...
  // Further setting-up of your testing class.
}


with getFeedsTargetPluginManagerMock() looking something like this:

/**
 * Creates and returns a mock for the feeds  
 */
protected function getFeedsTargetPluginManagerMock() {
  $feedsTargetPluginManager = $this
    -&gt;getMockBuilder('Drupal\feeds\Plugin\Type\FeedsPluginManager')
    -&gt;disableOriginalConstructor()
    -&gt;getMock();
  ...
  // Further mocking of the objects methods if needed.
  ...
  return $feedsTargetPluginManager;
}


Good luck!