# Code coverage with Coverage.jl in vscode

**URL:** <https://discourse.julialang.org/t/code-coverage-with-coverage-jl-in-vscode/65438>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [July 28, 2021, 1:53pm UTC](https://discourse.julialang.org/t/code-coverage-with-coverage-jl-in-vscode/65438 "2021-07-28T13:53:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![gitboy16](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gitboy16/32/24906_2.png) [@gitboy16](https://discourse.julialang.org/u/gitboy16)\
**Post date:** [July 28, 2021, 1:53pm UTC](https://discourse.julialang.org/t/code-coverage-with-coverage-jl-in-vscode/65438/1 "2021-07-28T13:53:55Z")

</div>

Hi,  
I followed the “tutorial” on [https://github.com/JuliaCI/Coverage.jl](https://github.com/JuliaCI/Coverage.jl)

I manage to create .cov files for my local package as well as an lcov file after running the command `LCOV.write("coverage-lcov.info", coverage)`

Is there a way to display the report in a nice way in vscode under windows?

I have tried Coverage Gutters but it does not seem to be working. I probably don’t use it correctly…

Is there a way to render the lcov file nicely in vscode?

Thank you

---

<div class="post-metadata">

**Author:** ![timcop](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/timcop/32/27693_2.png) [@timcop](https://discourse.julialang.org/u/timcop)\
**Post date:** [August 21, 2021, 5:24am UTC](https://discourse.julialang.org/t/code-coverage-with-coverage-jl-in-vscode/65438/2 "2021-08-21T05:24:05Z")

</div>

Hey there,

Not sure if you solved your issue or not but I recently decided to do the same thing as I had codecov setup but didn’t want to have to push to github and wait for tests to run to see my code coverage, and I managed to get this working using Coverage.jl to produce a lcov.info file and use Coverage Gutters extension with it. I noticed that for Coverage Gutters the default file it looks for is “lcov.info”, so change the .info file name (call LCOV.write(“lcov.info”, coverage)) if you haven’t already.

---

<div class="post-metadata">

**Author:** ![goretkin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goretkin/32/167_2.png) [@goretkin](https://discourse.julialang.org/u/goretkin)\
**Post date:** [June 29, 2022, 7:11pm UTC](https://discourse.julialang.org/t/code-coverage-with-coverage-jl-in-vscode/65438/3 "2022-06-29T19:11:14Z")

</div>

I just tried `Coverage.LCOV.write(filepath, coverage)` does not work. Here is the complete workflow that worked for me

# Julia line coverage information in VS Code

First generate `.cov` files:

```julia
using Pkg
Pkg.test("MyPackage"; coverage=true)

```

Then

```julia
using Coverage
coverage = process_folder()
open("lcov.info", "w") do io
    LCOV.write(io, coverage)
end;

```

Finally, open a source file in VS Code and run the command “Coverage Gutters: Display Coverage” in the VS Code Command Pallet.

---

<div class="post-metadata">

**Author:** ![klacru](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klacru/32/27890_2.png) [@klacru](https://discourse.julialang.org/u/klacru)\
**Post date:** [August 21, 2022, 8:45am UTC](https://discourse.julialang.org/t/code-coverage-with-coverage-jl-in-vscode/65438/4 "2022-08-21T08:45:53Z")

</div>

> `LCOV.write(“lcov.info”, coverage)`

the working call is

```julia
 LCOV.writefile(“lcov.info”, coverage)

```

---

<div class="post-metadata">

**Author:** ![greatpet](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Post date:** [May 24, 2023, 12:50pm UTC](https://discourse.julialang.org/t/code-coverage-with-coverage-jl-in-vscode/65438/5 "2023-05-24T12:50:38Z")

</div>

When I tested with the versions as of today, I needed to use the first one

```julia
LCOV.write(“lcov.info”, coverage)

```

It would be nice if all this workflow is directly integrated into a command in a future release of Julia’s VSCode extension.

---

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [May 24, 2023, 1:22pm UTC](https://discourse.julialang.org/t/code-coverage-with-coverage-jl-in-vscode/65438/6 "2023-05-24T13:22:34Z")

</div>

Maybe try [GitHub - JuliaCI/LocalCoverage.jl: Trivial functions for working with coverage for packages locally.](https://github.com/JuliaCI/LocalCoverage.jl)  
I’m using that to push coverage reports to a local Gitlab instance.

---

<div class="post-metadata">

**Author:** ![klacru](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klacru/32/27890_2.png) [@klacru](https://discourse.julialang.org/u/klacru)\
**Post date:** [May 26, 2023, 3:50pm UTC](https://discourse.julialang.org/t/code-coverage-with-coverage-jl-in-vscode/65438/7 "2023-05-26T15:50:47Z")

</div>

I have put this utility module in my `.julia/config/startup.jl`:

```julia
"""
    Util

`Util.test(;coverage=true)` to produce code coverage of active project. See ~/.julia/startup.jl
`Util.cleanup()` to remove .cov files.
"""
module Util
using Coverage
using Pkg

function test(;coverage=true, test_args=String[])
    Pkg.test(;coverage, julia_args=["--inline=no"], test_args)
    if coverage
        LCOV.writefile("lcov.info", process_folder())
    end
end
function cleanup()
    Coverage.clean_folder(".")
end
end # Util

```
