• No se han encontrado resultados

PROPUESTAS DE ENSEÑANZA DESDE LA PERSPECTIVA DIDÁCTICA DE ELE

Marta Belmonte Treviño

3. PROPUESTAS DE ENSEÑANZA DESDE LA PERSPECTIVA DIDÁCTICA DE ELE

Adrian Cowham

Problem

Making sure your app's GUI is as snappy as possible isn't easy. But with the help of Android's StrictMode it doesn't seem all that bad.

Solution

Android has a tool called Strict Mode that they introduced in Gingerbread, Strict Mode will detect all cases where an ANR might occur. For example, it will detect and log to LogCat all database reads and writes that happen on the main thread (i.e. the GUI thread).

Discussion

I wish I could've used a tool like StrictMode back when I was doing Java Swing Desktop development. Making sure our Java Swing App was snappy was a constant challenge, green and seasoned engineers would invariably perform database operations on the UI thread that would cause the app to hiccup. Typically we found these hiccups when QA ( or customers ) would use the app with a larger dataset than the engineers were testing with. Having QA find these little defects was unacceptable and ultimately a waste of everyone's time ( and the company's money ). We eventually solved the problem by investing more heavily in peer reviews, but having a tool like StrictMode would have been comparatively cheaper.

The example code below illustrates how easily StrictMode can be turned on in your app. Example 3-10.

// make sure you import StrictMode import android.os.StrictMode;

// In you app's android.app.Applicatoin instance, add the following // lines to the onCreate(...) method.

if ( Build.VERSION.SDK_INT >= 9 && isDebug() ) { StrictMode.enableDefaults();

}

Please note that the isDebug() implementation has been intentionally omitted, as this will vary among developers. I recommend only enabling StrictMode when your app is in Debug mode, it's unwise to put your app in the Market with StrictMode running in the background and consuming resources unnecessarily.

StrictMode is highly configurable, it allows you to customize what problems to look for. For detailed information on customizing StrictMode policies, see the StrictMode link below.

See Also

http://developer.android.com/reference/android/os/StrictMode.html

3.6 Barrel of Monkeys

Adrian Cowham

Problem

Not quite the Turing test, but if your app can pass the monkey test, you deserve a pat on the back.

Solution

Testing is so easy a monkey can do it, literally. Despite the lack of testing tools for Android, I have to admit that monkey is pretty cool. If you're not familiar with Android's monkey, it's a testing tool that comes with the Android SDK and simulates a monkey (or perhaps a child) using an Android device. Imagine a monkey sitting at keyboard and flailing away, get the idea? What better way to flush out those hidden ANRs?

Discussion

Running monkey is as simple as starting the emulator (or connecting your development device to your development machine) and launching the monkey script. I hate to admit this, but by running monkey on a daily basis we've repeatedly found defects that prob- ably would've escaped a normal QA pass and would've been very challenging to trou- bleshoot if found in the field. Or worse yet, caused users to stop using our app. Here we talk about a few best practices for using monkey in your development process. First, use monkey.

Second, create your own monkey script that wraps Android's monkey script. This is to ensure that all the developers on your team are running monkey with the same param- eters. If you're a team of one, this helps with predictability (discussed below).

Next, you'll want to configure monkey so that it runs long enough to catch defects and not so long that it's a productivity killer. In our development process, we configured monkey to run for a total of 50,000 events. This took about 40 minutes to run on a Samsung Galaxy Tab. Not too bad, but I would've liked it to be in the 30 minute range. Obviously, faster tablets will have a higher throughput.

Monkey is random, so when we first started running monkey every developer was getting different results and we were unable to reproduce defects. We then figured out that monkey allows you to set the seed for it's random number generator. So, configure your wrapper script to set monkey's seed. This will ensure uniformity and predictability across monkey runs in your development team.

Lastly, once you gain confidence in your app with a specific seed value, change it, you'll never know what monkey will find.

Below is a monkey script wrapper, and a description of its arguments.

• -p package name will ensure that monkey only targets the package specified • --throttle is the delay between events

• -s is the seed value • -v is the verbose option

• 50000 is the number of event monkey will simulate. Example 3-11.

#!/bin/bash

# Utility script to run monkey #

# See: http://developer.android.com/guide/developing/tools/monkey.html rm tmp/monkey.log

adb shell monkey -p package.name.here --throttle 100 -s 43686 -v 50000 | tee tmp/monkey.log There are many more configuration options for monkey, we deliberately chose not to mess around with what types of events monkey generates because we appreciate the pain. For example, the seed value we chose causes monkey to disable Wifi about half- way through the run. This was really frustrating at first because we felt like we weren't getting the coverage we wanted. Turns out, monkey did us a favor by disabling Wifi and then relentlessly playing with our app. After discovering and fixing a few defects, we soon had complete confidence that our app operated as expected with no network connection.

Good monkey.

See Also

http://developer.android.com/guide/developing/tools/monkey.html