I’ve written a 220 line class with 5 public methods. I have a unit testing class that runs 28 tests on this class which takes up over 1200 lines of code, but this is mostly due to repeated code used in setting the tests up. This code is testing the DAL in my project to ensure it interacts with the database correctly and that the stored procedures involved are running correctly. It seems like I have done a lot of work to test very little code. I am using mocks with Rhino mocks to avoid writing my own stubs where possible.
Is this typical unit testing experience?
It is fairly common that unit test classes contain more LOC than actual tested classes. That’s reasonable considering setting up dependencies, preparing faked data and all the unit testing related fuss.
However, testing DAL in terms of interacting with database and checking if correct procedures are invoked smells like an integration test. You might want to rethink what you want to do. With unit testing, all the DB-talking should be mocked/stubbed.
If you’re having issues with 1200 lines of code, you can break up your tests into contexts, eg. every context matching particular part of tested class (public method, set of properties and so on).
Edit:
Just to add example that other’s do that aswell. You can check sources of
AggregateandAggregateTestsclasses from Edulinq project. 15 tests to test 3 public methods, with tests class being twice as big as tested one.