Posts for: #Junit

Fixing Pageable Errors in JUnit MockMvc Tests

If you’ve tried unit testing a Spring controller that accepts a Pageable parameter using JUnit 5 and Mockito with MockMvc, you might have encountered this error:

java.lang.IllegalStateException: No primary or single unique constructor found for interface org.springframework.data.domain.Pageable

This happens because, in a standalone MockMvc test (without loading the full Spring context), Spring doesn’t automatically know how to convert query parameters like page, size, and sort into a Pageable object. Without the proper resolver, it tries to instantiate Pageable directly, which fails because it’s an interface.

Read more

Writing parameterized tests for Junit 5?

As a software engineer, I often encounter situations where I need to run the same test logic with different input values. Repeating the same test with minor variations not only clutters your test classes but also violates the DRY (Don't Repeat Yourself) principle.

That’s where parameterized tests come into play. Since JUnit 5, writing these tests has become much easier and cleaner. In this post, I’ll walk you through how to use parameterized tests effectively with JUnit 5.

Read more