Search⌘ K
AI Features

Assertions: assertEquals() and assertNotEquals()

Understand how to apply assertEquals and assertNotEquals in JUnit 5 to compare expected and actual values in unit tests. Explore the various overloaded methods for different primitive types, delta comparisons for floating points, and how message suppliers improve test feedback.

The assertEquals() method

The assertEquals() method asserts that two given values are equal.

  • If the actual value is equal to the expected value, the test case passes.
  • If the actual value isn’t equal to the expected value, the test case fails.

It has many overloaded methods for different primitive types and objects. For example, for the int primitive type, there are three different overloaded methods: ...