Java Unit Tests Maven dependencies snippet
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:
- JUnit:
junit
; - Hamcrest:
hamcrest-junit
; - Mockito:
mockito-core
.
Some possible questions:
- “Why
hamcrest-junit
and nothamcrest-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 ofhamcrest-all
. See Hamcrest-JUnit’s repo for more details.
- 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
- “Why
mockito-core
and notmockito-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.
- Basically
Should any other questions arise, I’ll address them here. I’ll also try to keep the snippet’s versions up to date.
Cya!
Leave a Comment