Join Chiu-Ki Chan for an in-depth discussion in this video ScreenRobot, part of Effective Android Testing for Mobile Developers.
- [Instructor] We will create the class screen robot as the basis for all robot classes. This serves two purposes. One, it abstracts common verifications such as a view being not selected from multiple calls I.e not and is displayed into a single convenient function. Two, it returns the robot itself at the end of the verifications so we can chain the calls together in a fluid manner.
First create the base class screen robot. Right click on the test folder and the Android test Java. Select "New Java Class" We will call it screen robot. This is going to be an abstract class that contains view related methods. So in line three put the word abstract after public. We are going to make it a generic class. So after the word screen robot add T extends screen robot.
The generic type T allows us to write the shared methods in this base class but still return the proper type so that we can chain them up in a fluid manner. This becomes clearer with an actual method. So let's write one. Check is hidden. We are going to write this method as public T, being the return value, and then the name check is hidden. It will take a list of integers which are the view IDs.
Annotate it with at IDRES so that other student knows that these have to be view IDs and not just any integers. Inside the function make the follow for int view ID colon view Ids and then we will check that each of them is not displayed. On view with ID and then view ID. Once we found the view we will check that it's not displayed.
Dot check matches not is displayed. Put your mouse over matches alt enter static input method and choose view assertions. Then put the cursor over not alt enter and then any one of these are okay so just choose one. Finally to make it fluid we will return this, the robot itself.
In line 17 we do return and then parenthesis T, this. This is why we will need the type T when we return this in the base class it is a screen robot but we actually want it to be the exact type. For instance when we make a recipe robot we want to return recipe robot. With the type T we can do that.
- 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.