I've been using FluentAssertions for unit testing and was wondering why it's only ever mentioned in that context. If you generally write fail-fast production code with guards you would have to duplicate some of the functionality FluentAssertions already provides. Some of the reasons I can think of to not use it:
- Its focus is to be readable, not to perform well. Counter: isn't that what higher-level languages also do and related to the warning to not do premature optimization?
- Also related to performance, there is no good way to have some assertions not run when code is compiled in release mode. Counter: You may remove an assertion you think won't happen in production but leads to an exception that is hard to track down. As long as they're not affecting performance significantly, leave it.
- Its assertions don't always throw standard exceptions. For example,
ArgumentNullException
andArgumentException
are ubiquitous and expected, but FluentAssertions doesn't know you're testing an argument and throws a generic exception.
Maybe it's already known performance is significantly impacted so #1 and #2 are legitimate, but you would generally also want fast unit tests so the same logic could apply there. Any other good reasons not to use FluentAssertions in production code?