From the course: Advanced Android Espresso Testing

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Incoming intents: Loading string

Incoming intents: Loading string - Android Tutorial

From the course: Advanced Android Espresso Testing

Start my 1-month free trial

Incoming intents: Loading string

- [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…

Contents