Search⌘ K
AI Features

assertIterableEquals method

Explore the assertIterableEquals method in JUnit 5 to verify that iterables match in size, order, and content. Understand how to use its overloaded forms through practical test examples, identifying equality and failure cases for robust unit test assertions.

We'll cover the following...

assertIterableEquals() method

Assertions API provide static assertIterableEquals() method. This method helps us in validating that expected and actual iterables are deeply equal. By, deeply equal we mean that number and order of elements in the collection must be the same, as well as iterated elements must be equal.

There are basically three useful overloaded methods for assertIterableEquals:-

Java
public static void assertIterableEquals(Iterable<?> expected, Iterable> actual)
public static void assertIterableEquals(Iterable<?> expected, Iterable> actual, String message)
public static void assertIterableEquals(Iterable<?> expected, Iterable> actual, Supplier<String> messageSupplier)

Demo

Let’s look into the ...