Tuesday, April 28, 2009

Testing your Android applications

For future reference, Můj Android.cz will probably be a good blog to look at for test-driven Android development. The linked article is the only one so far though, and the rest of the blog seems to be in Czech (?). But this quote is particularly pertinent:
"There are basically three levels of tests/unit-test you can use in your application:
  1. Unit testing of logic which does not depend on android at all. This is similar to every usual unit testing. Running tests directly from Eclipse requires some configuration changes which we will cover later.
  2. Unit testing of business logic which depends on Android but does not depend on Android application elements and ui. These logic does not require activity to be running with complete context and it can be tested in isolation from ui. These tests usually require something from context (e.g. resources, configuration, logger, some native classes)
  3. Unit/funcional testing of Android application elements. These tests are fully instantiated activities, services, content providers and applications. Via instrumentation it is possible to send keyboard and touch events to the activities and check response in ui. It is possible to test lifecycle of a service and to test databases changes made by content provider."
I've been trying to figure out how to test the second case, since I've been getting "Java RunTimeException: Stub!" errors for a while. As it turns out, you cannot just use JUnit to test code that calls on Android APIs: "android.jar in the SDK is only stubbed methods/classes, and contains no code." Even if you are not testing an Activity or any UI elements, you will still need to use Instrumentation. Once I figure this all out, and I am not lazy, I hope to write a very simple tutorial. Unless someone beats me to it, in which case I won't. :)

Monday, April 27, 2009

Android ApiDemos in Eclipse

I've been learning how to write Android apps lately, and I've been trying to figure out to use TDD. Diego Torres Milano's blog has been pretty helpful to me, especially his post about how get Android ApiDemos' tests to work. As a newbie to Eclipse and Android development though, I had some trouble with his instructions. Here are a few things I did that I didn't think was very clear on Diego's blog:
  • Create an ApiDemos Project first (New Android project -> Project from source -> use the source from [android SDK directory]/samples/ApiDemo).
  • Don't bother to delete the Dummy class or remove the source directory you created (when you follow his instructions to create the ApiDemosTest project).
  • The emulator has the ApiDemos installed by default. You should uninstall the default installation (adb uninstall com.example.android.apis) and run your ApiDemos project in Eclipse. If you don't, you'll get errors when you run ApiDemosTest because the default ApiDemos installation is in a separate security domain (I think).
Other than these points, his post (and the comments) are pretty clear. This entry from Zhao's Weblog is also helpful.

Friday, February 6, 2009

Intrepid Ibex on MSI Wind

I upgraded my MSI Wind laptop from Hardy Heron to Intrepid Ibex. It didn't really fix any problem - my wifi drivers don't seem to be packaged with Intrepid and I have re-download the kernel module every time my kernel gets upgraded. My webcam still does not work. And my hard drive is clicking again. Editing /etc/hdparm.conf doesn't seem to work anymore. So I edited the following files:
  • /etc/acpi/resume.d/90-hdparm.sh
  • /etc/acpi/battery.d/90-hdparm.sh
I set DO_HDPARM=n. Basically, I'm saying "don't park my drive heads." I could also install laptop-mode-tools, but all I really want to do is to stop the drive heads from parking. This is an inelegant solution, but simple.

Monday, December 22, 2008

My new MSI Wind and Ubuntu

I just bought a MSI Wind U100-420US netbook to replace a dying Sony Vaio. I got it for several reasons:
  1. I like small things that are easily portable - I suppose I am out of shape, but regularly sized laptops are actually fairly heavy. I do not want to carry a backpack everywhere I go, and a messenger bag or other bag with one strap, when a laptop is in it, causes my shoulder to cramp up.
  2. There are no other laptops out there right now that I find particularly interesting or desirable. The new Apple MacBook is nice, but not much of an improvement over their older MacBook (which Matthew has), and the Sony Vaio VGN-Z530N is pretty great spec-wise as well as light, but not quite worth $1600 to me (almost though - this was a pretty serious contender).
  3. Has a greater-than-16GB hard drive. I'd like to actually have space to download photos from my camera to, etc.
  4. There is a nice wiki on how to install Ubuntu on it.
  5. Was the cheapest Netbook I could find.
Once I finishd installing Ubuntu, it was time to try to fix all the little bugs. This part is mostly for me, to remember what I did in case I have to undo it or if I need to do this again for some reason.
  1. First I needed to get wireless working. Currently, the Realtek 8187 wireless card is not natively supported in Ubuntu, but you can compile them from source provided by Realtek. I chose to just install the .debs someone else made.
  2. I had a hard drive clicking problem which I fixed by turning off drive power management. (I used hdparm -B 255... 192 didn't fix the clicking for me.)
  3. Fixing the hard drive clicking is part of the fix for suspend - I also changed alsa as specified in that wiki article above, and suspend seems to work now.
  4. The Adobe Flash Player 10 .deb works just fine.
  5. I also installed Netbook Remix packages. It's quite nice, although there are some bugs. For instance, netbook-launcher (formerly ume-launcher) does not play nice with compiz.
There are still issues I would like to fix: for instance, I'd like to be able to modify the touchpad settings, and haven't bothered trying the webcam tweaks (I don't really need a webcam).