This might be a conceptually stupid question, but it also might not and since I am still a student I think I should I have no problem asking.
Imagine you have a method that if given certain conditions it will throw an NumberFormatException. I want to write a Unit Test to see if the exception is being correctly thorwn. How can I achieve this?
P.S. I am using JUnit to write the Unit Tests.
Thanks.
As other posters suggested, if you are using JUnit4, then you can use the annotation:
However, if you are using an older version of JUnit, or if you want to do multiple “Exception” assertions in the same test method, then the standard idiom is: