Skip to content

Fixes #21: merge test coverage with e2e tests in CI#22

Open
Reactivity512 wants to merge 2 commits into
ozontech:mainfrom
Reactivity512:feature/21-merge-coverage
Open

Fixes #21: merge test coverage with e2e tests in CI#22
Reactivity512 wants to merge 2 commits into
ozontech:mainfrom
Reactivity512:feature/21-merge-coverage

Conversation

@Reactivity512

@Reactivity512 Reactivity512 commented Jun 19, 2026

Copy link
Copy Markdown

Fixes #21: merge test coverage with e2e tests in CI

@metafates metafates left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Left some review comments

Comment thread .github/workflows/qa.yml Outdated
if: runner.os != 'Windows'
run: |
go test -race -v -coverprofile=coverage.out -coverpkg=./... ./...
make coverage-ci TEST_FLAGS="-race -v"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's inline this so that workflow won't depend on Makefile

Comment thread Makefile Outdated
go tool cover -func coverage.out

# get test coverage-ci
.PHONY: coverage-ci

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.PHONY isn't needed here because we have MAKEFLAGS += --always-make

Comment thread Makefile Outdated
coverage-ci:
go test $(TEST_FLAGS) -coverprofile=coverage.unit.out -coverpkg=./... ./...
go test $(TEST_FLAGS) -tags e2e -coverprofile=coverage.e2e.out -coverpkg=./... ./... || true
go run github.com/dlespiau/covertool@latest merge -o coverage.out coverage.unit.out coverage.e2e.out

@metafates metafates Jun 21, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, I think we should avoid relying on third-party tools.

I think we can simplify this a bit.

Overall, it should look like this:

  1. go test ./... - run unit tests
  2. go test -tags e2e -count 1 ./examples_test.go - run e2e tests
  3. go test -tags example -coverprofile coverage.out -coverpkg ./... ./... || true - run both unit tests and examples (which are invoked from e2e).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest two options:

  1. Simple, but it requires running unit tests twice (first without coverage, then again during the general test run)
# Run unit tests separately to catch errors
go test -race -v ./...

# Run all tests together for coverage (ignoring failures)
go test -race -v -tags e2e -coverprofile=coverage.out -coverpkg=./... ./... || true

go tool cover -func=coverage.out
go tool cover -html=coverage.out -o coverage/coverage.html
  1. Using go tool covdata. This is the official Go tool introduced in v1.20, designed exactly for this use case.
mkdir -p coverage/unit coverage/e2e coverage/merged

# Run unit tests and save raw coverage data to coverage/unit
go test -race -v -coverpkg=./... ./... -test.gocoverdir=coverage/unit

# Run e2e tests and save raw coverage data to coverage/e2e (ignoring failures)
go test -race -v -tags e2e -coverpkg=./... ./... -test.gocoverdir=coverage/e2e || true

# Merge data from both directories into coverage/merged
go tool covdata merge -i=coverage/unit,coverage/e2e -o=coverage/merged

# Convert merged data to text format (coverage.out)
go tool covdata textfmt -i=coverage/merged -o=coverage.out

# Generate a report to the console
go tool cover -func=coverage.out

# Save the report to text and HTML files
go tool cover -func=coverage.out -o coverage/coverage.out
go tool cover -html=coverage.out -o coverage/coverage.html

Which approach do you think is more suitable?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simple, but it requires running unit tests twice

I think it's good enough. Let's stick to this one.

But important note, though - running e2e won't affect the coverage, as it runs examples through separate process. We need to run those examples directly with example tag from examples/ dir with coverage.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, then we can run it like this:

go test -race -v -tags e2e,example -coverprofile=coverage.out -coverpkg=./... ./... || true

@metafates metafates added the enhancement New feature or request label Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Merge test coverage with e2e tests in CI

2 participants