The builder pattern is one of the more useful patterns out there when creation unit tests. Instead of having a huge initialization such as: @Test void validateUser_userNameIsEmpty_returnFalse(){ var user = new User(); user.setId("id-1"); user.setName(null); user.setPhoneNumber("555-1234"); // additional user initialization boolean result = userService.validate(user); assertFalse(result); } You can instead create a simple user builder object for … Continue reading Easily create builders for your tests using Intellij IDEA
Tag: JUnit
Better tests names using JUnit’s display names generators
Writing unit tests can be challenging, but there is one thing that can get you on the right track - the test name. If you manage to give your test a good name - you will write a good test. Unfortunately in some (read: many) unit testing frameworks the test name must be a valid … Continue reading Better tests names using JUnit’s display names generators