Learn how to use the Hamcrest Library in assertions for better unit tests.
Assertions are the way to check and validate results…and unit tests.…However as tests become more complex…the simple assertion methods found in the assert class…can make writing and reading the unit tests awkward.…Further, the assertion methods put much of the onus…on the developers to produce good quality unit tests.…Developers must provide helpful failure messages…and they must be very type conscious…when comparing the expected to the actual.…The Hamcrest Library is an augmenting library…to help unit testers create assertions…that are easier to read and write,…provide better failure messages,…and provide some type safety.…
Specifically, the library contains a set of predicates…called matchers.…These matchers are used with the assertThat…static method provided in the assert class.…I've started Android Studio and opened project 02_06_start.…Let's look at some examples of issues…surrounding the assertion methods…and how the Hamcrest Library can help.…In the ExampleUnitTest class, provided with this project,…I've provided a number of methods using both asserts…
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
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.