How to create a unit test for a class which uses a trait?
Following on Bedir's answer, here is an example.
I have a test that is using the class DurationService. DurationService uses the StringTranslationTrait as follows:
class DurationService implements DurationServiceInterface {
  use StringTranslationTrait;
  ...

To test this, I am doing the following (note, using a class that extends UnitTestCase):
$duration_service = new DurationService();
$duration_service-&gt;setStringTranslation($this-&gt;getStringTranslationStub());

This calls StringTranslationTrait::setStringTranslation() passing it the response from UnitTestCase::getStringTranslationStub().