Private methods, when used meaningfully, are a great tool for writing beautiful object oriented code. But as many other things in life, excess of private methods is bad, too!
In my opinion, we use private methods to:
1. isolate a block of code to be reused inside the class.
2. extract code from another method for code readability.
Now, taking these two use cases in mind, here’s an easy conclusion:
ActionInvoker.java
You will see there are public methods with 100+ lines. I hope you agree with me:
Disclaimer: I like the play! framework a lot. However, if you take a look at their code and if you think unit testing is important, you’ll see they have a lot of rooms for improvement with simple extract method refactoring.
In my opinion, we use private methods to:
1. isolate a block of code to be reused inside the class.
2. extract code from another method for code readability.
Now, taking these two use cases in mind, here’s an easy conclusion:
The lower the ratio of public to private methods, the harder it is to write unit tests since the “units” are potentially larger.I don’t know if there is any rule of thumb, but you will smell it when you see your unit tests require a lot of setup and assertions. Here’s a code example from the Play! framework, an MVC franework for Java developers.
ActionInvoker.java
You will see there are public methods with 100+ lines. I hope you agree with me:
“The ActionInvoker.java code is not readable”For the sake of readability, introducing private methods with good names would help. However, that doesn’t eliminate any of the possible code paths from the public methods. So, if you are lucky, you will see really long unit tests with complex setup conditions and mock expectations. Otherwise, there will be no tests at all! Without any tests for such long and complex methods, use them at your own risk. I won’t :(
Disclaimer: I like the play! framework a lot. However, if you take a look at their code and if you think unit testing is important, you’ll see they have a lot of rooms for improvement with simple extract method refactoring.
What I see from just a little code snippet here is basically you are creating a wrapper/facade for the library, or a delegate or even an anti-corruption layer kinda something. And your wrapper object is basically created in such a way that it looks like a Humble Object (http://xunitpatterns.com/Humble%20Object.html). Therefore I'd go for integration test. If the team you are working on is a distributed team, then you might have some trust and/or communication issues, therefore writing an additional unit test wouldn't hurt. Then again that's not necessary.
Main thing here is to understand that TDD won't tell you that you have write unit tests all the time. What TDD say is have a coverage before you operate, and drive your design with this mentality. One thing I like in Ruby community is that they do focus on Specs rather than focusing on unit/integration/functional tests differences. A tool like RSpec or Cucumber is even designed in such a way that they give you tagging support which you can easily mark your test with #requiresDB, #requiresFileAccess, #opensBrowser, etc.. And then you can create multiple builds by using these tags to have prioritized test suites.
Second question is probably an obvious one. If I were to re-write using TDD, I'd probably end up having an anti-corruption layer to the library which is designed 1:1 from the actual library, hence not need to be unit tested.