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/12Score 0

What does `containsString()` check, as opposed to `equalTo()`, when asserting on a String?

In this round
  1. What does `containsString()` check, as opposed to `equalTo()`, when asserting on a String?
  2. What is Hamcrest?
  3. What does `empty()` (and `emptyCollectionOf(Class)`) check?
  4. What does the `not()` matcher do?
  5. What is the basic syntax pattern for a Hamcrest assertion?
  6. What does `containsInAnyOrder()` provide that plain `contains()` doesn't?
  7. Why might a team prefer AssertJ's fluent assertions (`assertThat(value).isEqualTo(...).isGreaterThan(...)`) over Hamcrest in a newer Java codebase?
  8. What does the `is()` matcher do in Hamcrest, e.g. `assertThat(value, is(5))`?
  9. What is a practical downside of over-relying on very generic matchers like `notNullValue()` or `anything()` in tests?
  10. What is `hasSize()` used for on a collection or array assertion?
  11. What does `instanceOf()` (or `isA()`) check?
  12. 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?
Gaps to close?
Read the curated Hamcrest notes — core concepts, patterns, interview prep.
Hamcrest notes

More quizzes

.NET.NET MAUIAbsintheAccessibilityActixActix Web