Mockito
In the preceding examples, we looked at how to set up a unit test and how to use assertions to verify the result of an operation. What if we want to verify whether a certain method was called? Or what if we want to manipulate the test input in order to test a specific scenario? In these types of situations, we can use Mockito. This is a library that helps developers set up dummy objects that can be injected into the objects under test and allows them to verify method calls, set up inputs, and even monitor the test objects themselves.
The library should be added to your test
Gradle setup, as follows:
testImplementation 'org.mockito:mockito-core:3.6.0'
Now, let's look at the following code example (please note that, for brevity, import statements have been removed from the following code snippets):
class StringConcatenator(private val context: Context) { fun concatenate(@StringRes stringRes1: Int, ...