jeudi 20 août 2015

How to write unit tests for queries on complex existing database

I am taking over a (very) large existing web application with a very large and complex database. This is a very old application and has 0 unit tests. I have to do some refactoring and obviously want to be sure not to break anything and am thus setting up unit tests for the code I refactor.

The refactoring I'm currently doing involves querying the database with several joins and subqueries with all kinds of constraints. I'm not sure about the most practical way to test these methods. I'm a bit worried about starting to compose my own fixtures for all kind of datasets and keeping these up to date. I don't want to spend more time faking my data than writing code and tests. Is it viable to just run the tests against my regular database and setup a few queries at the start and end of a test case that manipulates the data the way I want it? Or am I going down a dangerous path with this?

I think I probably already know your answers :) but thanks for your thoughts on this.

Aucun commentaire:

Enregistrer un commentaire