wood burning stoves 2.0*
The moose likes Ruby and the fly likes Rails antipattern : testing the validation rules ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Ruby
Bookmark "Rails antipattern : testing the validation rules ?" Watch "Rails antipattern : testing the validation rules ?" New topic
Author

Rails antipattern : testing the validation rules ?

Thomas Queste
Greenhorn

Joined: Mar 08, 2006
Posts: 15
Hi,

I wonder what do you think about testing the validation rules ?

I have written code against simple rules, as validate_presence and so on.
Today, I don't do it anymore, because the "Return on investment" is not relevant for this test code.

(Exception to the rules : I do test my validation methods if they are complexe, like regex)

What do you think : is testing validation rules an anti-pattern ?

Thanks,
Tom
Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1357
    
  17
I don't know if it's an anti-pattern per se, but it's certainly a waste of time to test the framework -- there's other code testing that those validations work.

The exception would be if you're test driving the behavior of that code, at which point you're not testing validations you're specifying behavior.
Thin line, I guess :)
Tammer Saleh
author
Greenhorn

Joined: Mar 02, 2011
Posts: 11

That's a fairly well contested question, but I fall on the TDD line: I work best when I write tests before each line of code. Basically, it's more about tempo than knowing that I've got 100% test coverage.

So, with that philosophy, I end up writing tests for everything, including the fact that a validation was setup.
Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1357
    
  17
I generally fall on the TDD side as well; my colleagues don't. That way we're certain to have covered all possible exits :)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Rails antipattern : testing the validation rules ?
 
Similar Threads
how to "simulate" HTTP server
Testing private members
What Is Unit Testing -- and what it is NOT.
Testing Active Vs Passive or Explicit vs Implicit
test first