testing android application, droidcon torino

14
Pierto Alberto Rossi Testing Android Application

Upload: pietro-alberto-rossi

Post on 13-Jun-2015

145 views

Category:

Engineering


3 download

DESCRIPTION

This presentation talks about the basis of testing android application. It was presented at Droidcon Turin in 2014.

TRANSCRIPT

Page 1: Testing Android Application, Droidcon Torino

Pierto Alberto Rossi

Testing Android Application

Page 2: Testing Android Application, Droidcon Torino

About me➔ Android Developer for

hobby

➔ Kebab and Pizza dependent

➔ Always on a diet

➔ I don’t speak any-language

Page 3: Testing Android Application, Droidcon Torino

About me

Systems Engineer at Mosaicoon

We do marketing and software development for clients such as

Page 4: Testing Android Application, Droidcon Torino

Agenda

• Android• Android +1• Why testing application?• What to test• Testing Fundamentals• Create TestProject• Testing API• Code Sample

Page 5: Testing Android Application, Droidcon Torino

Why testing application?

If possible, reduce number of bugs before production version

not testing

Page 6: Testing Android Application, Droidcon Torino

What to test

• Change in orientation• Is the screen re-draw correctly? Any custom UI code you have

should handle changes in orientation• Does the application maintain its state? The Activity should not lose

anything that the user has already entered into the UI. The application should not "forget" its place in the current transaction.

• Change in configuration• Change in the availability of a keyboard or a change in system language

Page 7: Testing Android Application, Droidcon Torino

What to test

• Battery life• A device has finite "battery budget", and when it is gone, the device is useless

until it is recharged. You need to write your application to minimize battery usage, you need to test its battery performance, and you need to test the methods that manage battery usage.

• Dependence on external resources• If your application depends on network access, SMS, Bluetooth, or GPS, then

you should test what happens when the resource or resources are not available.

Page 8: Testing Android Application, Droidcon Torino

Testing fundamentals

The android testing framework provides an architecture and powerful tools that help you test every aspect of your application at every level from unit to framework.

Android test suites are base on JUnit.

Test suites are contained in test packages that are similar to main application packages, so you don’t need to learn a new set of tools or techniques for desining and building tests.

The SDK tools for building and tests are available in Eclipse with ADT, and also in command-line form for use with other IDEs.

Page 9: Testing Android Application, Droidcon Torino

Testing fundamentals

The Android JUnit extensions provide component-specific test case classes.These classes provide helper methods for creating mock objects and methods that help you control the lifecycle of a component.

The SDK also provides monkeyrunner, an API for testing devices with Python programs, and UI/Application Exercizer Monkey, a command-line tool for stress-testing UIs by sending pseudo-random events to a device.

Page 10: Testing Android Application, Droidcon Torino

Testing API

Junit You can use the Junit TestCase class to do unit testing on a class

that doesn’t call Android APIs. AndroidTestCase is a class to do unit testing on Android-dependent

objects. To display any test result you can use the Junit Assert class.

Instrumentation Android instrummentation is a set of control methods or “hooks” in

the Android system. These hooks control an Android component indipendently of its normal lifecycle.

They also control how Android loads applications. With Android instrumentation you can invoke callback methods in

your test code.

Page 11: Testing Android Application, Droidcon Torino

Testing API

There are many class for testing TestCase

ActivityUnitTestCase

SingleLaunchActivityTestCase

ActivityInstrumentationTestCase2

and so on…

Page 12: Testing Android Application, Droidcon Torino

Example

Page 13: Testing Android Application, Droidcon Torino

Espresso

The core API is small, predictable, and easy to learn and yet remains open for customization. Espresso tests state expectations, interactions, and assertions clearly without the distraction of boilerplate content, custom infrastructure, or messy implementation details getting in the way.

Espresso tests run optimally fast! Leave your waits, syncs, sleeps, and polls behind and let Espresso gracefully manipulate and assert on the application UI when it is at rest. Enjoy writing and executing your tests today - try a shot of Espresso!