Junit-5

JUnit 5 Nested Tests: Grouping Related Tests Together

This tutorial demonstrates how to use JUnit 5 nested tests to structure tests hierarchically, making it easier to group related cases and navigate results. It covers simple examples with nested classes, multi-layered nesting for REST controllers, and tips to avoid pitfalls like excessive duplication. Using nested tests improves readability and helps maintain clean, organized test code.

Testing

Using Mockito With JUnit 5

This guide explains how to integrate Mockito with JUnit 5 for effective unit testing. It covers three approaches: manual mock creation, annotation-based initialization, and using the Mockito JUnit 5 extension for automatic mock injection. By following these methods, you can simplify test setup, improve readability, and validate mock usage efficiently.

Testing

JUnit 5 Test Lifecycle: Before and After Annotations

This tutorial explores how to run code before and after tests in JUnit 5, both for individual tests and across the entire test class. It explains the differences between per-test and per-class test instances, handling nested tests, and how extensions wrap test execution. Learning these patterns helps manage shared resources and maintain predictable test behavior.

Testing

JUnit 5 Expected Exception: How to assert an exception is thrown?

This tutorial explains how to confirm that a specific exception is thrown in JUnit 5 tests and how to inspect the exception message. It covers handling unexpected or missing exceptions and shows how capturing the exception allows for more detailed assertions. Following these practices ensures reliable and precise error-handling tests.

Testing

A More Practical Guide to JUnit 5 Parameterized Tests

This tutorial explains how to create parameterized tests in JUnit 5, allowing the same test to run with different inputs. It covers single and multiple arguments, using external data sources like CSV files, and custom conversions or aggregations for complex types. Parameterized tests help reduce duplication and make test code more maintainable and readable.

Testing

Getting Started with JUnit 5: Writing Your First Test

This guide walks you through writing a simple JUnit 5 test to ensure your code works as intended. You’ll learn how to set up tests, verify expected results, and run them using an IDE, Maven, or Gradle.

Testing

JUnit 5 Assertions: Verifying Test Results

This article covers how to use JUnit 5 assertions to validate test results, including values, booleans, nulls, arrays, objects, exceptions, and timeouts. It explains custom error messages and grouped assertions for clearer reporting. For advanced scenarios, it also introduces third-party libraries like Hamcrest, AssertJ, and Truth to make assertions more readable and expressive.

Testing

JUnit 5 With Kotlin for Java Developers

This article explores writing JUnit 5 tests in Kotlin and configuring them with Gradle Kotlin DSL. It covers Kotlin-specific syntax for assertions, parameterized tests, dynamic and nested tests, lifecycle methods, and handling static fields. Readers will learn how Kotlin’s features can make test code more readable while fully supporting JUnit 5 functionality.

Testing

JUnit 5 Maven Example: Running Tests with Surefire

This guide demonstrates how to configure Maven for JUnit 5 testing, including adding dependencies and setting up the Surefire plugin. It covers both current Maven versions with native support and older versions requiring extra configuration. By following this example, you can run JUnit 5 tests seamlessly in your Maven projects.

Testing

JUnit 5 Gradle Example

This guide shows how to configure Gradle for JUnit 5, including adding dependencies and enabling the JUnit platform for running tests. It covers both modern Gradle versions with native support and older versions using the JUnit Gradle plugin. By the end, you’ll be able to run JUnit 5 tests successfully in your Gradle projects.

Testing