# Testing Android Apps with Calabash

I’ve been doing Android development for three years now, and I’ve only used Robotium and JUnit for testing my apps. Recently, a friend of mine introduced me to Calabash, an acceptance testing framework for mobile apps. Calabash is based from Cucumber, a ruby BDD framework.

I’ve played around with Ruby before, but I haven’t really used it for a real project because I’m primarily a Java and Python guy. This weekend, I decided to try Calabash to get some Ruby chops. I rolled up my sleeves and read about the differences of ruby from python. I nodded along the way, but I needed something more to help me understand ruby. This talk did the job. Now onto Calabash!

I have some BDD experience with AngularJS, but Cucumber’s way of doing things looks like magic to me. How is it possible to describe tests in a human readable language? Calabash docs assume familiarity with Cucumber, so I started with that first. Thankfully, Cucumber has a nice documentation about the Gherkin syntax, the language being used to define Cucumber tests, or features in Cucumber speak. An example of a feature looks like this:

A feature file is parsed by Cucumber, which in turn executes each steps. The final step asserts whether the test passes or fails. At this point, it still looks like magic to me, until I learned that I have to define each step from the feature file in a separate Ruby file. While Calabash has a good set of canned steps, you’ll soon find that you’ll have to define some of the steps on your own if you decide to do anything serious with it. I’m not yet good at Ruby, and I don’t have someone with me to help me out. Luckily, there’s the Calabash shell which allows me to try out the Ruby API interactively.

Now, let’s get back to defining the steps for our feature. As an example, let’s define the step “an ad is at the bottom of the screen”:

After fleshing out the rest of the steps, execute calabash-android run path/to/your/android.apk and watch the magic begin!

As a newcomer to Ruby, Cucumber, and Calabash, I’m quite surprised at how easy it is to get started at using the whole suite. Granted, there’s a lot of reading involved, but overall it was a smooth process. It took me less than a day to get stuff running. Another thing that I like about Calabash is its interactive nature. Since it is written in Ruby, I can test the steps I’m planning to write in irb prior to fleshing it out and see immediate results. Compare this to Robotium, where you’ll have to recompile each time you make a change to your tests. Generally, I’m a fan of interpreted languages because of the smoother workflow compared to, say, Java. As an Android developer, Calabash is my gateway drug to the Ruby world.

# Comments

comments powered by Disqus