Using assertNull() and assertNotNull() methods together
Explore how to apply assertNull and assertNotNull methods in JUnit 5 to test different return values from Java methods. Understand how to verify null, empty, and non-null strings in unit tests to ensure accurate test coverage.
We'll cover the following...
We'll cover the following...
Demo
Step 1 - Create a Java class in Eclipse as discussed in previous lessons.
Step 2 - Give it a name as, StringUtils.`
Class Under Test - StringUtils
StringUtils is our class under test. It has one method as, reverse(). This method takes in a String and returns reverse of it.
For example -
-
If we provide input String as, “ABCD”, it returns back “DCBA”.
-
If we provide input String as, “Student”, it returns back “tnedutS”.
-
If we provide input ...