nx run-many --target=test --coverage but exclude one project from coverage - code-coverage

Is it possible to exclude one project (name it ProjectA) from coverage with nx run-many --target=test --coverage?
--exclude won't work as I still need UT result of ProjectA. ProjectA is expected to have very low code coverage rate, that I don't want to include into a code coverage summary of whole workspace.
Setting collectCoverageFrom to !** in ProjectA's jest.config.js somehow works, but nx --coverage command still generate code coverage result 0/0.
I could also split original command into two
nx run-many --target=test --all
nx run-many --target=test --all --coverage --exclude=ProjectA
but it's waste of time to run test twice.
Is there a better solution? Is it possible to configure a project differently with nx run-many command?

Related

bazel coverage results are incomplete

The problem I'm running into is that my bazel coverage output coverage data feels incomplete.
For example, I have a project with 10 source files, and 1 test file (which tests only 1 source file).
Run bazel clean && bazel coverage --combined_report=lcov -- //src/...:all
Verify coverage data generated with find -L -type f -name 'coverage.dat'
Notice that:
There exists 1 coverage file for each test run
(Problem!) There is no coverage data for the untested source files
Does anyone know how to configure bazel to generate a complete coverage report, which includes the untested source files as well?

How to include all targets in bazel coverage

How do I include non-test targets in bazel coverage? Currently I use the following bazel command to get code coverage:
bazel coverage \
--instrument_test_targets \
--experimental_cc_coverage \
--combined_report=lcov \
//... --test_arg=--logtostderr
The project is written in C++. The command works fine. However, the output lcov trace file only includes the files that have coverage. If a C file does not have a test, it is not in the lcov trace file.
Does bazel coverage only executes the test targets? Is there a way to include all targets (the non-test targets)? So that even if a file has no test, I can still see it in the report (the report will show zero coverage). The intention for this is that if someone adds new files and doesn't write unit test, the file can be shown in coverage report.
Can you reproduce using --incompatible_cc_coverage?

Bazel: How to exclude path from code coverage for Scala / Java?

I am using Bazel with rules_scala. My problem now is how to exclude files from code coverage. So far this is how I am running coverage:
rm -rf coverage
bazel coverage --combined_report=lcov --coverage_report_generator="#bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main" ...
genhtml -o coverage --ignore-errors source bazel-out/_coverage/_coverage_report.dat
But there are some folders I would like to exclude from code coverage. I tried using the --instrumentation_filter flag, but no matter what I tried putting there Bazel still collect coverage for this folder.
Are there any examples how I should use this flag?
Thanks!
Use
bazel coverage --combined_report=lcov --coverage_report_generator="#bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main" -- //... -//package/to/ignore/...
This appears to be a bug with rules_scala. See this issue for more details.

How to improve the branch coverage using gcovr tool

I have written a sample program using C++. I have written corresponding unit tests using GUNIT framework. I was successfully able to generate.gcda and .gcno files for every source file. I used (gcov -b -l -p -c *.gcno) command in the folder where the .gcno files were generated. I am using gcov 7.5.0 . When i ran this command i saw that it gave me a)Lines covergae in percentage b)Branches covered in percentage c)Taken atleast once . Next i ran (gcovr --html -o Filename.html -r /path_to_C_sourceFiles/ .) command to generate the html output for this data. In the html file i see that the branch covergae data is extracted from the taken atleast once data which was generated by the gcov. Why is the html not taking the branches covered percentage from the gcov data and displaying it as branch covergae. Taken atleast data given by the gcov tool is a reduced number when compared to branches percentage. What is this taken atleast once?
A branch is covered if it was taken at least once. If a branch is executed multiple times, it is not more covered. So gcovr primarily considers covered/uncovered status for lines and branches, whereas GCC's gcov tool shows execution counts and branch probabilities.
Having access to the branch probabilities can be useful. Not in the context of testing, but perhaps for low-level code optimization. If you need that data, you will likely want to look at the gcov files yourself.
However, the next version of gcovr (expected to be gcovr 4.3) will show branch counts (not percentages) in the HTML report:
For each line with branch coverage data, there will be a popup that shows full branch counts.
You can use this functionality right now if you install gcovr's development version:
pip install git+https://github.com/gcovr/gcovr.git

How to show branch coverage for C++ project on coveralls.io?

I am using the coveralls.io service to display line coverage for my C++ project. I also want to track branch coverage, but cannot get it to work.
On Travis CI, I use this call to generate the coverage report:
coveralls -r <my_project_root> -b <my_build_dir> --verbose --gcov=gcov --gcov-options '\-lpbc';
The coveralls script is previously installed with pip
pip install cpp-coveralls urllib3[secure]
I get the line coverage shown correctly on coveralls.io, but not the branch coverage. I don't know what of the following things I am doing wrong.
Do I have to activate it on coveralls.io explicitly?
Is there something wrong with the coveralls command?
Can coveralls.io even show branch coverage?
Pretty late to the party, but to answer your question(s):
Yes, you will want to enable the Coveralls setting for BRANCH COVERAGE: INCLUDE IN AGGREGATE %:
Of course, this will only work if branch coverage is included in your original coverage report.
That happens in a prior step, when you compile the original project into an "instrumented" version of the source code and generate the GCOV coverage report, before you use the coveralls command to POST the coverage report to Coveralls.
Something like:
gcc -Wall -ftest-coverage -fprofile-arcs cov.c
gcov --branch-probabilities cov.c
Source: gcov Wiki - Example

Resources