Testing in Android: automatici, di integrazione, TDD e scenari avanzati

download Testing in Android: automatici, di integrazione, TDD e scenari avanzati

If you can't read please download the document

Transcript of Testing in Android: automatici, di integrazione, TDD e scenari avanzati

Who am I

32 years old happy software developer

Mobile addictedAndroid enthusiasticFree software fan

and Tiramisu' lover

rainbowbreeze

Overview

Setup the environmentTest with Junit 3Test with special Android mocksAndroid monkey and monkeyrunner

External libraries: RobotiumTDD with RobolectricExample of advanced scenario

Setup the environment

http://developer.android.com/guide/topics/testing/testing_android.html

Test with Junit 3

Create a class that extends TestCase

Code first test

Run it!

http://developer.android.com/resources/tutorials/testing/helloandroid_test.html

Test with special Android Mock

AndroidTestCase(mock context, MoreAsserts)

http://developer.android.com/reference/android/test/AndroidTestCase.htmlhttp://developer.android.com/reference/android/test/MoreAsserts.html http://developer.android.com/reference/android/test/IsolatedContext.html

Test with special Android Mock

ApplicationTestCase(mock context)

http://developer.android.com/reference/android/test/ApplicationTestCase.html

Test with special Android Mock

ActivityInstrumentationTestCase2(mock intent)ActivityUnitTestCase(mock context and application)SingleLaunchActivityTestCase(single environment thru tests)ViewAsserts(extended asserts)

http://developer.android.com/guide/topics/testing/activity_testing.html http://developer.android.com/resources/tutorials/testing/activity_test.htmlhttp://developer.android.com/reference/android/test/ViewAsserts.html

Test with special Android Mock

ProviderTestCase2(mock ontext and application, MockContentResolver)

http://developer.android.com/guide/topics/testing/contentprovider_testing.html

Test with special Android Mock

ServiceTestCase(mock context and application)test the service lifecycle, not the logic (detached)

http://developer.android.com/guide/topics/testing/service_testing.html

Test with special Android Mock

MockApplication, MockContext, MockContentProvider (API8), MockCursor (API8), MockDialogInterface, MockPackageManager, MockResources

MockContentResolver, IsolatedContext

Android monkey

adb shell monkey -p your.package.name -v 500

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

Android monkeyrunner

monkeyrunnerwriting programs that control an Android device or emulator from outside of Android code. With monkeyrunner, you can write a Python program that installs an Android application or test package, runs it, sends keystrokes to it, takes screenshots of its user interface, and stores screenshots on the workstation

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

Robotium

Automatic black-box test cases for Android applicationsYour applications or black-box apk

http://code.google.com/p/robotium/

TDD with Robolectric

Robolectric is a unit test framework that de-fangs the Android SDK jar so you can test-drive the development of your Android app.TDD also for Android (yuppi)!Shadow objects (stock and custom)Integrable with RoboGuice for IoC/DI

http://pivotal.github.com/robolectric/

Example of advanced scenario

Created a framework for test automationNow QA write XML files corresponding to specific test casesDrastic time redution: from days to 30 minutesFree software!

Link to website

Example of advanced scenario

Complex and boring test cases to verify upon each release of the product / user storiesAndroid / Blackberry / iPhone testsJunit for logic, but for server integration / different OSes capabilites?

Example of advanced scenario

Redefined InstrumentationTestRunner, the new one load xml files and all the tests resourcesRobot and CommandRunnerXml files define tests to executeIt's code, so... Let's the fun begin! ;)

https://android-client.forge.funambol.org/

Click to edit the title text format

Click to edit the outline text formatSecond Outline LevelThird Outline LevelFourth Outline LevelFifth Outline LevelSixth Outline LevelSeventh Outline LevelEighth Outline LevelNinth Outline Level

Testing in AndroidAlfredo Morresi (http://www.rainbowbreeze.it)

Slide