Posts

Showing posts from March, 2014

HOW-TO: Test dependencies in a Maven project (JUnit, Mocito, Hamcrest, AssertJ)

Image
JUnit itself is not enough for most of today's Java projects. You also need a mocking library, maybe something else. In this mini HOW-TO I present the test dependencies you can start with in a new Java project.

JUnit ExpectedException rule: beyond basics

Image
There are different ways of handling exceptions in JUnit tests. As I wrote in one of my previous posts , my preferable way is using org.junit.rules.ExpectedException rule. Basically, rules are used as an alternative (or an addition) to methods annotated with org.junit.Before , org.junit.After , org.junit.BeforeClass , or org.junit.AfterClass , but they are more powerful, and more easily shared between projects and classes. In this post I will show more advanced usage of org.junit.rules.ExpectedException rule.