Hi,
I am using Windows and I did a mistake regarding capital case for package name, like below.
It is: %GOPATH%\src\WrongCapitalCase
But it should be: %GOPATH%\src\wrongCapitalCase
Please note that word wrong
should be all lower case, but I put it as Wrong
with first letter as upper case by mistake.
When I run tool go test -cover
it work, I mean, it build and run, but coverage is 0%
.
If I fix the package name (rename directory or change file package instruction) it works fine, it shows the correct coverage.
I know the problem is the wrong package name between files and directory, but my point is why build
and run
works and cover
doesn’t?
File: main.go
package wrongCapitalCase
import "fmt"
// DoSomething :
func DoSomething() {
fmt.Println("init")
}
File: main_test.go
package wrongCapitalCase_test
import "testing"
import "wrongCapitalCase"
func Test1(t *testing.T) {
wrongCapitalCase.DoSomething()
}
Output:
Running tool: C:\Go\bin\go.exe test -v -race -cover -coverprofile=cover.out -timeout 30s -tags
=== RUN Test1
init
--- PASS: Test1 (0.00s)
PASS
coverage: 0.0% of statements
ok WrongCapitalCase 1.364s
Success: Tests passed.