Is there any specific naming convention for Test functions of private functions?

My apologies if this is a naive question, but I was unable to find any similar topics here or on StackOverFlow. I am aware that testing public functions are generally recommended, and the test function’s naming convention is TestFoo() where Foo() is the public function.

However, say if I want to test a private function called doStuff(), then which will be the idiomatic way to name the test function for it.

  1. TestDoStuff()
  2. TestdoStuff()
  3. Test_doStuff()
  4. Other (Please mention in reply)


Finally, the convention in Go is to use MixedCaps or mixedCaps rather than underscores to write multiword names.

I would say that from your example the best name will be TestdoStuff, since it’s not exported function. Same you can go with TestDoStuff. But no underscores in names

1 Like

Yes, it seems MixedCaps/PascalCaps would be the most apt approach since with TestdoStuff, the linter goes crazy. I am going with TestDoStuff() and mention the private method testing in comments for better readability.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.