Reputation: 329
I have the rails application and i use postgresql for database. I use trigger functions to make some changes in the database while there is changes happens in the application data. But i dont have a good idea on how to test the trigger functions with test cases...
Upvotes: 1
Views: 2208
Reputation: 78543
I'm in a similar boat on my end. I ended up writing unit tests that involved direct database insert/update/delete statements, and direct select statements to validate the changes.
As a tip, consider writing a few tests that manipulate multiple rows as once, and which verify that the number of affected rows returned is valid. In my experience the latter have a knack for revealing shortcomings (crashes, race conditions, etc.) when things are complex.
Upvotes: 1
Reputation: 12998
Why not simply do the same operation you do in the production application?
E.g. if your trigger incements a column value on an insert and update, just write a test for these events and test if the value was incremented correctly by retrieving it and checking it. So if a column value is "3" before the insert operation and "4" afterwards, you know that the trigger was fired correctly.
Upvotes: 0