I have a go project, test directory contains a single sample test file. Few Functions of the test file are
func TestMain(m *testing.M) {
setup()
code := m.Run()
shutdown()
os.Exit(code)
}
func TestUserLogin(t *testing.T) {
//sample code to make api call and validate response
}
func setup() {
//start service
}
func shutdown() {
//stop service
}
I want to see/generate a coverage report. The following command is being used to run tests:
go test -coverprofile=coverage.out
Output on terminal is
PASS
coverage: 100.0% of statements
coverage.out is getting generated but it consists of only single line
mode: set
coverage.out should have information about the files, lines, etc.
Anything that I am doing wrong here?
test directory contains a single sample test file
Here it is, Go coverage does not work if your *_test.go files are not in the same directory aka they have been put in another folder.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.