测试Go中未导出函数的命名约定

I can't trace where I know it from, but normally if one writes a test for method Foo, the corresponding test is named TestFoo.

If one tests an unexported function, say foo, what the name of the test should be then?

My question comes from the fact, that JetBrains IDE for Go, when asked to generate a test for an unexported function, generates something like Test_foo.

This behavior may have sense, because if you have Foo and it's unexported counterpat foo in the same package, you'd want to distinct tests for them somehow (at least for jump to test feature in IDE).

So is there any convention on naming tests after unexported functions?

BTW: documentation for the Go testing package says, that a test is executed if it is:

any function of the form

func TestXxx(*testing.T)

where Xxx can be any alphanumeric string (but the first letter must not be in [a-z]) and serves to identify the test routine.

Which means, that any test having underscore in its name shouldn't be executed by go test. However, we all know, that such tests work just fine.

My initial confusion with this originated from 2 things:

1) an assumption, that underscore is allowed in test funciton name. This assumption was backed by tons of major opensource projects that do this

2) the fact, that JetBrains Idea generates tests with names containing underscores

The response to my own question: there is a convention (I'd rather say, it's a guideline from Google), which many projects violate. Underscore should not be used in a test name.

I've voted for closing my own question and created a bug-report in JetBrains bugtracker. https://youtrack.jetbrains.com/issue/GO-5185