Free Hamcrest Course: Expressive Java Test Matchers

A useful test should make its expectation easy to understand when it succeeds and when it fails. Craig Hawkins’s Hamcrest course introduces a Java matcher library that helps you express those expectations alongside JUnit. It is a focused next step for learners who can already write basic Java and want more ways to describe the result a test should accept.

Original Free Hamcrest Course cover with interlocking matcher tiles, comparison blocks and a magnifying glass, credited to Craig Hawkins.
Free learning access

Listed as Free on Udemy when checked on 8 November 2026. No coupon or subscription trial is required for the listed lessons. Enrollment needs a Udemy account; availability can change.

About this course

A useful test should make its expectation easy to understand when it succeeds and when it fails. Craig Hawkins’s Hamcrest course introduces a Java matcher library that helps you express those expectations alongside JUnit. It is a focused next step for learners who can already write basic Java and want more ways to describe the result a test should accept.

The free English course moves from string and number comparisons to arrays, collections, objects, custom matchers, and JavaBeans. Its current syllabus lists five sections and roughly 44 minutes of material. That compact scope suits a targeted study session, followed by time spent trying the ideas in your own small test project. It does not replace an introduction to Java or a complete unit-testing curriculum.

Official course Hamcrest Quick Start: Enhanced JUnit syntax and capabilities
Created by Craig Hawkins
Platform Udemy
Language English
Level Intermediate
Listed duration 45 minutes; 18 lectures across 5 sections
Completion terms Not included with a new free enrollment

What you’ll learn

Learn to connect an actual value with a matcher, choose comparisons for different data structures, and make test intent more readable. The lessons introduce assertThat and equalTo before exploring strings, numeric bounds, collections, and object properties. Later demonstrations develop custom matchers and provide practice prompts for applying them. The goal is a clearer vocabulary for assertions, with deliberate choices about what each assertion proves.

Skills you’ll gain

  • Hamcrest assertion syntax
  • String and number matchers
  • Array and collection comparisons
  • Object and null checks
  • Custom matcher design
  • JavaBeans property assertions

Make the expectation visible

The opening lessons establish the relationship between the value under test and the condition it should satisfy. String examples cover beginnings, endings, containment, and equality; number examples include ordering and comparisons within a tolerance. These are useful distinctions when a simple true-or-false expression conceals the reason for a failure.

Readable syntax still needs an exact meaning. Hamcrest’s equalTo uses object equality rather than simply asking whether two references identify the same instance. The is wrapper can make an assertion read naturally without adding another condition. When following examples, check the import for Hamcrest’s MatcherAssert.assertThat; do not assume that every assertion method comes from JUnit’s Assertions class.

Choose the right comparison for a collection

The next section moves beyond individual values to arrays, lists, sets, and maps. It also introduces object type and null checks. The practice material applies combinations of expectations to sample data, giving you a reason to think about the requirement before choosing a matcher.

For collections, asking whether an item occurs somewhere is different from specifying every expected item. An order-independent exact-content comparison still needs matching contents and length; it does not automatically allow arbitrary additional entries. Likewise, anything deliberately accepts any value. It can be useful in a larger expression, but it cannot establish a meaningful restriction by itself. Select the least ambiguous assertion for the behavior you actually need.

Build a matcher around a small rule

Four lessons explore custom matchers through odd-number, sum, string-prefix, and alphanumeric examples. This progression takes you from using supplied matchers to describing a condition yourself. A custom matcher needs both a decision about acceptance and a useful description of the expectation, so its value extends beyond shortening a repeated expression.

Keep those examples tied to their teaching purpose. An alphanumeric exercise using English letters and digits is not a universal Unicode validator or a security filter. A numeric tolerance in a practice problem is not automatically suitable for a real measurement system. Before reusing a matcher, identify its accepted values, rejected values, boundary cases, and assumptions. The later JavaBeans lesson adds another way to express expectations about objects.

Try a document-list exercise

For an original practice task, imagine a method that returns the names of three generated reports. Write down whether their order matters, whether duplicates are allowed, and whether an unexpected fourth report should fail the test. Then choose a collection assertion that expresses those decisions. Change one name, add an extra entry, and reverse the order to see whether each expectation matches your written rule.

This is an editorial exercise, separate from the instructor’s assignments. It helps connect matcher selection with observable behavior. Passing these checks would demonstrate only the conditions you tested, not that the entire reporting program is correct. Clear assertions and thoughtful test cases belong together.

Prepare your Java test project

Bring basic Java knowledge, familiarity with JUnit, and an IDE or another way to run Java tests. The course was updated in September 2020, so compare dependency coordinates, imports, and setup details with the documentation for your chosen versions. Keep the learning project small enough that a setup issue does not hide the matcher concept you are studying.

The listed lessons are free to watch. The page also lists an article and two quizzes, but this overview does not promise access to particular downloads, quiz services, or a certificate. Treat the course as a short introduction to expressive assertions and guided matcher practice, then deepen it through your own testing work.

Read the Hamcrest tutorial: Review assertions and matcher concepts. Check collection matching: Distinguish exact contents from simple membership.

Enroll Now ↗

Related courses for your next step

Frequently asked questions

Do I need to know Java and JUnit first?

Yes. The course assumes basic Java and JUnit knowledge. It introduces Hamcrest rather than teaching those foundations from scratch.

Does this course include custom matchers?

Yes. The visible syllabus includes odd-number, sum, prefix, and alphanumeric matcher examples, followed by a JavaBeans lesson.

Will these matchers guarantee correct software?

No. Matchers express test expectations. The usefulness of those tests depends on their cases and assumptions, and passing tests do not prove that a program has no defects.

Share this course

Learner reviews

Tell other learners what you actually tried. Reviews are moderated and may come from learners who have started or completed the course.

No published learner reviews yet.

Sign in to write a review

Questions still belong in the discussion below. Review and ranking rules.

Questions & discussion

Share a useful question or correction. Comments appear after moderation. Please avoid personal or sensitive information.

Add to the discussion

Keep comments relevant and respectful. Spam, adult content, and adult-site names or links are not allowed. All visitor comments are reviewed before publication.

Your email address will not be published. Required fields are marked *