After a hard day at work my mind was in no state to churn out quality code on open source. But really wanted to get something done about rapa. So thought it might be a good idea to integrate some metrics into the build and see what they had to say.
Misko has created this really cool tool called Testability Explorer. It tells you how testable your classes are. But why do we need such a tool?
Rapa was mainly designed and developed the TDD way. There is always more to learn and improve in the code. Certain parts of Rapa became increasingly difficult to develop the TDD way. We also need a tool that can Flag some basic testability issues.
Lets start with some basic testability issues that we all may have faced at some point in time.
A very common issue most people new to TDD and mocks face is the mocks returning mocks. Below is an example.
MethodExecutor executor = new MethodExecutor(mockMethodProvider);
In the first line we are setting an expectation on mockMethodProvider to return a mockMethod. The mockMethodProvider is injected into the methodExecutor. Then we call execute on executor. In the last line we are verifying that execute was called on the mockMethod by the executor.
If we look at this code closely we can observe that MethodExecutor is being injected with mockMethodProvider when all it needs is the mockMethod.
It is a simple design issue. You can find this and many more examples of such common issues with testability in Misko’s blog.
Rapa and Testability Explorer
Integrating testability explorer itself into the build is an easy process. I used the instructions in this link.
Below is the report.
Looks like the code is not too bad. :)