Which Hamcrest matcher to import

Viewed 554

I am using Hamcrest in a gradle/JVM project via the org.hamcrest:hamcrest:2.2 artifact which is what the Hamcrest website recommends. When I go to static import a matcher, e.g. is or notNullValue, I am presented with 3 options of where to import it from. In the case of notNullValue these are:

  • org.hamcrest.CoreMatchers
  • org.hamcrest.Matchers
  • org.hamcrest.core.IsNull

I was wondering if there was a 'best practice' one to choose?

choice of imports

1 Answers

You can import all of these functions like this:

import static org.hamcrest.Matchers.*;
Related