Go test results in: "testing: warning: no tests to run"

What have I done wrong? I’m still learning and trying to figure out testing, but clearly I have something wrong and can’t figure it out, despite lots of searching. What am I missing? Thanks in advance!!

mainFile.go is:

package main

func fourPlusFour() (r int) {
   return 4 + 4
}

mainFile_test.go is:

package main

import "testing"

func testfourPlusFour(t *testing.T) {
	if fourPlusFour() != 7 {
		t.Error("You Failed")
	}
}

terminal command is: ~/go/src/user/testingTest$ go test
Output to terminal is:

testing: warning: no tests to run
PASS
ok      user/testingTest        0.002s

go env output:

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/user1/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/user1/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build486771635=/tmp/go-build -gno-record-gcc-switches"
1 Like

change the name of the packages, mytest or whatever name both files and execute again

Not sure I understand:

I changed the package name to mytest in both files, but no change in the output of go test

put yours methods in capital letter TestFourPlusFour()

1 Like

So I didn’t realize it, but specifically the test functions need to be capitalized. I’m guessing this has something to do with exported functions? Non-testing functions should determine First letter capitalization based on whether they should be exported right?

Yep :+1:

https://golang.org/pkg/testing/

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