Let’s suppose there is an utility class (no data) with one complex (as in, hard-to-test) public method. It uses random number generation, return large arrays of data and that fun stuff. However, if you implement it in small private methods, every private method would be easy to test, and thus the whole thing would be easier to test. From the application point of view, only the big method needs to be public, and the other should be private. Yet, testing the private methods results in an easier to test class. How should I approach this problem?
Share
Whether you should leave your method as a single blackbox algorithm whose subparts aren’t testable, or try to externalize as many responsibilities as possible to separate classes, is very situational.
You might have subparts that are likely to be reused, in which case it’s a good idea to factor them out. You might have subparts that talk to other layers or to the hardware – same thing.
It all depends on what these small sub methods do, it’s hard to tell without a context.