Reputation: 582
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!
Upvotes: 1
Views: 161
Reputation: 339
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");
});
Upvotes: 1