What if your tests could instantly tell you if your code broke without you lifting a finger?
Why assertEquals in JUnit? - Purpose & Use Cases
Imagine you have a calculator app and you want to check if adding 2 + 2 gives 4. You try it yourself every time by clicking buttons and writing down results on paper.
This manual checking is slow and tiring. You might make mistakes writing results, forget to check some cases, or miss errors when the app changes.
Using assertEquals in JUnit lets you automatically compare expected and actual results in code. It quickly tells you if the test passed or failed without guessing.
if (add(2, 2) == 4) { System.out.println("Pass"); } else { System.out.println("Fail"); }
assertEquals(4, add(2, 2));
It enables fast, reliable checks that catch mistakes early and save time.
When developers update the calculator, assertEquals tests instantly verify all math still works correctly without manual re-checking.
Manual checks are slow and error-prone.
assertEquals automates result comparison.
It makes testing faster, easier, and more accurate.