Skip to main content

Java

Mastering JUnit 5 @TestFactory: Dynamic Testing Beyond Parameterized Tests

In the world of Java unit testing, we are mostly accustomed to the standard @Test annotation. These are static tests—their structure and logic are set in stone the moment you compile your code. But anyone who has tried to test rule engines, data migrations, or complex validation pipelines knows the pain: either you duplicate dozens of nearly identical tests or force-fit everything into a parameterized test that eventually becomes unreadable. What if you need to generate hundreds of test cases based on a JSON file, a database result set, or complex runtime logic? Enter Dynamic Testing with JUnit 5. In this comprehensive guide, we’ll explore the @TestFactory annotation, how it differs from traditional testing models, and how to leverage it to make your test suites more flexible, maintainable, and powerful. What is a Dynamic Test? Standard JUnit tests are "fixed." When you write a method annotated with @Test, JUnit knows exactly how many tests exist before the execution starts. A DynamicTest, however, is a test generated during runtime by a factory method. Think of it as the difference between a static HTML page and a React application. One is hardcoded; the other builds its UI based on the data it receives. Dynamic tests allow you to programmatically create a series of tests based on a data source, a list of objects, or even a continuous stream of events.

The Complete Guide to JUnit 5 @ParameterizedTest: Write Smarter, Faster, and Cleaner Java Tests

Every official way to feed a @ParameterizedTest, built and run against a real JUnit 6.1.3 module: @ValueSource through @ArgumentsSource, how display names actually compile to a MessageFormat pattern, two real anti-patterns caught failing on purpose, and three genuine bugs found by rebuilding this guide's original examples from scratch instead of copying them forward.

Organising and Displaying JUnit Tests: @DisplayName, @Nested, @Tag (JUnit 5 → JUnit 6)

A beginner-first, fully verified guide to @DisplayName, DisplayNameGenerator, @Nested, and @Tag in JUnit — every code example and console transcript comes from a real Maven module built and run against JUnit 6.1.3, the current GA release verified against Maven Central. Covers what changed for these three annotations between JUnit 5 and JUnit 6, including a real behaviour change (deterministic @Nested ordering) that most migration guides mention only in passing.

JUnit Conditional Test Execution (JUnit 5 → 6)

Run tests only where they belong. Every conditional-execution example from my 2025 article, re-run on JUnit 6.1.3 and JDK 25 with the real skip reasons, what changed from JUnit 5, and where the old text was wrong.

Dozer Bean Mapping in Java: Practical Guide with Benchmark vs MapStruct

Dozer is a battle-tested Java bean mapper that eliminates DTO-to-entity boilerplate using runtime reflection. This guide covers basic and nested mapping, custom converters, Spring integration, and a head-to-head benchmark vs MapStruct — so you can choose the right tool for your project.

JUnit @RepeatedTest in JUnit 6: RepetitionInfo, failureThreshold, and Real Flaky-Test Detection

JUnit's @RepeatedTest runs the same method N times, each with its own pass/fail result. Rebuilt here against real JUnit 6.1.3 on JDK 25: all four RepetitionInfo accessors (not just two), RepetitionInfo injected into @BeforeEach/@AfterEach, what failureThreshold actually does when it fires (skips, not stops), a real flaky-test detection demo, and a placeholder the original version of this post claimed existed but never did.

How to Check if a Number is a Pronic Number in Java

Whether you are preparing for a technical interview or exploring the fascinating world of number theory, encountering Pronic numbers is almost a rite of passage for Java developers. These numbers, often hidden in pattern-matching puzzles, have unique properties that make them a favorite for practicing algorithmic efficiency. In this guide, we will dive deep into what Pronic numbers are and demonstrate two distinct ways to identify them using Java—ranging from a beginner-friendly loop to a high-performance mathematical "trick." What is a Pronic Number? A Pronic number (also known as an oblong or rectangular number) is a number that is the product of two consecutive integers. Mathematically, a number P is pronic if it can be expressed as: P = n X (n + 1) For some integer n. Examples of Pronic Numbers: 0: 0 X 1 = 0 2: 1 X 2 = 2 6: 2 X 3 = 6 12: 3 X 4 = 12 20: 4 X 5 = 20