Timeline for How to unit test private method that is used by several public methods without duping the tests
Current License: CC BY-SA 4.0
12 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jan 10 at 21:20 | comment | added | candied_orange | @DavidMason I will concede one thing though. When we create private functions it can be very useful to write tests against them to ensure we're getting what we expected. The problem is that very test cripples our refactoring. So while I still write such tests I never publish them. That test needs to die when the private method changes. Publish it and it will lock us down to a particular implementation. No, I don't trust people to let go of the test when it's time. So I just never check in such tests. | |
| Jan 10 at 21:10 | comment | added | candied_orange | @DavidMason The adapter fixes the "not the same API". But different behavior severally limits the reusability of the tests. Look, if I have two functions that calculate distance, one that takes Cartesian cords and one that takes radial cords and they both happen to use the ABS function. This does not let us off the hook if the ABS function has been tested. We need tests on both distance functions that prove that they work regardless of if they actually use ABS. So sorry. There's just no getting out of this. Good testing is against the used interface. Not every little thing you find inside. | |
| Jan 10 at 21:03 | comment | added | David Mason | It's just that testing the public behavior of both methods is much work. But the biggest part of this work is the part that covers the private method. And those parts (>15 tests) need to be duplicated now because both public methods make use of them... | |
| Jan 10 at 21:00 | comment | added | David Mason | No, they have not the same API and they also have a different behavior (however it's connected) | |
| Jan 10 at 17:56 | history | edited | candied_orange | CC BY-SA 4.0 | added 339 characters in body |
| Jan 10 at 16:15 | history | edited | candied_orange | CC BY-SA 4.0 | added 1 character in body |
| Jan 10 at 16:07 | history | edited | candied_orange | CC BY-SA 4.0 | added 1 character in body |
| Jan 10 at 15:59 | history | edited | candied_orange | CC BY-SA 4.0 | added 520 characters in body |
| Jan 10 at 14:19 | history | edited | candied_orange | CC BY-SA 4.0 | added 85 characters in body |
| Jan 10 at 14:12 | history | edited | candied_orange | CC BY-SA 4.0 | added 76 characters in body |
| Jan 10 at 14:06 | history | edited | candied_orange | CC BY-SA 4.0 | added 76 characters in body |
| Jan 10 at 13:06 | history | answered | candied_orange | CC BY-SA 4.0 |