Android: Code coverage tool using Android Studio - android

I have written test cases for iOS and there we have
XcodeCoverage
for finding out the code coverage. Now, I wish to do same for my android test cases. Is there any tool compatible with Android Studio itself?Any suggestions/ reference links would be helpful.

using Android Studio 1.4 (and probably 1.1+), you have the ability to get the coverage while running your tests without additional plugins.
If you can't see the Run 'All Tests' with coverage button, you can find out why here.

You can use JaCoCo plugin, which is fairly new, but in general does the job more than enough. You can get more details about it here : Android test code coverage with JaCoCo Gradle plugin

Related

How does Android Studio get code coverage?

As stated in the docs and other SO questions Android Studio provides a way to run your tests and get the code coverage (class, method and line level).
What framework or tool does it use internally to get the coverage ?
Android Studio is based on IntelliJ, and as such uses IntelliJ's IDEA Code Coverage Runner. This is open source, and can be found here

How to run unit tests with IDEA+Gradle+Android

I've written some unit tests in my Android projects with Robolectric, and some of them even don't use Android.
I've tried first this: robolectric-gradle-plugin, following this template.
The result is that I've faced this bug in IDEA, that I reported myself.
Then I've tried another possibility: the gradle-android-test-plugin, which separates tests in another submodule, that is a regular Java project. I've tried to follow this other template. I've open this bug report.
Then I've faced again with other bug.
What recommendations can you provide me, that does work?
Finally I've had to upgrade IDEA to 14 EAP, and know it works ok.
gradle-android-test-plugin seems to work better than robolectric plugin, as I can run JUnit and ScalaTest tests easily. I've had to install with a script, the non-published com.novoda:gradle-android-test-plugin:0.9.9-SNAPSHOT.
It's a hell the combination of versions of:
Android Build Tools
Gradle
com.android.tools.build:gradle
IDEA
robolectric
robolectric plugin
....
Any change in one of them, can make your project fail.
Luckily, by using Gradle you can fix the versions of every component, and do Continous integration.

Unit tests in Android Studio 0.8

BREAKING NEWS: Android Studio 1.1.0 now has built-in support for unit testing. See more here: https://sites.google.com/a/android.com/tools/tech-docs/unit-testing-support
At first I know that there are very, very, very much similar questions (even here on SO). Most of them are terribly outdated so I'm asking a fresh new question which should be up to date for Android Studio 0.8.x.
I know there are some libraries which work somehow, but in almost each case I had no evidence that the information were up to date. I know there is e.g. roboelectric, there are also some deprecated Jake Wharton like gradle-android-test-plugin or double-espresso, I also found the library RoboSpock and Deckard. But none of them seems to have any Android Studio integration.
After long reseach I found this two bugs in all implementations:
The classpath is broken and needs to been hacked to get junit running
The junit tests cannot been debugged
What I'm looking for:
I want to automatically test an algorithm (which is plain java)
I want to check the integration in my Android app works
I want an integration in Android Studio so that I can jump into the code out of a stacktrace
I want to step thrue the test code
I found also somewhere a nice hack which run the tests in gradle as an external task and pushed the results into AS so that the results could been displayed, but unfortunately I cannot find that link again (and if I remember correctly it did also not work for me).
Do you guys have some fresh references? Does it work for you?
You have to edit the .iml file that Android Studio generates to point to your test-classes directory and also to fix the Stub error from Junit. There is currently no work around for this.
Gradlectric is a sample that uses the Robolectric Gradle Plugin to run unit tests in Android Studio.
Here you miss one example project setup https://github.com/nenick/android-gradle-template
But none of them seems to have any Android Studio integration.
This project is maintained for android studio
The classpath is broken and needs to been hacked to get junit running
gradle scripts will fix the classpath
The junit tests cannot been debugged
tests a running inside AS so they are easy to debug
This project of mine does not cover all your requests, but a fair lot of them.
It covers a default Java test case, and some tests interacting with Views.
The root project uses Travis CI, which uses gradle connectedCheck to run the tests. To be able to debug the tests, you can just create a test run configuration in AS and run it in debugging mode.
Note that this does not use any special Android testing frameworks like robolectric.
You can find a fork of Jake Wharton's gradle-android-test-plugin here. This is compatible with AS 0.6 and is regularly maintained by Robolectric. You can look at this project to set up Robolectric in Android Studio with help of this plugin. You can achieve fair bit of functionality you mentioned with the help of robolectric-gradle-plugin. You can also successfully debug your test code using AS.

How can I capture code coverage of manual tests on an Android apk, built with maven?

We're trying to get code coverage analysis of a set of manual tests run on an Android application running on a device. We build our application using maven, so the cool emma and ant solution isn't viable.
Does anybody have explicit experience getting emma or cobertura (or any other open source coverage tool) working for manual testing of Android applications? We can't afford to purchase a solution (so no Clover, or Java Test Coverage Tool, etc.).

Getting code colored with emma in Android project

I have code coverage with Emma for my Android projects and I get a nice html-file. But i kind of think an html-file isn't really good enough. I want to see covered and not covered code in the editor.
Is there a way to use the .em or .ec files are genereated to get Eclipse to color the code?
Thanks in advance
Roland
EclEmma the eclipse plugin gives you colored code coverage.
You just run your tests using this button:
And you get in Eclipse output like this:
Oh and I run my unit tests with Robolectric that is Android but doesn't use Dalvik, uses your native JVM
Perhaps this what you are looking for EclEmma, however it looks like it is now using JaCoCo for code coverage metrics rather than Emma perhaps there is an older version of the plug-in that still works.
I suppose it depends on what you want code coverage from Emma, or visualization in Eclipse.
Try comparing the outputs of JaCoCo and Emma, I would have thought they should give similar if not identical results, and then choose.
Does JaCoCo work against the android platform - I can't say.
According to the ECLEmma team, on http://www.eclemma.org/devdoc/eclemma20.html:
Future support for EMMA and EclEmma 1.x Maintenance
From EclEmma 2.0 on EMMA will not be supported any more as a coverage
engine. ...
Beside this we will try to maintain the EMMA based 1.x stream on a
best effort base but with no functional enhancements planned. There
will be a separate download for the 1.x versions.
Per my comment below, ECLEmma 2.0 uses JaCoCo which is currently incompatible with Android due to not supporting off-line instrumentation that can be processed into Dalvik. To use Emma with Eclipse, you need ECLEmma 1.0, so see here: http://www.eclemma.org/installation1x.html

Categories

Resources