0
votes

I have a class (call it filetest) in a class library (b), which is trying to get files from a directory which does not exist. This throws an exception fine, and there is a throw in the catch block.

Above in the callstack in a class called Test (excuse the names as this si a test), there I call the class filetest and the method which reads the wrong directory, and try to catch the exception.

I have an NUnit test which calls the class/method responsible for invking filetest and the method which reads the wrong directory. I have an expectedexception attribute, set to DirectoryNotFoundException, but the test fails saying "UnsupportException thrown". Am I wrong to expect an exception in the method in Test?

Thanks

1
Please show the code. It looks as if you are not throwing a DirectoryNotFoundException but something else. - Daniel Hilgarth
I agree with Daniel Hilgarth. It would be really helpful if you could include the code - specifically the part from your try/catch block where the exception is rethrown. - Richard J Foster

1 Answers

0
votes

. Am I wrong to expect an exception in the method in Test?

Yes, for the following reasons:

  • The assumption is false
  • There may be multiple exceptions for a single test