将 MVCContrib.TestHelpers 与 MsTest 结合使用 - 有没有办法获得更好的失败消息?
我刚刚开始使用 MVCContrib,我真的很喜欢它为各种测试场景添加的语法糖。例如,我刚刚写了这样的断言:
"~/".Route().ShouldMapTo<SpotController>(c => c.List());
太棒了!好吧,几乎...
而不是像我希望的那样,查看测试失败的实际原因(我在 MVC 应用程序中没有更改任何内容,因此应该路由到 HomeController.Index()
) 我收到有关测试执行期间引发异常的通用消息。这是我在调试时发现的,因为 MVCContrib 中的测试扩展方法正确地(?)抛出了 AssertionException
。
我假设这是 NUnit 类型的失败异常,而 MsTest 版本是 AssertFailedException 。由于 NUnit 版本(显然)不是从 MsTest 版本继承的,因此 VS 中的测试运行程序不会捕获异常并给我一个很好的消息。
有没有办法让 MsTest 以与 AssertFailedExceptions 类似的方式处理 AssertionExceptions,而不必重写 MVCContrib.TestHelpers 的一半?
我确实在本地工作副本中有源代码,所以我可以进去并重写测试方法以抛出 MsTest 异常,但这似乎太过分了......
更新:
大多数模拟框架也会出现此问题,因此现在我不仅想使用 NUnit 中的 AssertionException
来执行此操作,还想使用 Moq 中的 VerificationException
以及其他可能的框架来执行此操作……难道就不可能吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论