Unit Testing Anti-Patterns
Writing unit tests might be challenging, especially when dealing with an ongoing project with already established hard-to-break anti-patterns. I will go through some of the most common pitfalls I’ve encountered quite often. Verifying the stubs Let’s suppose we write the following piece of code: @AllArgsConstructor public class UserCreationService { private final UserFactory factory; private final UserRepository repository; private final NotificationService notificationService; public void create(UserCreateRequest request) { var user = factory.createEntity(request); user = repository.save(user); notificationService.notify(USER_CREATED, user.getId()); } } And then create a test for the happy path: ...