Timeline for How to unit test a public method that calls a private method
Current License: CC BY-SA 4.0
3 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Dec 15, 2020 at 20:44 | comment | added | Simon B | @Jacob If you need 100% code coverage (and most people don't bother unless it's safety-critical software), you should still be able to achieve that through calls to the public function. If you can't, then the private function must have redundant code that can't be called from anywhere. But with TDD, the aim is usually just to write the code that passes the tests. How it passes the tests isn't normally an issue. | |
Dec 15, 2020 at 18:42 | comment | added | Jacob | Yes you are right Simon, I got it loud and clear that I should not be directly testing my private methods... but what should I do in the case I laid out above, where a public method calls a private method? Whenever I call the public method to test it, should I be concerned about getting 100% code coverage within all the different routes of execution in the private method, or not? | |
Dec 15, 2020 at 11:21 | history | answered | Simon B | CC BY-SA 4.0 |