2

I'm just starting to use MVCContrib, and I'm really liking the syntactic sugar it adds to various test scenarious. For example, I just wrote this assertion:

"~/".Route().ShouldMapTo<SpotController>(c => c.List());

It's brilliant! Well, almost...

Instead of, as I'd like, seeing the actual reason why the test fails (I've changed nothing in my MVC application, so that should route to HomeController.Index()) I get the generic message about an exception being thrown during test execution. This is, I find when I debug, because the test extension method in MVCContrib correctly (?) throws an AssertionException.

I assume this is the NUnit type of failure exception, while the MsTest version is AssertFailedException. Since the NUnit version (obviously) does not inherit from the MsTest version, the test runner in VS doesn't catch the exception and give me a nice message.

Is there any way to get MsTest to treat AssertionExceptions in a similar manner as AssertFailedExceptions, without having to re-write half of MVCContrib.TestHelpers?

I do have the source code in a local working copy, so I could go in and re-write the test methods there to throw MsTest exceptions instead, but it seems like extreme overkill...

Update:
This problem appears with most mocking frameworks too, so now I don't only want to do this with the AssertionException from NUnit, but also with VerificationException from Moq, and possibly others... Is it just not possible?

Tomas Aschan
  • 58,548
  • 56
  • 243
  • 402
  • If you were using xUnit.net, you could easily write a custom runner that does the translation (sorry!) – Ruben Bartelink Jul 22 '10 at 07:46
  • @Ruben: This is more and more making me progress to switching to NUnit, actually, since I can't seem to find any good way to see the exception messages first. But it would still be nice to know. – Tomas Aschan Jul 22 '10 at 09:22
  • I agree its a good question (the +1 on it is mine). I personally would skip NUnit and go to xunit.net is what I'm saying - it has a way better extensibility story than NUnit and that matters when you're backed into a corner by issues like this. It's codebase is really Clean and will remain so because it has two opnionated committers with taste and a strong awareness of the need to and proven record of rejecting junk and duplication. NUnit's runner codebase is far from clean. Just my opinion though! – Ruben Bartelink Jul 22 '10 at 13:18
  • @Ruben: Is the xUnit framework extensible enough for me to use some assemblies that test with NUnit, and other that test with xUnit, and then run all of it in TD.NET and get nice errors? – Tomas Aschan Jul 23 '10 at 18:02
  • TD.NET will handle mixes of all types happily - it's hard to find a hole in what *it* can do. However for your sanity, you want as few test runners (and the versioning of them) as possible in your build process. (So when I was faced with 500 MSTest tests and 30 NUnit tests, I ported them to 530 xUnit Facts - this was an easy port using CodeRush and I dont regret it for a second) – Ruben Bartelink Jul 26 '10 at 12:25
  • xUnit.net recently deprecated the ability to use the xUnit runner to run a mix of xUnit Facts and NUnit Tests as a single atomic run. I think this is bad news anyway (in addition to not being what you asked for!). This allows one to replace all occurrences [TestClass] with [RunWithNUnit] and then just use the xunit runner on the assemblies (you have NUnit assemblies in your process, but its not the primary runner). This sort of trickery is no problem with xUnit if you end up in this sort of a corner. The question is whether it's a good idea if it can be avoided. – Ruben Bartelink Jul 26 '10 at 12:27
  • My original point was really that if I was going to there, I wouldnt start from here - I'd move to xUnit first, safe in the knowledge that I cant be painted into a corner as easily as one can be with MSTest (and IMO NUnit - though it's orders of magnitude better than MSTest from that perspective). IOW, I'd rate MSTest 2, NUnit 6 and xUnit 9 on enabling this sort of thing. – Ruben Bartelink Jul 26 '10 at 12:30
  • I'll stop typing generalities now and you can ask specific questions now! – Ruben Bartelink Jul 26 '10 at 12:31

0 Answers0