I'm used to an approach in unit testing to cover each method with a separate unit test. Including private methods by marking them as internal virtual (C#) and creating a separate unit test for them. Recently I can't find a single person who supports this approach in my company - the preferred way is to write a single unit test for a public method, even if it contains calls to another private method(s), in which case all dependencies in those private methods must be mocked as well. I'll give a simple example on top of my head:
public async Task DoSomeWorkAsync()
{
await repo.SaveStateAsync();
await DoSomeAdditionalWorkAsync();
Console.WriteLine("Done");
}
private async Task DoSomeAdditionalWorkAsync()
{
await repo.GetDataAsync();
await repo.GetAnotherDataSetAsync();
}
In an example above my colleagues say it's right way to go is to set up stubs for all 3 methods being called (SaveState, GetData, GetAnotherData) so single unit test will execute both public and private methods and check both. The way I'm used to do it is to declare method as internal virtual, so method would become visible to an assembly with tests, and writing a separate test for DoSomeAdditionalWorkAsync method first and then using partial mock to mock DoSomeAdditionalWorkAsync method when writing another unit test for DoSomeWorkAsync method.
I heard the argument that if private method is used only in one place and was created for code readability reason then it's fine to have a single unit test. But in that case there's a risk for next developer to re-use private method with assertion it's already covered in a separate test. Does the answer depend on complexity of a private method itself? (the bigger private method, more reasons to add unit test for it)
Am I in the wrong here? Should I stick to my colleagues' recommendations? I tried to search for this topic but not sure what keywords to look for here. What are best practices/recommendations for such a simple scenario?
Thanks in advance for any kind of opinion or advice.