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 is `hasSize()` used for on a collection or array assertion?

Questions in this quiz
  1. What is `hasSize()` used for on a collection or array assertion?
  2. 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?
  3. What is the difference between `hasItem()` and `contains()` for asserting on a collection?
  4. What is the purpose of `Matchers.describedAs()` (or overriding `describeMismatch`) in Hamcrest?
  5. What is Hamcrest?
  6. What does `instanceOf()` (or `isA()`) check?
  7. What is a practical downside of over-relying on very generic matchers like `notNullValue()` or `anything()` in tests?
  8. Why might a team prefer AssertJ's fluent assertions (`assertThat(value).isEqualTo(...).isGreaterThan(...)`) over Hamcrest in a newer Java codebase?
  9. What is `hasProperty()` used for, e.g. `assertThat(person, hasProperty("name", equalTo("Alice")))`?
  10. What is `closeTo()` used for?
  11. What does the `not()` matcher do?
  12. How do you write a custom Hamcrest matcher for a domain-specific assertion?
Gaps to close?
Read the curated Hamcrest notes — core concepts, patterns, interview prep.
Hamcrest notes

More quizzes

.NET.NET MAUIAbsintheAccessibilityActixActix Web