Udemy
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
Hamcrest Quick Start: Enhanced JUnit syntax and capabilities
Rating: 4.5 out of 5(28 ratings)
2,136 students

Hamcrest Quick Start: Enhanced JUnit syntax and capabilities

Learn how to use Hamcrest to make your JUnit tests easier to read and write.
Created byCraig Hawkins
Last updated 9/2020
English
English [Auto],

What you'll learn

  • How to use Hamcrest to make unit tests more expressive
  • How to use Hamcrest to increase unit testing capability
  • How to use Hamcrest to ease unit testing development
  • How to write and run custom Hamcrest matchers

Course content

5 sections • 18 lectures • 44m total length
  • Hamcrest source code.0:03

    You will need to download and install Hamcrest for Java:

    https://github.com/hamcrest/JavaHamcrest

  • Introduction0:49

    After watching this video, students will understand the advantages of using Hamcrest, and the requirements for the course.

  • assertThat(), equalTo() methods2:07

    Explore Hamcrest's assertThat and equalTo methods to express assertions, verify a string length equals three, and use an optional custom error message with imports.

  • String methods2:33

    Explore Hamcrest string assertions by using starts with, ends with, contains, and equals, plus ignore case, empty and blank checks, to validate strings in unit tests.

  • Number methods2:50

    Explore Hamcrest number methods for numeric assertions, using integers with less than, less than or equal to, equal to, greater than or equal to, and greater than, and floating-point checks within plus or minus delta.

  • Expressive syntax1:33

    Explore Hamcrest expression methods that boost JUnit readability by crafting expressive asserts with string comparisons and test annotations, and practice writing your own readable asserts.

  • Matcher practice 12:49

    Practice writing Hamcrest matchers to verify ride eligibility using a Person class with age and height, creating tests for eligible and not eligible, based on 10 and 48 inches.

  • Matcher practice 21:58

    Practice writing compressed matches with Hamcrest by testing thermometer readings against known values within 0.2 degrees Celsius using the closeTo matcher, iterating over arrays, and asserting each result.

  • Quiz 1

Requirements

  • Basic abilities with Java and Junit.
  • Basic abilities with an IDE.

Description

JUnit is one of Java's most popular unit testing frameworks.  Hamcrest is an additional layer that sits on top of JUnit, and it allows you to write expressive and developer-friendly unit tests.  In this course, you will learn which imports to use, how to write and run Hamcrest tests, how to use Hamcrest's fundamental methods, and how to write your own custom Hamcrest matchers.  No prior knowledge of Hamcrest is necessary. The course is example-driven instruction and includes guided practice and quizzes to strengthen your understanding. Basic knowledge of Java programming and JUnit is required.

Who this course is for:

  • Developers looking to add Hamcrest into their unit testing
  • Students wishing to learn Hamcrest
  • Academics wishing to learn development tools used in industry
  • Software team leaders looking to evaluate Hamcrest as a development tool