Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

New Post: Testing validators

$
0
0
Thanks for the suggestion.

Personally, I'm not keen on this approach so I don't have any plans on implementing it - this is really testing the internal implementation of the validator which I'd tend to avoid as it leads to brittle tests. I find it better to simply test given a particular input, is the validator valid or not as this makes the tests far less brittle. In this situation, I'd have tests for the following tests:
  • Name contains numbers -> not valid
  • Name is 100 characters -> not valid
  • Name greater than 100 characters -> not valid
  • Name shorter than 100 characters -> valid
  • Name doesn't contain numbers -> valid
    (you could even go further, and have combinations of the above)
These tests cover the business rules, but aren't tied to which rule is being invoked. This way, you can choose to re-write how the rules are impelmented/executed (eg through RuleFor, Custom, a custom property validator etc etc) without the tests needing to change.

Viewing all articles
Browse latest Browse all 1917


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>