Hearn how to handle code conditionals, exceptions, ignoring tests and how to simplify tests with before/after test methods.
- [Voiceover] The code, and therefore the unit test,…so far demonstrated are pretty simple.…There aren't too many things that could go wrong,…nor are there any conditional paths and exception paths…in the code.…If there were, we would wanna have separate unit tests…to exercise each.…For example, what if my simple math class…also included a div method?…If the div method is called with zero,…as the argument for op2, the divisor,…we're going to get a Java.lang ArithmeticException,…due to the division by zero.…
I started Android Studio again and opened project two…to start.…My simple math class now has a div method…that could throw such an exception.…There are a number of ways this issue could be handled,…or not handled, in the code.…The method could detect a problem and just return zero…as the quotient.…In my test class, simple math test,…there should be more unit tests for the div method…in simple math.…Any alternate path or conditional in the method…should be exercised along with the main, or happy, path,…as developers like to call it.…
AuthorJames P White
- Why unit test?
- Unit testing tools
- Local testing with JUnit
- Working with JUnit assertions, rules, and categories
- Executing instrumented tests
- Filtering tests
- Testing with UI Automator and other testing tools
Skill Level Intermediate
UX Foundations: Usability Testingwith Chris Nodder1h 29m Beginner
1. Getting Started
2. Local Tests
3. Instrumented Tests
4. Other Android SDK Testing Tools
5. Mocking objects
- 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.