Using MVCContrib.TestHelpers with MsTest - is there any way to get nicer fail messages?

假装没事ソ 提交于 2019-12-13 16:13:24

问题


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?

来源:https://stackoverflow.com/questions/3269151/using-mvccontrib-testhelpers-with-mstest-is-there-any-way-to-get-nicer-fail-me

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!