1

I have folder structure somewhat like this.

├── executor
|   ├── executor_test.go
|   |── executor.go
|   |--excutor_mock.go
|   |--errors.go
|   |--app.go 
├── _includes
|   ├── xyz.go
|   └── abc.go
├──vendor

executor_test.go contains all the unit test cases for executor.go.

So when I run go test --cover ./... It shows me the coverage package wise which is good but I also want to exclude errors.go, excutor_mock.go and app.go in executor folder from showing up in go test --cover ./....So is there a way to exclude them?

bugfreerammohan
  • 1,471
  • 1
  • 7
  • 22
Rajat Seeddharth
  • 197
  • 1
  • 3
  • 19
  • 1
    If these files are not part of the build than they are probably excluded already by a build tag and would not show up in the cover profile. If they do they are compiled and thus should be part of the line coverage. Note that line coverage as a single number is meaningless. – Volker Sep 15 '18 at 05:57
  • These files are included in build but since they are just defining the constants and interface and are mock files so i didnt write test cases for those files.Can you throw some more light on cover.out? – Rajat Seeddharth Sep 15 '18 at 06:41
  • Type definitions and constants are not counted during test coverage. View the coverprofile. (You probably but these into the relevant files anyway.) – Volker Sep 16 '18 at 07:47
  • you see this command is used for testing by Sonarcube go test ./... -v -coverprofile=cover.out .Some senior guy told me to play around with 'cover.out' to exclude those files but i didnt find any resource on that.Do you have any idea about this? – Rajat Seeddharth Sep 16 '18 at 08:53
  • I'm telling you to keep those files. You may cite me. – Volker Sep 16 '18 at 09:17

1 Answers1

-1

You can add all the tests you want to run in my_test.go and run go test my_test.go.

you can use -run=<regex> flag. This possible when you have a common Prefix, Suffix or term in the names of the tests you want to run. I will update a better answer.

hey, if anyone still ends up here. I tried building a command line application. Its still rough around the edges. It doesn't import all the packages. But it does what you required here. It will exclude files. Based on contents of a .testignore file.

here is the link https://github.com/kurianCoding/ko

whitespace
  • 789
  • 6
  • 13