Android Studio Unit Tests With Coverage Showing 0% On Everything - android-studio

I'm trying to check my unit test coverage, all my tests are passing, but when I run the tests with 'Run Tests With Coverage' by right clicking on my test file, when it completes, everything comes back as 0%?
Looks like it's supposed to just work reading https://developer.android.com/studio/test/index.html and can't find anything saying why it would be returning 0% for everything?
Is there some hidden setting I'm missing to get this working?

Go to Run->Edit Configuration->Code coverage.
Add your package/class for which you want to run tests, in Packages and classes to record coverage data section.
Also, check Enable coverage in test folders option.
Click Apply and Ok. Re-run your tests with coverage.

Related

How can I merge coverage reports from jest and playwright using nyc without getting wrong results for functions?

In the project I use playwright to test most of the code. I added jest to test some specific util stuff directly. Playwright and jest generate a json test coverage report which I want to combine to show the total coverage as a HTML report. I managed to merge the two reports and the coverage values seem to be correct. But the function coverage is off. Before adding jest it showed 16/16 Functions covered with 100 % now it shows 17/34 and 50% after adding the jest tests.
I use the following commands to merge my reports:
npx nyc merge ./coverageReports/ merged-output/result.json
npx nyc report --reporter=html --reporter=text -t merged-output/
Now I would expect the HTML report to look something like this:
But my coverage looks like this:
The rest off the report looks correct and for files where I only have tests for one of the tools it works as expected. Utilities is currently the only file with playwright and jest tests covering functions. But this will change when more jest tests are added. Is there a way to get correct numbers in this case as well?

Change coverage combination method for Gitlab from different sources

In the project I mainly use Playwright to test and collect coverage. It's around 50 pages which are covered in this way. Now I added Jest to test some util functions which do not directly show up in the Frontend.
Now I am trying to combine the coverage for both playwright and Jest. My problem is, that jest only covers two or three files while playwright covers around 50. So the default behavior of GitLab to display the average between the two percentage values does not display the coverage accurately. E.g. Playwright has a Coverage of 80% over 50 files while Jest only covers 10% for one file atm. Coverage is now at 45% overall.
I tried to use the Regex in my gitlab.yml described on GitLab in both jobs, which allows me to display the coverage in the first place.
I also tried to move the final coverage collection to a new job where I use
npx cobertura-merge -o ./coverage/combined-coverage.xml package1=./coverage/cobertura-coverage.xml package2=./coverage/cobertura-jest-coverage.xml
to create a combined coverage report to use in the reporting system. But If I try to use the Regex in this job instead of the other two, I see no coverage value at all.
I would expect to get a coverage value that matches the actual files I covered so e.g. 80% in the playwright files and added to that the value for one file covered in jest and not the 50:50 split between playwright and jest.
It looks like this in my MR where I add Jest. As you can See, my overall coverage is dropping by 34.90% which is a bit misleading.
I solved this by adding a -p tag to my merge command which prints the result. Then I adapted the regex to match the value I wanted to present:
coverage: '/Total line Coverage: \d+\.\d+/'

TFS Test - mstest log output - final test results

A couple of days ago our vs2012 mstest started producing two logs of test results in the one session, the initial "Results Top Level Tests" then Final Test Results:" "Results Top Level Tests"
As we parse the file, naturally we came undone with two lots of results.
Why is their two lots of results and - or how was this triggered ?
What is "Final Test Results" about?
(the console output from mstest is piped to a file)
Thanks
Based on my test, the issue should be caused by the test cases or the test processes which have something wrong. And the "Final Test Results" will appear there.
Simply say, when the message "Final Test Results" appears, that means maybe there are something wrong with the configuration of your test project or test processes.
So, please check and debug the test cases, processes, environments etc...
Firstly make sure the tests running without any error within local Visual Studio.
Reference:
MSTest hangs when used from command line
MSTest.exe command-line options

Fail code coverage if no tests exist for code

I have a simple Node JS application and am using Istanbul with Mocha to generate code coverage reports. This is working fine.
If I write a new function, but do not create any tests for it (or even create a test file) is it possible to check for this?
My ultimate goal is for any code which has no tests at all to be picked up by our continuous integration process and for it to fail that build.
Is this possible?
One way you could achieve this is by using code coverage.
"check-coverage": "istanbul check-coverage --root coverage --lines 98 --functions 98 --statements 98 --branches 98"
Just add this in your package.json file, change the threshold if needed. If code is written but no test then the coverage will go down.
I'm not sure if this is the correct way to solve the problem but by running the cover command first and adding the parameter --include-all-sources this then reported on any code without a test file and added them to the coverage.json file it generated.
Then running the check-coverage would fail which is what I'm after. In my CI process I would run cover first, then check-coverage
Personally I find the documentation on Istanbul a little bit confusing/un-clear which is why I didn't see this at first!

nUnit Test Runner - Test stays in "Not run" if it takes over a certain amount of time

We have some Selenium tests built with nUnit that take quite a while to complete. We are finding that they stay in the "Not run tests" grouping even though they should pass.
After some initial investigation we found that if we remove some long running steps the tests will pass correctly but as soon as we shove a sleep in the code that waits for a couple of minutes the problem comes back.
We are using Visual Studio 2012 with the nUnit Test Runner extension as shown here: http://nunit.org/index.php?p=vsTestAdapter&r=2.6.2
Is there some hidden timeout in nUnit or the test runner that we need to change to get our tests (no matter how long they take) to pass or is there some other problem at work here?

Resources