In JUnit there are many ways of handling exceptions in your test code: try-catch idiom With JUnit rule With @Test annotation With catch-exception library With custom annotation With Lambda expression (as of Java 1.8) With AssertJ 3.0.0 for Java 8 (NEW!) With JUnit 5 built-in assertThrows Which one should we use and when?
To improve the readability of my unit tests I use assertThat with Hamcrest matchers. This is a good way to improve readability of your test code, especially when I statically import members of like org.junit.Assert.assertThat and org.hamcrest.Matchers . But when I add Mockito matchers on top of it, I experienced the problem of static import conflicts that ended up with "not nice" code (according to my definition).
I have been working with unit testing for several years and I always had problems in finding the best names for my tests. I have been trying different conventions and I ended up with the practice of naming tests based on the behavior they test.