Why do we mock the repository?

Our tests written in this video wants to specifically test the service. During our tests, we don't want to be reliant on an API we do not have control over. For example, what would happen to our tests if the server was down?

So to fix this we mock out the repository. That way during our tests when the service calls the repository to make the API calls, we can specifically tell our mock to return specified values instead. This way we are in control of whether we want to test with a value, exception, and so on.

Given-When-Then

There are a bunch of different naming conventions of tests. I have a habit of using Given-When-Then but this is just a matter of what you like the most and think is the most readable.

Here is a blog post with 7 different naming conventions that you can pick from. Go with whatever you enjoy the most but the important part is sticking with the same naming convention throughout the project!