Gotta Test

time to read 3 min | 442 words

This has been a strange day, I didn't get much work done, and I was continiously interuptted throughout the day. Nevertheless, I managed to read all the new posts and do some work on NQA. I think that TechEd is driving the bloshpere crazy, I never seen so many posts in so short a time.

Anyway, I did some refactoring of NQA today. The change should have been simple, RenameClass and ExtractInterface. I'd a class named AppDataManager, which was the BossClass in the old incarnation of NQA, and still had quite a lot to say about itself this day (for instance, it persisted itself to the database for no good reason, etc).

I trimmed it a little bit and renamed it ProjectsRepository (yes, I read DDD :-) ). Pulling out some more nastiness resulted in some cleaning up of both the code and the tests. I still don't have nearly enough test coverage to feel comportable, though.

One thing that Roy mentioned in his recent podcast was that each test should take at most 0.01 second to run, since you're going to be running hundreds / thousands of them and doing so frequently. One of the things that he mentioned was that tests should execute in memeory only, and shouldn't touch HD or DB. I'd several tests that used a test database to run, but refactoring brought it down to two test fixtures which calls the database (the test fixture for the database creation and the test fixture for the ProjectsRepository). I wonder if I should create an integration tests assembly and move them there.

I've stragled long and hard with tests performance, and currently I've the ProjectRepository tests taking 6 seconds 4 seconds to run, 30% of which is dedicated to creating an AppDomain. about half of which in taken by database access. The second long test is a 3 seconds test that test an object that encapsulate access to an object in another AppDomain. This requires creating an AppDomain, which is damn expensive in terms of time.

I currently don't see a big solution there outside of declaring these as integration tests. The database creation tests are certainly so, and perhpas the proxy object as well, but I can't help feeling that the repository tests are unit tests, even though they touch the database and even though they take too long. I think that I need to think about splitting the tests, but I've no experiance in doing so.

As usual, comments are welcome.