From the course: Kotlin Essential Training: Functions, Collections, and I/O

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Mocking data

Mocking data

- [Instructor] Sometimes it's not possible to easily set up the environment for a specific test. This could be due to types that are not open for extension, complex dependency graphs, or other reasons. In these situations, it can be helpful to mock out the data and responses that we need to effectively write our test. Mockito is a popular mocking tool for Java development and works great for Kotlin code as well. So here's a testing scenario for us. If we open up our code here, we'll see that we have an AnalyticsClient interface, and this interface allows us to track some analytics event. And we also have a ViewModel class. That ViewModel class takes in an instance of an analyticsClient, and it has a public method called submitClicked. And when that button is clicked, it should track an analytics event using that analyticsClient. Now our task is to write a test that validates the tracking of that analytics event when…

Contents