android testing: an overview

37
An Overview of Android Testing Eric Oestrich BohConf 7/19/2013

Upload: smartlogic

Post on 06-May-2015

1.954 views

Category:

Technology


1 download

DESCRIPTION

A brief overview of android testing from SmartLogic's Eric Oestrich.

TRANSCRIPT

Page 1: Android Testing: An Overview

An Overview of Android Testing

Eric Oestrich

BohConf7/19/2013

Page 3: Android Testing: An Overview

You can test Android?

Page 4: Android Testing: An Overview

Regular Android testing leaves a lot to be

desired

Page 5: Android Testing: An Overview

Robolectrichttp://robolectric.org/

Page 6: Android Testing: An Overview

Run tests on your development machine

Page 7: Android Testing: An Overview

JUnit 4

Page 8: Android Testing: An Overview

Requires Maven

Page 9: Android Testing: An Overview

IntelliJSupports maven projects

Page 10: Android Testing: An Overview

EclipseShould just use IntelliJ

Page 11: Android Testing: An Overview

Android StudioUses gradle, not much support for

this yet

Page 12: Android Testing: An Overview

Downsides

Page 13: Android Testing: An Overview

Content Providers are still hard to test

Page 14: Android Testing: An Overview

Still somewhat newNot every area is able to be tested

nicely

Page 15: Android Testing: An Overview

Lack of Documentation

Page 16: Android Testing: An Overview

Extra Libraries You Should Consider

Page 17: Android Testing: An Overview

Hamcresthttp://hamcrest.org/JavaHamcrest/

Page 18: Android Testing: An Overview

Hamcrest● Nicer assertions than regular JUnit

Page 19: Android Testing: An Overview

HamcrestassertThat(item.getId(), equalTo(itemId));

Page 20: Android Testing: An Overview

FEST Androidhttps://github.com/square/fest-android

Page 21: Android Testing: An Overview

FEST Android● Fluent assertions make test read nicely● FEST additions specific to Android

Page 22: Android Testing: An Overview

FEST Android

assertThat(view.getVisibility(), equalTo(View.GONE));

vs

assertThat(view).isGone();

Page 23: Android Testing: An Overview

Awaitilityhttps://code.google.com/p/awaitility/

Page 24: Android Testing: An Overview

Awaitility● Handles testing asynchronous code nicely● Set timeouts

Page 25: Android Testing: An Overview

Awaitilitypublic void testActivityTitle() {

await().atMost(TIMEOUT_SECONDS, TimeUnit.SECONDS).until(

activityTitle(), equalTo("Notification"));

Spoon.screenshot(getActivity(), "activity_title");

}

Page 26: Android Testing: An Overview

Awaitilityprotected Callable<String> activityTitle() {

return new Callable<String>() {

@Override

public String call() throws Exception {

return mActivity.getTitle().toString();

}

};

}

Page 27: Android Testing: An Overview

Spoonhttps://github.com/square/spoon

Page 28: Android Testing: An Overview

Spoon● Take screenshots of app during test● Compiles to animated gif● Instrumentation tests

Page 29: Android Testing: An Overview

Spoonpublic void testActivity() {

Spoon.screenshot(getActivity(), "activity");

}

Page 30: Android Testing: An Overview

Spoon

http://square.github.io/spoon/sample/index.html

Page 31: Android Testing: An Overview

Continuous Integration

Page 32: Android Testing: An Overview

Jenkins Shell Scriptexport ANDROID_HOME=/var/lib/jenkins/tools/android-sdkmvn clean test --batch-mode

Page 33: Android Testing: An Overview

Javadocs

Page 34: Android Testing: An Overview

JUnit Results