-
Notifications
You must be signed in to change notification settings - Fork 256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Go-dog code coverage percentage shows 0.0% #376
Comments
Same for me as well, Godog version
Go version
// file: main_setup_test.go
// this shows %0 test coverage
func TestMain(m *testing.M) {
// Check whether should it run godog E2E tests or not, this is the entry point for e2e tests
// I always pass arguments like godog.random, I'm aware it is super hacky :/
for _, argStr := range os.Args[2:] {
if isE2E := strings.Contains(argStr, "godog"); isE2E == true {
pflag.Parse()
os.Exit(runE2E()) // the changed line
}
}
// Otherwise run native test suite
os.Exit(m.Run())
} // file: main_unit_test.go
func TestItDoesSomething(t *testing.T) {
...
}
...
... // file: main_e2e_test.go
func runE2E() int {
opts.Paths = []string{"features"}
return godog.TestSuite{
Name: "E2E Test Suite",
TestSuiteInitializer: InitializeTestSuite,
ScenarioInitializer: InitializeScenario,
Options: &opts,
}.Run()
}
...
... if I apply following changes to // file: main_setup_test.go
// Then I suddenly get %86 coverage
// os.Exit(runE2E()) changing this to
status := runE2E()
if s := m.Run(); s > status {
status = s
}
os.Exit(status)
} Nevertheless, I still cannot get the coverage report. If I only run I execute my tests like below: // for E2E tests
go test -v -race -coverprofile=../../tmp/e2e.cov -covermode=atomic --godog.random
// for Unit tests
go test -v -race -coverprofile=../../tmp/unit.cov -covermode=atomic
|
I think the issue you're seeing is caused by default behavior of Go, which collects coverage only in the package that owns the test, this makes sense for unit tests. For end-to-end (integration) tests this is usually not the desired behavior. Please try configuring which packages should qualify for coverage with |
My case is a bit different, my project has this structure
Test suite is in func init() {
godog.BindCommandLineFlags("godog.", &opt)
}
func TestMain(m *testing.M) {
pflag.Parse()
os.Exit(m.Run())
}
func TestIntegration(t *testing.T) {
// Test suite is in here.
} When I run
I have 0% coverage in coverprofile file However, when I put func TestMain(m *testing.M) {
flag.Parse()
pflag.Parse()
os.Exit(m.Run())
} It works! And I have the right report in the coverprofile file. I have no idea what happens 🤷♂️ |
Just wondering if your tests are panicking. Go test coverage will not generate unless TestMain ends nicely. |
In my case, no panic |
Please answer these questions before submitting a bug report.
What version of godog are you using?
What version of Go are you using?
What did you do?
I'm trying to fetch code coverage on godog feature files(functional test cases). Have executed the below command and made necessary changes to testmain package for integration of godog with go test.
cd functionaltests
go test -v --godog.format=pretty -coverprofile=functionaltests.cov -covermode=atomic >> fcoverageresult.txt
All my test cases ran and i get the below output:
801 scenarios ([32m782 passed[0m, [31m19 failed[0m) 7066 steps ([32m7008 passed[0m, [31m19 failed[0m, [36m39 skipped[0m) 1m1.610143019s
What did you expect to see?
90% code coverage
What did you see instead?
coverage: 0.0% of statements
Additional context
Tried using httptest instead of http as well in the test packages. Still facing the same issue. Any suggestions?
The text was updated successfully, but these errors were encountered: