问题
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