I'm writing unit tests for the implementation of an API I wrote myself in my company's application. Still new to this whole thing. When looking for answeres on how to unit test certain things I come across a certain pattern. It goes something like this:
Question:
I have this private method I need to unit test.
Top voted answer:
Don't.
I also came across this article arguing against unit testing private methods as well.
Basically how I'm implementing an API I'm given is I write the code first, then I write unit tests to "break it the worst way possible" (as my superior puts it). Once I notice something broke I fix it in the code. To me this seems like a mash-up of OOD and TDD. Is that a legit approach?
The reason I got so many private
methods in the first place is that I'm required to break up larger chunks of code into methods. Since these methods are only supposed to be used within the scope of this API implementation I set them to private
. Since the file structure established by my team requires me to write all the code into a single file corresponding to an API I can't separate these private
methods into a new class and set them to public
.
My superior expects me to test these private
methods as well. But I'm beginning to doubt if this is even really necessary if the Assert
s on the public
methods all run successfully?
From my point of view, if my tests on the public
methods return the values I expected, I infer that my private
methods also work like I intended.
Or am I missing something?