2007-11-15

On unit testing: separate logic from storage

Reminder to all: split logic from your storage mechanism. We decided it would be important to write tests around a function in `ftolib` I did some refactoring on. It would be a pity if that accidentally changed the outcome too. Of course I should have used tests while refactoring. But we didn't have any. So I set up a nice environment using Pyunit (import unittest). Then had some example tests running. When I started a test for my function, I found out it was virtually impossible to harness it with tests: the function calculates frequencies of specific medication per prescriber AND stores the results in the DB. Logic and storage in 1 big function. Not very nice.