Mocking ViewModel for Espresso tests

Viewed 170

I decided that it's time to automate some tests, and I wanted to start using Espresso. I was following few tutorials, but I am not able to make it work in my app because of my architecture.

My app is following MVVM architecture, and I am using Hilt for dependency injection. My idea is to mock (using Mockk) the ViewModel to be able to control the flows and the data, but I am not getting how to do it, and when I run the test, the real ViewModel is being called.

This is an example of how I instantiate my ViewModel in my fragment:

This is an example of how I instantiate my ViewModel in my fragment.

Anybody could help me with it? I would be super thankful!

1 Answers

Espresso tests are not used for mocking or with mocking. Espresso is used for complete UI testing while running on the real device or emulator. With espresso, you're navigating through app functionality and verifying that everything works.

Related