Most of us are aware of the general principals of writing testable code. Drupal 8, based on Symfony, leverages a service based architecture where the services themselves are modular and the injected dependencies for each service class can be derived from a number of places. On a Drupal site, in normal operation these dependencies will come from the "Container", which uses the definition in your mymodule.services.yml.
When testing, you can still leverage the container to pull services from, but it is also necessary at times to pass mock dependencies to your services in order to provide predictable results.
See the post on setting up a kernel test for an overview of writing tests in Drupal 8. This article will continue to use the example of a service that uses networking resources.