Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should methods updating database tables be unit tested?

I have an application that is database intensive. Most of the applications methods are updating data in a database. Some calls are wrappers to stored procedures while others perform database updates in-code using 3rd party APIs.

What should I be testing in my unit tests? Should I...

  1. Test that each method completes without throwing an exception -or-
  2. Validate the data in the database after each test to make sure the state of data is as expected

My initial thought is #2 but my concern is that I would be writing a bunch of framework code to go along with my unit tests. I read that you shouldn't write a bunch of framework code for unit testing.

Thoughts?

EDIT: What I mean by framework is writing a ton of other code that serves as a library to the unit testing code...not a third party framework.

like image 366
Jordan Parmer Avatar asked Dec 02 '08 13:12

Jordan Parmer


1 Answers

I do number 2, i.e., test the update by updating a record, and then reading it back out and verifying that the values are the same as the ones you put in. Do both the update and the read in a transaction, and then roll it back, to avoid permanent effect on the database. I don't think of this as testing Framework code, any more than I think of it as testing OS code or networking code... The framework (if you mean a non-application specific Database access layer component) should be tested and validated independently.

like image 176
Charles Bretana Avatar answered Sep 23 '22 03:09

Charles Bretana