Java Unit Tests Maven dependencies snippet

1 minute read

Pretty much every Java project I have uses these dependencies: JUnit + Hamcrest + Mockito.

So, from time to time, this pom.xml snippet containing them proves needed.

The dependencies above avoid having multiple hamcrest versions on the classpath (as JUnit or Mockito may require a different Hamcrest version at a given point in time).

Latest versions of each lib can be checked at the The Maven Central Repository Search Engine:

Some possible questions:

  • “Why hamcrest-junit and not hamcrest-all?”
    • Hamcrest folks have recently changed the way they handle releases. Their goal was to decouple Hamcrest from JUnit. The impact in our life is that we now use hamcrest-junit instead of hamcrest-all. See Hamcrest-JUnit’s repo for more details.
  • “Why mockito-core and not mockito-all?”
    • Basically mockito-all is sort of a fat jar, containing all its dependencies (such as Hamcrest), embedded. As we want to fine tune its dependencies (that’s what the <exclude> tag is!), then -core is the way to go.


Should any other questions arise, I’ll address them here. I’ll also try to keep the snippet’s versions up to date.

Cya!

Tags: , , , , ,

Categories:

Updated:

Leave a Comment