Join Chiu-Ki Chan for an in-depth discussion in this video Incoming intents: Loading string, part of Advanced Android Espresso Testing.
- [Instructor] Let's take a look at the…Punny Test Method.…On line 30 we had coded the string Punny.…In general, it is better to load strings from…resources instead of hot coding it.…That way when we update a string resource…the test automatically looks for the updated string.…To load a string resource we need a context.…Let's add that.…
In the beginning of the test method on line 29 add…val context…= InstrumentationRegistry….getTargetContext…Make sure you pick getTargetContext…instead of getContext.…What is the difference?…getContext gives you the context of the test APK…which does not contain the strings in the app.…
For that you need getTargetContext.…Now that we have a context…we can load the string with context.getString…On line 31…type val theme…= context….getString…and then R.string.theme_punny…Next, replace the hot coded strings with this theme.…
On line 34 for the second parameter…replace the hot coded string Punny with theme.…Do the same on line 38.…Let's run the test to make sure it still passes.…Click on the green triangle.…
- Incoming and outgoing intents
- How intents are used
- Dependency injection
- Why extract dependencies?
- Mockito and Dagger
Skill Level Advanced
Effective Android Testing for Mobile Developerswith Chiu-Ki Chan2h 56m Intermediate
Android App Development: Data Persistence Librarieswith Annyce Davis4h 52m Intermediate
2. Hermetic Test Environment
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.