JUnit testing throw NullPointerException

Viewed 43

I need to test a function in JUnit5 (interface-based). I do not have the implementation. If one of the function's parameters is null, I need to throw NullPointerException. My question is, how can I test this function to throw a NullPointerException? Thank you!

1 Answers

Can you be more clear in your explanation of the problem? What does

without using the function's output (only the parameters)?

mean?

JUnit has as way of testing if a method throws an exception

Exception exception = assertThrows(NumberFormatException.class, () -> {
        Integer.parseInt("1a");
    });
Related