Integration testing

September 26, 2008

I recently started using the PHP continous integration tool phpUnderControl in some of the projects I’m currently working on. A little before that, I started writing integration tests.

I have to admit, I really had to convince myself to start writing tests because a lot of people writing tests sometimes make me feel a bit awkward. I don’t feel very comfortable with those kind of people. They give me the impression they always have everything under control, that everything is “all good“. Fact is, I’m trying hard to keep these guys out of my friendzone. Either way, they scare the girls, and boys shouldn’t do that.

Anyway, since I have a girlfriend, I thought what the fuck, so I started Unit Testing (how about my reason to start unit testing?)

Sebastian BergmannIt seemed I had the choice between SimpleTest and PHPUnit but since Germany always wins, I chose Sebastian Bergmann’s framework. Luckily, Seba developed a framework using his immense forehead resulting in a easy-to-use yet powerful development tool. I installed everything in a jiffy and started out with the PHPUnit Pocket Guide.

The cool thing is that you can use you terminal (Linux) or command prompt (Windows) and look like a real professional when your boss passes by. Since I wanted to test my projects models, I started using the database testing tools available by the framework. The models I use for the project aren’t really complex, hence my choice of writing integration tests. I setup a small XML datasetfile used in my setUp-blocks to run the tests against.

Now, during my intensive period (2 weeks) of using Tests, I already came across some problems concerning integration testing. The problem is that you want to test your code against a certain dataset (setup in XML) that gets loaded into a test-database by the framework. I wrote about 100 tests and since my XML dataset kinda grows like hell, It now takes about 1 second/test. I started drinking a lot (of water) these last days and I managed to start taking 100-second pisses every 45 minutes. The problem is that I want to run these tests more frequently thus faster.

I read some things about mocking objects, but I haven’t figured out whether one can use that with database objects. (say an instance of Zend_Db)

If anyone knows how to handle this kind of problem, feel free to let me know. You don’t have to come by, just write a comment or a postcard…