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

New Post: Using NSubstitute is it possible to verify which ruleset was used to validate an object?

$
0
0
I would say that a lot of it depends on finding a balance that you're happy with. When I first started out with TDD, I went very over-board with testing the interactions - I had very high code-coverage but my tests were very brittle, and would break as soon as there was any refactoring.

These days, I tend to write unit tests for critical or complex logic (business processes, validation rules etc) but I don't tend to write unit tests for controller layer - my controller layer is very thin and any issues would quickly be made visible via UI testing. But this is just my personal preference, and also varies from project-to-project. I've found that by having a very thin controller layer, the need to explicitly write tests for it becomes very minimal. If you are going to test the controller layer, then I would have tests that perhaps do the following (just an example):
  • When a controller action is passed a valid model instance, the user is redirected to a success page
  • When a controller action is passed an invalid model instance, the page is re-rendered and there are errors in the model-state (if you're using MVC for example)
    I personally don't tend to go any deeper than that. In your particular case, if you're finding that you're frequently forgetting to change the name of the ruleset, then I'd look at finding a way of using conventions to automatically work out the correct ruleset name (maybe based on the name of the controller action or something) rather than hard-coding it. This way your infrastructure is taking care of the problem.
I'd say go as deep as it makes sense to do so for your particular project - only you can know how much value will be derived from doing this sort of testing. At the end of the day, as developers we have to provide value for the business - if all of our time is being spent re-writing tests because they're brittle then this isn't a good use of the business's money, or our time.

All the best with the project, I hope you find a comfortable balance with the testing.

Jeremy

Viewing all articles
Browse latest Browse all 1917

Trending Articles



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