Code coverage for monorepo

Buyung Hardiansyah
2 min readMay 19, 2020

--

coverage sunburst graph

Code coverage is a measurement used to express which lines of code were executed by a test suite. A program with high test coverage, measured as a percentage, has had more of its source code executed during testing, which suggests it has a lower chance of containing undetected software bugs compared to a program with low test coverage.

monorepo is a software development strategy where code for many projects is stored in the same repository.

in monorepo you will have multiple project with mutliple coverage based on the project in monorepo. but the case is you want to have one coverage including all of the project in one coverage file.

in this case we use codecov (codecov.io) for code coverage tools. and bazel for monorepo build tools. and github for source code repository.
assume we have 2 application in monorepo with each coverage file. we want to merge all of the coverage file into one coverage file. and upload to codecov.

monorepo
└── pkg
├──logs
│ ├── main.go
│ ├── BUILD.bazel
│ ├── coverage.txt
│ ├── ext
│ │ ├── counting.go
│ | ├── counting_test.go
├──services
│ ├── main.go
│ ├── BUILD.bazel
│ ├── coverage.txt
│ ├── ext
│ │ ├── stringers.go
│ | ├── stringers_test.go
├──WORKSPACE
├──BUILD.bazel

first you must activate codecov from selected repository.

for this case, codecov have feature named flags (https://docs.codecov.io/docs/flags). Flags allow you to isolate coverage reports for different tests. This is particularly helpful if you employing a monorepo setup where you’d like to encapsulate each project’s test coverage independently.

create codecov.yml in root folder :

upload your coverage with this command :

if no error in uploading codecov. you will see the result in codecov.io :

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Buyung Hardiansyah
Buyung Hardiansyah

Written by Buyung Hardiansyah

Software Developer -- Golang | Python | PHP | Reactjs | Flutter

No responses yet

Write a response