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.
Aucun commentaire:
Enregistrer un commentaire