Rhino Mocks reach 100% testability
I took a bit of time to work on Rhino Mocks today, mainly cleaning up some stuff and rearranging things. It occur to me that after getting so excited about Rhino's tests earlier today, I might check the code coverage reports*.
The first report that I got was quite disappointing, I had only 57% coverage. I had such high hope and they were thoroughfully dahsed. Then I remembered that I used CodeSmith to generate custom collections for Rhino. NCover doesn't allow you to exclude namespaces, which made it impossible to see the code coverage excluding this annoying code generated files. I wrote quick & dirty script in Boo that cleaned the report from those annoying classes and then I run the reports again.
I fell of my chair. I had 93%! Just to put these things in order, I currenly have about 40% coverage for NQA**. There are three reasons for using code coverage:
- Your ego needs a boost :-)
- You want to track TDD's usage in your code, if you suddenly see the precentage dives, you know that you need to find the responsible party and commence in re-educating them.
- You want to check for possible dead code / dead code paths.
The first thing that I noticed when doing this is that I actually had two custom collection classes that I actually weren't using, there went 3,500 LoC that I don't want to see again. Then i gotten into the code and found some surprising results, I'd places where there was code rotting. It was mainly a case where I was handling certain condition via a higher level method while the lower level methods were prepared to handle it themself (which of course never happened). I filled all the missing remaining holes (error handling in contraints was a big thing that I mostly missed) and then I took the time to look at the rest of the collection classes.
They were huge classes that were quite capable, but I only used one or two methods of the doezens that they had. Considerring that, I chopped them off and built my own strongly typed wrappers around Hashtable and ArrayList reducing the total lines of code by another ~5,500(!) LoC. This also means that I now have 100% test coverage over my entire codebase.
So there is another release, 2.3.4, which is smaller by 50Kb than the previous one, with no loss of functionality or changing the API. One bug fix that I made was to throw an exception if you pass a null as a parameter for Constraints(), which is something that I ignored previously.
*I'm using NCover, it's good and unintrusive, but it can be a pain to setup for the first time.
** Of course, now I'll get comments saying that it's 93% that is low.
Comments
Comment preview