Code coverage in Android Studio
Code coverage is a metrics that helps you understand how much % of your source code has been tested in unit/integration tests that you have written in any language.
In Android studio it is pretty easy to get the code coverage and also know the lines that were covered and lines that were not covered in testing.
To get simple code coverage( assuming you have default studio settings). Just go to the class and click on the test/class containing the test and choose to run with code coverage option.
Then just have a look at the folder list.
Next to the class you will have code coverage percentage.
Next if you want to know Coverage of all your test cases, just goto Java folder in testing, right click and run test with coverage. That would help you to determine coverage for all test cases.
However it is not still easy to tell that if code coverage < 100%, what portion of code we missed.
However it is quite easy thanks to Android Studio. Just goto your configuration, that you have created for testing and choose tracing radio button and check “Track per test coverage”
Run the coverage
You see this window
You see the coverage
You can now see lines not covered in red and covered in green . Lines in red needs test cases to be exercised upon them.
If the colors are too light for your eyes you can always darken them by clicking on the red bar
And then choosing colors of your likening