Re: Assume
"Daniel M. Pomerantz" <[email protected]>
| Newsgroups | gmane.comp.windows.dotnet.nunit.devel |
|---|---|
| Message-ID | <[email protected]> |
See the " //Do some stuff here " That's the code outside of the try. Nothing should go after the catch though. dmp Kelly Anderson wrote: > On Fri, Feb 15, 2008 at 2:51 PM, Daniel M. Pomerantz > <[email protected]> wrote: > >> See inline: >> Kelly Anderson wrote: >> > Do you Assert the line of code threw the exception that you expected? >> > That seems like the Test is tied too closely to the implementation for >> > my taste. >> > >> > >> >> All I'm saying here is that if you have >> >> [ExpectedException(typeof(InvalidCastException))] >> >> And the test passes, all you know is that some line of code caused an >> invalid cast exception to be thrown. I supposed you can have some >> degree of certainty that the line you wanted to throw the exception did, >> but I don't know of a way to enforce that. >> >> Compare that too this: >> >> public void foo() >> { >> //Do some stuff here >> >> try >> { >> DoSomethingThatThrowsAnException(); >> >> Assert.Fail("Exception not Thrown"); >> } >> catch (InvalidCastException ex) >> { >> //Do Nothing...Swallow it >> } >> } >> >> >> In this case, you know exactly which line of code raised the exception. >> I'm not saying it's easier to maintain - To be 100% clear, I remove this >> second example of code and replace it with the first when I see it, as >> do you. My point is that you have a bit more certainty that what >> happened is what you expected with this example, for better or for worse. >> > > Honestly, I don't see the difference unless you have some code outside > the try as well. The semantics seem equivalent in the case you > present. > > -Kelly > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > nunit-developer mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/nunit-developer > > > ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/