Customize failure handling in FluentAssertions

落爺英雄遲暮 提交于 2021-01-28 04:51:23

问题


I'm trying to use FluentAssertions not only as testing assertions framework but also to check runtime contracts (like advanced Debug.Assert, and I have read this question). The desired behaviour is:

  • In debug mode: throw exceptions (it does).
  • In release mode: do not stop method execution (no exception is thrown) but execute custom action (write to log).

Is there a way to customize failure handling behaviour? There is IAssertionStrategy interface which is exactly about failure handling. However, it's implementations are hard-coded inside the AssertionScope. Did I miss something in the sources?


回答1:


You can set FluentAssertions.Common.Services.ThrowException to override the behavior. Note though it was never designed for that.



来源:https://stackoverflow.com/questions/50760245/customize-failure-handling-in-fluentassertions

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