technology from back to front

Archive for December, 2010

Robolectric: unit testing Android apps

I’ve been playing around with doing some testing of my Android apps, and it turns out to be a little bit more difficult than I’d hoped, but with the aid of some tools it can be brought back under control. Given Android apps are basically just Java, the usual choice would be JUnit. Android needs a bunch of extra classes that aren’t part of the standard Java setup, but given the SDK provides an android.jar it should just be a matter of plugging that into your test stage, right?

Ok, it’s not quite that simple. Doing this gets you “java.lang.RuntimeException: Stub!” rather rapidly. As it turns out, the major purpose of the android.jar is to provide something to compile against, but the actual implementation of the classes is missing, as it’s assumed you’re going to run the app on your device or emulator. Interfacing with either of these is going to be a bit slow and fiddly for unit testing purposes (my netbook for example is perfectly good for Android dev provided you don’t need the emulator…), so that’s out. Something could possibly be worked out using the x86 Android port, but that’s likely to get very complicated very fast, so let’s skip that as well.

Enter Robolectric. With the aid of a bunch of magic behind the scenes, it lets you make your tests work.
Read more…

by
Tom Parker
on
31/12/10

F# zipper with pipe forward

The zipper is a purely functional data structure which is useful when manipulating immutable data structures (see the original paper here by Gerard Huet). Haskell and Clojure both have implementations of the zipper, but I have been unable to find one for use with F#. The original implementation is written in OCAML so is relatively easy to port to F# so this post will briefly walk through the code and give an example of its use.

Here I have defined three types:

  • A tree – a simple tree data structure.
  • A path – the items in the tuple correspond to everything to the left of a location in the tree, everything above a location in the tree and everything to the right of a location in the tree, and a location in the tree.
  • A location- the first item in the tuple is the current location and the second item is the path through the tree to the current location.

The location type is a pointer into the tree structure, by manipulating the location we can traverse the tree.

We use two additional functions to create locations and extract the tree from a location.

We also need functions that will actually manipulate the zipper, these differ from Huet’s OCAML in that the parameters have been swapped so that they can be used with the F#
pipe forward (|>) operator.

Now, we have that we can try it out using FSI:

The pipe forward operator combined with the navigation and modification functions produces a nicely readable line of code that traverses and produces an altered tree. The original tree is also unmodified as this is purely functional code.

by
tim
on
30/12/10

Conditional statements, the lambda calculus and early/late binding

Soon after I started learning Smalltalk, I found my brain broken. Smalltalk doesn’t have control structures. No ifs, no whiles, no for loops. All these structures are instead patterns of message
passing [1].

Read more…

by
Frank Shearar
on
22/12/10

mercurial-server version 1.1 released

Version 1.1 of mercurial-server is now available. This permits one repository to be in a subdirectory of another, which makes subrepositories more convenient, as well as improvements to logging and documentation. I’ve also included the collection of scripts I use for testing under the “dev” subdirectory in the main repository, though I’d want to clean these up somewhat before including them in the release tarballs.

The Debian version also includes fixes for all the outstanding bugs against it in Debian; I’ve sent the files off to the sponsor, so hopefully that’ll enter Debian testing soon.

by
Paul Crowley
on
19/12/10

Search

Categories

You are currently browsing the LShift Ltd. blog archives for December, 2010.

Feeds

Archives

2000-14 LShift Ltd, 1st Floor, Hoxton Point, 6 Rufus Street, London, N1 6PE, UK+44 (0)20 7729 7060   Contact us