patterngoCritical
Golang testing: "no test files"
Viewed 0 times
testinggolangtestfiles
Problem
I'm creating a simple test within my package directory called reverseTest.go
whenever i try to run it the output is
this is my go env
Any help will be greatly appreciated. Thanks!!
package main
import "testing"
func TestReverse(t *testing.T) {
cases := []struct {
in, want string
}{
{"Hello, world", "dlrow ,olleH"},
{"Hello, 世界", "界世 ,olleH"},
{"", ""},
}
for _, c := range cases {
got := Reverse(c.in)
if got != c.want {
t.Errorf("Reverse(%q) == %q, want %q", c.in, got, c.want)
}
}
}whenever i try to run it the output is
exampleFolder[no test files]this is my go env
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/juan/go"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
TERM="dumb"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CXX="g++"
CGO_ENABLED="1"Any help will be greatly appreciated. Thanks!!
Solution
Files containing tests should be called
To run the tests recursively call
From How to Write Go Code:
You write a test by creating a file with a name ending in
name_test, with the _test suffix. They should be alongside the code that they are testing. To run the tests recursively call
go test -v ./...From How to Write Go Code:
You write a test by creating a file with a name ending in
_test.go that contains functions named TestXXX with signature func (t *testing.T). The test framework runs each such function; if the function calls a failure function such as t.Error or t.Fail, the test is considered to have failed.Context
Stack Overflow Q#28240489, score: 205
Revisions (0)
No revisions yet.