Dashboard > ActiveRecord > ... > Documentation > Best practices
Best practices
Added by Daniel Rothmaler, last edited by Daniel Rothmaler on Aug 20, 2007  (view change)
Labels: 
(None)


After eating our own dog food for a while, we think we might have some valuable tips for people who want to try ActiveRecord.

Test cases

Have test cases for your object model

So when you change something on your model, you can easily check if something breaks.

Test interactions

The interactions among objects are especially important. When they are meaningfull, create special methods for them that assert some conditions.

For example, with a Pool and Vote classes, the Pool might expose a RegisterVote method.

Code a little, test a little

Prefer small steps instead of creating a whole object model assuming that it's right and working. Growing the object model in small steps, while coding test cases for it, allows you to quickly identify something that went wrong.

Testing a complex object model

As the application grows big, you might end up with a complex object model with lots of interconnections. So testing become a complex issue, for example, imagine that you want to test an Order class, but to test it you must create a Product, and a Supplier and an Consumer.

We recommend using ObjectMother pattern for such cases.

See also

Approaches to unit testing

Site running on a free Atlassian Confluence Community License granted to Castle Project. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.4 Build:#809 Jun 12, 2007) - Bug/feature request - Contact Administrators