0

I am currently trying to test the Android SDK/API, and to do so have created an application that utilizes the SQLite classes in the API as well as a test that runs that application. I have been desperately trying to find code coverage of the SDK so that I can analyze my tests and get some actual results for my project. However, I can not seem to find any documentation (or even Stack Overflow questions) that provide any help for me to do this. I have been playing around with EMMA (and for a while Ant, although apparently the version in my Android build is not sufficient, and downloading it separately didn't go well for me). I found this question before, but I don't get their solution.

Can anyone help me? Thanks.

EDIT: I tried adding the code from the preceding link's link (it's adding code to the build.xml and ant.properties for EMMA), but now I don't even know where the coverage logs are stored, if it even works like I think it might.

Community
  • 1
  • 1
NioShobu
  • 775
  • 2
  • 10
  • 21

1 Answers1

1

I run code coverage on my Android projects using EclEmma. My unit tests are setup to run using Robolectric. I haven't used Ant to manage my Android builds, but it shouldn't be difficult getting it to work with these.

Tyler Treat
  • 14,640
  • 15
  • 80
  • 115
  • Two things: 1) Does using EclEmma give me coverage of the Android source classes (i.e. SQLiteDatabase, which I am using) and not just my test? The whole purpose of what I am doing is to test the Android API, so I need coverage of those classes. 2) I tried using EclEmma, but I get a weird error: "Error while dumping coverage data (code 5013). Socket closed" – NioShobu Aug 22 '12 at 18:34
  • Assuming you have the source code for the Android SDK attached to your project, yes it should. Although I find it a little strange you need to test Android's code. I don't know what that second issue is. – Tyler Treat Aug 22 '12 at 19:13
  • I updated, and it seems to work now, but I'm getting an error: "java.lang.NoClassDefFoundError: android/test/ActivityInstrumentationTestCase2" – NioShobu Aug 22 '12 at 20:15
  • After looking it up some, I found someone mention that it might be because Java 1.7 doesn't support EclEmma (or I think the other way around), but I'm using 1.6.0.33... Do I need to downgrade so little just to get this to work? – NioShobu Aug 22 '12 at 20:29
  • I use regular JUnit for my Android testing, but it looks like the Android test classes (i.e. ActivityInstrumentationTestCase2`) aren't in your classpath. – Tyler Treat Aug 22 '12 at 22:10
  • How should I change that in my settings? – NioShobu Aug 22 '12 at 22:12
  • I looked in Coverage Configurations > ClassPath and see the Android 4.1 library in there under "Bootstrap Entries". Doesn't this mean it is included in the classpath? – NioShobu Aug 22 '12 at 22:18
  • Presumably in your test project's classpath. I don't think this has anything to do with EclEmma. – Tyler Treat Aug 22 '12 at 22:32
  • Where do I change that in Eclipse's settings, though? This works fine when running normally on the emulator, I just get it when I run coverage with EclEmma. – NioShobu Aug 22 '12 at 22:38
  • Adding `android.jar` specifically to the User Entries under classpath results in a `Stub!` error. – NioShobu Aug 22 '12 at 22:49
  • Right, Robolectric is used to avoid the stub issues. – Tyler Treat Aug 22 '12 at 23:23
  • By the way, how would I be able to see the coverage of the Android libraries if I run EclEmma? – NioShobu Aug 23 '12 at 21:09
  • You will need to attach the source code to your project. It won't work if you're just using the binaries. – Tyler Treat Aug 23 '12 at 21:09
  • How so? Just link something to the source code in my AOSP directory? Where would that be in the settings? – NioShobu Aug 23 '12 at 21:11