All quizzes
Free quiz · 20 questions in the bank

Hamcrest quiz

Test your Hamcrest knowledge with a free interactive quiz — 20 questions with answers and explanations. No signup needed to play.

Question 1/5Score 0

What does the `is()` matcher do in Hamcrest, e.g. `assertThat(value, is(5))`?

Questions in this quiz
  1. What does the `is()` matcher do in Hamcrest, e.g. `assertThat(value, is(5))`?
  2. What is Hamcrest?
  3. What is a practical downside of over-relying on very generic matchers like `notNullValue()` or `anything()` in tests?
  4. What is `hasProperty()` used for, e.g. `assertThat(person, hasProperty("name", equalTo("Alice")))`?
  5. What is `closeTo()` used for?
  6. What does `containsString()` check, as opposed to `equalTo()`, when asserting on a String?
  7. How does Hamcrest typically integrate with JUnit assertions?
  8. What does `empty()` (and `emptyCollectionOf(Class)`) check?
  9. How do you combine multiple conditions in a single Hamcrest assertion, e.g. requiring a value be both greater than 5 AND less than 10?
  10. How do you write a custom Hamcrest matcher for a domain-specific assertion?
  11. What is `hasSize()` used for on a collection or array assertion?
  12. What advantage does `assertThat(value, greaterThan(5))` have over a plain `assertTrue(value > 5)`?
Gaps to close?
Read the curated Hamcrest notes — core concepts, patterns, interview prep.
Hamcrest notes

More quizzes

.NET.NET MAUIAbsintheAccessibilityActixActix Web