I just stumbled over a situation that made me curious. I spent half an hour to figure out why go test -run testWrittenWithSmallT
is not executing my test. Except that I spelled it with a small t instead of T I noticed that go test
passes if the given test method does not exist.
Little background: Initially I was wondering why my tests are not printing fmt.Println
to stdout
, or at least I thought that was the error. Only after a while I found out that the test is not executed at all.
So I am wondering, is there any reason why that should pass silently?
Examples go
file:
package helloworld
import(
"fmt"
"testing"
)
func testWithSmallT(t *testing.T) {
fmt.Println("test with small t executed")
}
func TestWithCapitalT(t *testing.T) {
fmt.Println("test with capital T executed")
}
Test results:
$go test -run testWithSmallT
PASS
ok starsheriff.net/helloworld 0.004s
$go test -run TestWithCapitalT
test with capital T executed
PASS
ok starsheriff.net/helloworld 0.003s
$go test -run TestDoesNotExist
PASS
ok starsheriff.net/helloworld 0.004s