Hmm, this is something I did not know: when a testing framework’s Assert method fails, an exception gets thrown. We don’t actually see that exception, because the framework catches it. We usually don’t see it because tests normally look like this:
[Test] public void SomeTest() { Assert.IsTrue(false, "whatever"); }
However, say the test was written like this:
[Test] public void Test() { try { Assert.IsTrue(false, "whatever"); } catch (Exception ex) { Console.WriteLine(ex.GetType().FullName); } }
We get the following printed on the Output window:
NUnit.Framework.AssertionException
So why would somebody ever write a test like the one above, you may ask, right? Well, like I mentioned the other day, I wrote a framework for integration tests that has a bunch of assertions for some things so that the developer doesn’t have to write those over and over again. Even though those things are hidden from the developer, I try to capture as much information as possible, and if any assertion fails, I give all the details to the developer so that he know exactly what failed during the integration.
When running a specific test here, I noticed that I was getting some extra information that shouldn’t really be there, and that was because one assertion was failing and was getting trapped by a try/catch somewhere, and after some digging I actually realized this behavior of assertions throwing "AssertionException"’s.