Fearless F. wrote:
Marnen Laibow-Koser wrote:
[snip]
Sent from my iPhone
Â
Wow - that’s some agile thumbs you’ve got there.
I take the “agile” part of my job seriously. 
Â
Yes, I could create mock classesÂ
No one is talking about mock objects, exactly. Â The objects you’d be
creating with factories would be real AR objects, with real DB records
behind them. Â There just wouldn’t be 85,000 of them.Â
Think about it: no test case is going to touch more than about 5 records
maximum. Â You’re just not creating the 84,995 you won’t use.Â
that fake the data for exactly theÂ
items I need. Â But:
Â
Since I already have the static tables (and have tested them), wouldn’tÂ
that be analogous to writing a Math::sin(x) function that is definedÂ
only for specific values of x?
Sort of. Â And that’s a good testing practice: Math::sin is already well
tested, so you don’t need to test it further. Â So don’t incur the
overhead of calling it.Â
Now, for a cheap function like sin, the difference in performance is
trivial. Â For 84,995 unnecessary records, the difference is not
trivial.Â
Â
To extend the analogy, Math::sin(x) is not part of the business logic ofÂ
my app, and I should not be testing it any more than I should be testingÂ
whether or not :belongs_to generates the correct methods inÂ
ActiveRecord.
Correct. Â So don’t bother calling it in your tests – or in the analogy,
don’t bother testing your already tested gargantuan constant table.Â
Â
In these circumstances, I’d maintain that I’m MORE likely to introduceÂ
errors in my tests by writing mock classes when stable, proven dataÂ
already exists.
You’re not writing mocks. Â And you’ll be less likely to introduce
errors, because you know that your specially crafted test data has
exactly the properties that your tests need it to.Â
With crafted test data, you’re testing your application.Â
With your whole constant table, you’re testing your constant table –
which you say you’ve already tested – not your app code, and you’re
working harder to do it. Â There’s no advantage to this approach, and
several disadvantages. Â Don’t do it.Â
Can’t you just be happy that I’m not using fixtures now? Â 
But you are using fixtures. Â You may not be using the Rails fixtures
mechanism, but you’re still using brittle, permanent test fixtures
instead of the flexible crafted test data you should be using. Â This is
a terrible idea. Â There is not a single reason to do it that way. Â Do
not do it.Â
Â
Best,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
Sent from my iPhone