Testing With Hilt Tutorial: UI and Instrumentation Tests

Learn how to get started with testing with Hilt by writing UI and instrumentation tests. By Massimo Carli.

Leave a rating/review
Download materials
Save for later
Share
You are currently viewing page 4 of 4 of this article. Click here to view the first page.

Implementing Tests to Help Structure the Code

In the previous test, you could have just replaced the binding for NewsRepository instead of the entire AppModule. You did it that way to see how to replace a @Module, but it proves how important it is to group bindings together depending on how you might change or replace them in a test.

Even if NewsRepository and RwNewsLogger have the same scope, you should still define them in different @Modules.

Where to Go From Here?

To see the final version of the RW News app, download the project by clicking the Download Materials button at the top or bottom of this tutorial.

Great job completing the tutorial! First, you learned how to configure your project to run a different kind of test using Hilt. You then implemented a UI test using Hilt with Robolectric. Finally, you configured your project to use Hilt to run instrumentation tests.

During this journey you also met and used @UninstallModules and @BindValue.

To learn more about dependency injection with Hilt, check out the Dependency Injection with Hilt: Fundamentals video course.

The Dagger by Tutorials book also provides an in-depth look at how to use Dagger and Hilt.

We hope you enjoyed this tutorial. If you have any questions or comments, please join the forum discussion below!