Programmer2B
Programmer2B

Reputation: 582

JUnit testing throw NullPointerException

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

Answers (1)

Tim Winters
Tim Winters

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

Related Questions