Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect code-coverage of separated folders in GO?

My project-structure
stuff/stuff.go -> package: stuff
test/stuff/stuff_test.go -> package: test
Although stuff_test executes code from stuff.go it shows
coverage: 0.0% of statements

I used go test -cover
If I move my *_test.go to the stuff-folder of the program it is working fine.
Or perhaps my approach of the project-structure is not well designed/go-conform?

like image 964
johannes.schmidt.delaunay Avatar asked Dec 30 '15 19:12

johannes.schmidt.delaunay


1 Answers

Conventional Go program structure keeps the tests with the package. Like this:

project
|-stuff
|--stuff.go
|--stuff_test.go

At the top of your testing files you still declare package stuff, and it is required that your test methods take the form TestMethodX if you want go test to automatically run them.

See Go docs for details: https://golang.org/pkg/testing/

like image 135
saarrrr Avatar answered Sep 20 '22 15:09

saarrrr