Question: Need help on a unit testing on handling the empty string, pretty new to java. @Test void should_handle_null_string() { assertNull(ClassName.methodName(null)); } @Test void should_handle_empty_string() {
Need help on a unit testing on handling the empty string, pretty new to java.
@Test void should_handle_null_string() { assertNull(ClassName.methodName(null)); } @Test void should_handle_empty_string() { assertTrue(ClassName.methodName("").isEmpty()); } For the first test, I can successfully use "if (input == null) return null;" to pass. However, I encountered the problem on the second one. Since the output of the method is String, so when I tried using the following:
if (input.equals("")) return String.valueOf(true); It cannot pass. The error shows that "expected:
"
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
