I'm creating a simple test within my package directory called reverseTest.go
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!!
Files containing tests should be called 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 namedTestXXX
with signaturefunc (t *testing.T)
. The test framework runs each such function; if the function calls a failure function such ast.Error
ort.Fail
, the test is considered to have failed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With