Join Chiu-Ki Chan for an in-depth discussion in this video TestRecipeApplication, part of Effective Android Testing for Mobile Developers.
- [Instructor] Now we need to have a different application during test. First, create test recipe application by right clicking on the package name under Android test. Scroll up, click on the package name, right-click, new Java class. We will call it, test recipe application. Append dot injection in the package name. Press okay. We will have test recipe application extend recipe application.
This way, it can be used in place of recipe application during test. We will need to override the get favorites function so that it returns shared preferences favorites instead of in-memory favorites. Press Control + Alt and override get favorites. Instead of calling the super.getFavorites, what we will do is we'll make a final field called favorites, which is an in-memory favorites and return it here.
Outside of the get favorite function we will add private, final, favorites, and then we'll call it favorites. We'll initialize it to new in-memory favorites. And then, in line 11, we will return this favorites. To use a test recipe application during testing, we need a custom test runner. Let's open app slash build.gradle. Command + Shift + O, build.gradle.
Here you can see that test instrumentation runner is the Android J unit runner in line 13. Next we will create our own test runner and use it here.
- Why test?
- Local vs. on-device
- Code coverage
- UI testing
- Hermetic environment
- Dependency injection
- Testing with MVP
Skill Level Intermediate
Android App Development: Unit Testingwith James P White2h 58m Intermediate
Android Studio Essential Trainingwith David Gassner3h 41m Beginner
Android App Development: Data Persistence Librarieswith Annyce Davis4h 52m Intermediate
1. Testing Considerations
2. Test as You Go
3. UI Testing
4. Hermetic Environment
5. Robot Pattern
- 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.