JSON, testing

JSON on Android

Profiled some of my code with Traceview, turned out that 99% or so of time was spent in JSON-parsing library code. For JSON parsing at the moment I’m using org.json that comes with Android. I plugged in Jackson, which was quite easy to do, and saw noticeable speed improvement. Unfortunately my .apk size grew by about 270KiB. Plugged in another library, JSON.simple, which was only 15KiB, but also didn’t seem any faster than the built-in library. I’m sticking with built-in for now.


Since I’m just getting familiar with Android platform, I’ve been coding in exploratory style: write some code, run it and see what happens, reiterate. As I’m starting to get hang of things, it’s time to get back on TDD, and see what the testing infrastructure on Android is like. As usual, in beginning it’s frustrating. You don’t know how to ask right questions to Google, you don’t know what to test and how to do it, what is the best practices and idioms. You’re bound to make mistakes, rewrite, make more sophisticated mistakes, rewrite again…

By following tutorial and related docs, I set up a testing project in Eclipse. Had some struggle with setting up a 3rd party library used by my app. After that soon enough I had a very basic test that launches an activity and checks if it really launched. And this is where I’m at now. I need to inject mock datasource, so the test project doesn’t touch network connection, and I need to figure out least intrusive way of testing asynchronous aspects of my activities (here’s one starting point, registering callback and using CountDownLatch for wait-notify).