Search code examples
gotravis-ciginkgo

Ginkgo does not provide coverage in Travis CI


I have a GO project which I build in Travis CI. I have implemented a few tests with Ginkgo, and I am getting code coverage when I run it locally, however I get no coverage when I run it on Travis.

My .travis.yml

language: go

# safelist
branches:
  only:
  - master
  - travis

before_install:
  - go get github.com/onsi/gomega
  - go get github.com/onsi/ginkgo/ginkgo
  - go get github.com/modocache/gover

script:
  - ginkgo -r --randomizeAllSpecs --randomizeSuites --failOnPending --cover --trace --race --compilers=2

after_success:
  - gover . coverage.txt
  - ls -al
  - cat coverage.txt
  - bash <(curl -s https://codecov.io/bash)

When I run the script command on my own machine I get the following result

$ ginkgo -r --randomizeAllSpecs --randomizeSuites --failOnPending --cover --trace --race --compilers=2
Running Suite: Gitserver Suite
==============================
Random Seed: 1470431018 - Will randomize all specs
Will run 4 of 4 specs

++++
Ran 4 of 4 Specs in 0.000 seconds
SUCCESS! -- 4 Passed | 0 Failed | 0 Pending | 0 Skipped PASS
coverage: 25.9% of statements

Ginkgo ran 1 suite in 4.411023s
Test Suite Passed

But on travis CI the coverage says "0.0% of statement"

I have tried to setup a new GOPATH on my local machine to get a clean setup and only run the commands that occurs in the Travis log, and I still get a reported 25% coverage. My machine is running windows where as Travis is linux, that is the only difference I can think of right now.

I have just tried GoCover.io on my package, and that also gives me the 25% coverage that I get locally.


Solution

  • I finally got it to work after I ran the travis build locally through their docker image. For some reason I need to specify which package to cover, so the ginkgo command has been changed into

    ginkgo -r --randomizeAllSpecs --randomizeSuites --failOnPending --coverpkg gitserver --trace --race --compilers=2