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 - Android Tutorial
From the course: Advanced Android Espresso Testing
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
App: Cat Names1m 28s
-
How intents are used5m 6s
-
Incoming intents: Empty4m 20s
-
Incoming intents: Activity rule2m 45s
-
Incoming intents: Known theme2m 19s
-
Incoming intents: Loading string2m 25s
-
Incoming intents: Unknown theme4m 34s
-
Outgoing intents: Launch activity4m 14s
-
Outgoing intents: Verify intent5m 1s
-
Outgoing intents: How to match?5m 5s
-
Stubbing: Intending1m 16s
-
Stubbing: ActivityResult4m 52s
-
-
-
-