Here is a very basic example to illustrate my point
class SomeClass {
publicMethod1(param1, param2) {
if (param1 === "some value") {
// do stuff
} else {
// do stuff
}
this.privateMethod(true);
}
publicMethod2(param1, param2, param3, param4) {
if (param3) {
// do stuff
} else {
// do stuff
}
this.privateMethod(false);
}
privateMethod(param) {
// do stuff
let obj = database.getObject(param); // call to database
if (obj.property === "random") {
// do stuff
} else {
// do stuff
}
}
}
I've done a bit of research into this topic but didn't find any people asking the exact question I'm asking. I think I'm clear that I should only be unit testing my public methods and not private ones. But I'm just wondering how I should be testing my public methods that make calls to private methods that are within the same class.
Should I simply be testing to make sure that private method was called? Or should I be delving into the logic of the private method to make sure I test every possible route of execution. And if it's a "yes" to the latter, I was wondering if it is common to reuse unit tests when dealing with private methods that are called multiple times (like in the example above).
EDIT: The answers to this question that everybody keeps linking seem to be solely geared around the question should I unit test my private methods? and what I'm asking is how exactly do I unit test my public methods that call private methods within the same class?