Your SlideShare is downloading. ×
0
안드로이드 앱의 성능 테스트,
자동화가 가능할까?
이경민 / LG전자
About Me
About Me

Android Platform
About Me

Android Platform
SDK
About Me

Android Platform

SDET

SDK
About Me

webOS

Android Platform

SDET

SDK
About Me

webOS

Android Platform

SDET
Test Automation

SDK
About Me

webOS
kandroid.org

Android Platform

SDET

Test Automation

SDK
About Me

webOS
kandroid.org

Android Platform

SDET

SDK

Test Automation
snailee
CONTENTS
Why Automated Performance Testing?
How to Automate Performance Testing?
- Historical Analysis w/ kmemtracer
- Mea...
Why Automated Performance Testing?
If you can’t measure it,
you can’t manage it.
Peter F. Drucker
(1909~2005)
If you can’t measure it,
you can’t manage it.
Peter F. Drucker
(1909~2005)

If you can’t automate
the measurement of it,
i...
Diversity or Fragmentation
Platform
Versions

http://developer.android.com/about/dashboards/index.html
Diversity or Fragmentation
Platform
Versions

Screen Sizes
and Densities

http://developer.android.com/about/dashboards/in...
http://www.mactrast.com/2012/05/visualized-the-truth-about-android-fragmentation/
How to Automate Performance Testing?
- Historical Analysis w/ kmemtracer
- Measuring Performance
- Controlling UI
Why Historical Analysis?

Source: Memory and Performance at the 11th Korea Android Conference
Why Historical Analysis?

Source: Memory and Performance at the 11th Korea Android Conference
Why Historical Analysis?

Activity
Navigation
& Lifecycle
Source: Memory and Performance at the 11th Korea Android Confere...
How to Track Activity Navigation & Lifecycle?
How to Track Activity Navigation & Lifecycle?

Override onCreate, onStart, …
of your Activity classes
How to Track Activity Navigation & Lifecycle?

Modify android.app.Activity
in the framework
How to Track Activity Navigation & Lifecycle?

Is there a way that does not
require the modification of
an application or ...
How to Track Activity Navigation & Lifecycle?

Is there a way that does not
require the modification of
an application or ...
Android instrumentation is a set of control methods
or "hooks" in the Android system.
These hooks control an Android compo...
Historical Analysis w/ kmemtracer
Application
Package

Control
android.test.
Instrumentation
TestRunner

Test
Package
Historical Analysis w/ kmemtracer
https://github.com/snailee/kmemtracer-libs

Application
Package

Control

Track

android...
android.app.Instrumentation
void
void
void
void
void
void
void
void
void
void
void
void
void

callActivityOnCreate(Activit...
android.app.Instrumentation
void
void
void
void
void
void
void
void
void
void
void
void
void

callActivityOnCreate(Activit...
android.app.Instrumentation
void
void
void
void
void
void
void
void
void
void
void
void
void

callActivityOnCreate(Activit...
org.kandroid.memtracer.MemoryInstrumentation
public class MemoryInstrumentation extends Instrumentation {
private static f...
How to Use kmemtracer?
How to Use kmemtracer?
1. Create an Android Test Project for the trace package.
How to Use kmemtracer?
1. Create an Android Test Project for the trace package.
2. Add ‘kmemtracer-libs.jar’ in the ‘libs’...
How to Use kmemtracer?
1. Create an Android Test Project for the trace package.
2. Add ‘kmemtracer-libs.jar’ in the ‘libs’...
How to Use kmemtracer?
4. Install the trace package as well as the application package.
$ adb install –r ApiDemos.apk
$ ad...
How to Use kmemtracer?
4. Install the trace package as well as the application package.
$ adb install –r ApiDemos.apk
$ ad...
How to Use kmemtracer?
4. Install the trace package as well as the application package.
$ adb install –r ApiDemos.apk
$ ad...
How to Use kmemtracer?
4. Install the trace package as well as the application package.
$ adb install –r ApiDemos.apk
$ ad...
How to Use kmemtracer?
8. Open the trace file with Excel and create charts.
How to Automate Performance Testing?
- Historical Analysis w/ kmemtracer
- Measuring Performance
- Controlling UI
What to Measure?

Rendering (or GUI) Performance
Frame Rate (FPS), Frame Time , Jankiness, Input Latency, …

Resource Cons...
What to Measure?

Rendering (or GUI) Performance
Frame Rate (FPS), Frame Time , Jankiness, Input Latency, …

Resource Cons...
How to Measure Resource Consumption?
How to Measure Resource Consumption?

API

cmds
How to Measure Resource Consumption?

cmds

API

Public

Internal
How to Measure Resource Consumption?

cmds

API

Public

Internal

Android

Linux
How to Measure Resource Consumption?

cmds

API

Public

Easy

Internal

Android

Linux

Flexible
Measuring Memory Usage
Measuring Memory Usage
Public
android.app.ActivityManager.MemoryInfo
android.os.Debug
android.os.Debug.MemoryInfo
Measuring Memory Usage
Public

Internal

android.app.ActivityManager.MemoryInfo
android.os.Debug
android.os.Debug.MemoryIn...
Measuring Memory Usage
Public

Internal

Android

android.app.ActivityManager.MemoryInfo
android.os.Debug
android.os.Debug...
Measuring Memory Usage
Public

Internal

Android

Linux

android.app.ActivityManager.MemoryInfo
android.os.Debug
android.o...
Measuring CPU Usage
Measuring CPU Usage
Public
android.os.Process
android.os.Debug.InstructionCount
Measuring CPU Usage
Public

Internal

android.os.Process
android.os.Debug.InstructionCount

com.android.internal.os.Proces...
Measuring CPU Usage
Public

Internal

Android

android.os.Process
android.os.Debug.InstructionCount

com.android.internal....
Measuring CPU Usage
Public

Internal

Android

android.os.Process
android.os.Debug.InstructionCount

com.android.internal....
Measuring I/O Usage
Measuring I/O Usage
Public
android.net.TrafficStats
Measuring I/O Usage
Public

Internal

android.net.TrafficStats
android.net.NetworkStats
android.net.NetworkStatsHistory
Measuring I/O Usage
Public

Internal

Android

android.net.TrafficStats
android.net.NetworkStats
android.net.NetworkStatsH...
Measuring I/O Usage
Public

Internal

Android

android.net.TrafficStats
android.net.NetworkStats
android.net.NetworkStatsH...
Measuring Battery Usage
Measuring Battery Usage
Public
android.os.BatteryManager
Measuring Battery Usage
Public

Internal

android.os.BatteryManager

android.os.BatteryStats
com.android.internal.os.Power...
Measuring Battery Usage
Public

Internal

Android

android.os.BatteryManager

android.os.BatteryStats
com.android.internal...
Measuring Battery Usage
Public

Internal

Android

android.os.BatteryManager

android.os.BatteryStats
com.android.internal...
Tracing Performance Snapshots in kmemtracer
public class MemoryInstrumentation extends Instrumentation {
Tracing Performance Snapshots in kmemtracer
public class MemoryInstrumentation extends Instrumentation {
...
private Memor...
Tracing Performance Snapshots in kmemtracer
public class MemoryInstrumentation extends Instrumentation {
...
private Memor...
MemoryTracer$addSnapshot
public Bundle addSnapshot(String label) {
MemoryTracer$addSnapshot
public Bundle addSnapshot(String label) {
...
long nativeMax = Debug.getNativeHeapSize() / 1024;
...
MemoryTracer$addSnapshot
public Bundle addSnapshot(String label) {
...
long nativeMax = Debug.getNativeHeapSize() / 1024;
...
MemoryTracer$addSnapshot
public Bundle addSnapshot(String label) {
...
long nativeMax = Debug.getNativeHeapSize() / 1024;
...
MemoryTracerCsvWriter$writeTraceSnapshot
public class MemoryTraceCsvWriter implements MemoryTracer.ResultsWriter {
MemoryTracerCsvWriter$writeTraceSnapshot
public class MemoryTraceCsvWriter implements MemoryTracer.ResultsWriter {
...
pub...
MemoryTracerCsvWriter$writeTraceSnapshot
public class MemoryTraceCsvWriter implements MemoryTracer.ResultsWriter {
...
pub...
MemoryTracerCsvWriter$writeTraceSnapshot
public class MemoryTraceCsvWriter implements MemoryTracer.ResultsWriter {
...
pub...
To Do’s
To Do’s

Add more tracers
CpuTracer
IOTracer
BatteryTracer
To Do’s

Add more tracers
CpuTracer
IOTracer
BatteryTracer

Make metrics to gather configurable
To Do’s

Add more tracers
CpuTracer
IOTracer
BatteryTracer

Make metrics to gather configurable
Make trace output destinat...
To Do’s

Add more tracers
CpuTracer
IOTracer
BatteryTracer

Make metrics to gather configurable
Make trace output destinat...
How to Automate Performance Testing?
- Historical Analysis w/ kmemtracer
- Measuring Performance
- Controlling UI
Automate Controlling UI
Application
Package

Control

Track

android.test.
Instrumentation
TestRunner

org.kandroid.
memtr...
Automate Controlling UI
Application
Package

Control

Track

android.test.
Instrumentation
TestRunner

org.kandroid.
memtr...
Automate Controlling UI
Application
Package

Control

Track

android.test.
Instrumentation
TestRunner

org.kandroid.
memtr...
Three Alternatives
Three Alternatives

Instrumentation
API Level 1 ~
Single activity
Framework APIs
White-box

http://developer.android.com/t...
Three Alternatives

Instrumentation
API Level 1 ~
Single activity
Framework APIs
White-box

Robotium
2010/01 ~
Multiple ac...
Three Alternatives

Instrumentation
API Level 1 ~
Single activity
Framework APIs
White-box

Robotium
uiautomator
2010/01 ~...
Case Study: ApiDemos
https://github.com/snailee/deview-2013-samples
Case Study: ApiDemos
https://github.com/snailee/deview-2013-samples

Click
Case Study: ApiDemos
https://github.com/snailee/deview-2013-samples

Click
Case Study: ApiDemos
https://github.com/snailee/deview-2013-samples

Click

Scroll
down
Case Study: ApiDemos
https://github.com/snailee/deview-2013-samples

Click

Scroll
down
Case Study: ApiDemos
https://github.com/snailee/deview-2013-samples

Click

Scroll
down
Click
Case Study: ApiDemos
https://github.com/snailee/deview-2013-samples

Click

Scroll
down
Click
Case Study: ApiDemos
https://github.com/snailee/deview-2013-samples

Click

Scroll
down
Click

Click
Case Study: ApiDemos
https://github.com/snailee/deview-2013-samples

Click

Scroll
down
Click

Click
Controlling UI Using Instrumentation
Controlling UI Using Instrumentation
1. Create an Android Test Project for the test package.
$ android create test-project...
Controlling UI Using Instrumentation
1. Create an Android Test Project for the test package.
$ android create test-project...
Controlling UI Using Instrumentation
1. Create an Android Test Project for the test package.
$ android create test-project...
Controlling UI Using Instrumentation
4. Find and act on a control.
public void testNavigate() {
Controlling UI Using Instrumentation
4. Find and act on a control.

Find a view
to control

public void testNavigate() {
....
Controlling UI Using Instrumentation
4. Find and act on a control.

Find a view
to control

public void testNavigate() {
....
Controlling UI Using Instrumentation
4. Find and act on a control.

Find a view
to control

public void testNavigate() {
....
Controlling UI Using Instrumentation
4. Find and act on a control: getChildViewByText.
private View getChildViewByText(Lis...
Controlling UI Using Instrumentation
4. Find and act on a control: getChildViewByText.
private View getChildViewByText(Lis...
Controlling UI Using Instrumentation
4. Find and act on a control: getChildViewByText.
private View getChildViewByText(Lis...
Controlling UI Using Instrumentation
4. Find and act on a control: getChildViewByText.
private View getChildViewByText(Lis...
Controlling UI Using Instrumentation
4. Find and act on a control: getChildViewByText.
private View getChildViewByText(Lis...
Controlling UI Using Instrumentation
4. Find and act on a control: Revised getChildViewByText.
private View getChildViewBy...
Controlling UI Using Instrumentation
4. Find and act on a control: Revised getChildViewByText.
private View getChildViewBy...
Controlling UI Using Instrumentation
5. Monitor a new Activity to launch.
public void testNavigate() {
...
Instrumentation...
Controlling UI Using Instrumentation
5. Monitor a new Activity to launch.
public void testNavigate() {
...
Instrumentation...
Controlling UI Using Instrumentation
7. Build and Install the test package.
$ cd ApiDemosInstrumentTest
$ ant debug
$ adb ...
Controlling UI Using Instrumentation
7. Build and Install the test package.
$ cd ApiDemosInstrumentTest
$ ant debug
$ adb ...
Controlling UI Using Instrumentation
7. Build and Install the test package.
$ cd ApiDemosInstrumentTest
$ ant debug
$ adb ...
Controlling UI Using Robotium
Controlling UI Using Robotium
1. Create an Android Test Project for the test package.
$ android create test-project --main...
Controlling UI Using Robotium
1. Create an Android Test Project for the test package.
$ android create test-project --main...
Controlling UI Using Robotium
1. Create an Android Test Project for the test package.
$ android create test-project --main...
Controlling UI Using Robotium
4. Create an instance of Solo in the setUp method and
close open activities in the tearDown ...
Controlling UI Using Robotium
4. Find and act on a control.
public void testNavigate() {
solo.assertCurrentActivity("Shoul...
Controlling UI Using Robotium
6. Build and Install the test package.
$ cd ApiDemosRobotiumTest
$ ant debug
$ adb install –...
Controlling UI Using Robotium
6. Build and Install the test package.
$ cd ApiDemosRobotiumTest
$ ant debug
$ adb install –...
Controlling UI Using Robotium
6. Build and Install the test package.
$ cd ApiDemosRobotiumTest
$ ant debug
$ adb install –...
Controlling UI Using uiautomator
1. Create an Java Project for the test jar.
Controlling UI Using uiautomator
1. Create an Java Project for the test jar.
2. Add ‘android.jar’ and ‘uiautomator.jar’ in...
Controlling UI Using uiautomator
1. Create an Java Project for the test jar.
2. Add ‘android.jar’ and ‘uiautomator.jar’ in...
Controlling UI Using uiautomator
4. Launch ApiDemos.
public void testNavigate() throws UiObjectNotFoundException {
Controlling UI Using uiautomator
4. Launch ApiDemos.
public void testNavigate() throws UiObjectNotFoundException {
getUiDe...
Controlling UI Using uiautomator
4. Launch ApiDemos.
public void testNavigate() throws UiObjectNotFoundException {
getUiDe...
Controlling UI Using uiautomator
4. Launch ApiDemos.
public void testNavigate() throws UiObjectNotFoundException {
getUiDe...
Controlling UI Using uiautomator
4. Launch ApiDemos.
public void testNavigate() throws UiObjectNotFoundException {
getUiDe...
Controlling UI Using uiautomator
4. Launch ApiDemos.
public void testNavigate() throws UiObjectNotFoundException {
getUiDe...
Controlling UI Using uiautomator
5. Find and act on a control.
Controlling UI Using uiautomator
5. Find and act on a control.
...
UiScrollable demoList = new UiScrollable(
new UiSelecto...
Controlling UI Using uiautomator
5. Find and act on a control.
...
UiScrollable demoList = new UiScrollable(
new UiSelecto...
Controlling UI Using uiautomator
5. Find and act on a control.
...
UiScrollable demoList = new UiScrollable(
new UiSelecto...
Controlling UI Using uiautomator
5. Find and act on a control.
...
UiScrollable demoList = new UiScrollable(
new UiSelecto...
Controlling UI Using uiautomator
5. Find and act on a control.
...
UiScrollable demoList = new UiScrollable(
new UiSelecto...
Controlling UI Using uiautomator
7. Compile your test case into a JAR file.
$
>
$
$

android create uitest-project --name ...
Controlling UI Using uiautomator
7. Compile your test case into a JAR file.
$
>
$
$

android create uitest-project --name ...
Controlling UI Using uiautomator
7. Compile your test case into a JAR file.
$
>
$
$

android create uitest-project --name ...
Controlling UI Using uiautomator
7. Compile your test case into a JAR file.
$
>
$
$

android create uitest-project --name ...
Controlling UI Using uiautomator
7. Compile your test case into a JAR file.
$
>
$
$

android create uitest-project --name ...
Doing both Controlling and Tracking
Doing both Controlling and Tracking
1. Modify org.kandroid.memtracer.MemoryInstrumentation.
public class MemoryInstrumenta...
Doing both Controlling and Tracking
1. Modify org.kandroid.memtracer.MemoryInstrumentation.
public class MemoryInstrumenta...
Doing both Controlling and Tracking
1. Modify org.kandroid.memtracer.MemoryInstrumentation.
public class MemoryInstrumenta...
Doing both Controlling and Tracking
1. Modify org.kandroid.memtracer.MemoryInstrumentation.
public class MemoryInstrumenta...
Doing both Controlling and Tracking
2. Add ‘kmemtracer-libs.jar’ in the ‘libs’ directory.
Doing both Controlling and Tracking
2. Add ‘kmemtracer-libs.jar’ in the ‘libs’ directory.
3. Edit the <instrumentation> el...
Doing both Controlling and Tracking
2. Add ‘kmemtracer-libs.jar’ in the ‘libs’ directory.
3. Edit the <instrumentation> el...
Doing both Controlling and Tracking
2. Add ‘kmemtracer-libs.jar’ in the ‘libs’ directory.
3. Edit the <instrumentation> el...
Doing both Controlling and Tracking
2. Add ‘kmemtracer-libs.jar’ in the ‘libs’ directory.
3. Edit the <instrumentation> el...
SUMMARY
SUMMARY
Why Automated Performance Testing?
Measure to improve / Fragmentation
SUMMARY
Why Automated Performance Testing?
Measure to improve / Fragmentation

How to Automate Performance Testing?
- Hist...
SUMMARY
Why Automated Performance Testing?
Measure to improve / Fragmentation

How to Automate Performance Testing?
- Hist...
SUMMARY
Why Automated Performance Testing?
Measure to improve / Fragmentation

How to Automate Performance Testing?
- Hist...
Q&A
THANK YOU
DEVIEW2013: Automating Performance Tests for Android Applications
Upcoming SlideShare
Loading in...5
×

DEVIEW2013: Automating Performance Tests for Android Applications

4,934

Published on

Published in: Technology
0 Comments
6 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
4,934
On Slideshare
0
From Embeds
0
Number of Embeds
12
Actions
Shares
0
Downloads
130
Comments
0
Likes
6
Embeds 0
No embeds

No notes for slide

Transcript of "DEVIEW2013: Automating Performance Tests for Android Applications"

  1. 1. 안드로이드 앱의 성능 테스트, 자동화가 가능할까? 이경민 / LG전자
  2. 2. About Me
  3. 3. About Me Android Platform
  4. 4. About Me Android Platform SDK
  5. 5. About Me Android Platform SDET SDK
  6. 6. About Me webOS Android Platform SDET SDK
  7. 7. About Me webOS Android Platform SDET Test Automation SDK
  8. 8. About Me webOS kandroid.org Android Platform SDET Test Automation SDK
  9. 9. About Me webOS kandroid.org Android Platform SDET SDK Test Automation snailee
  10. 10. CONTENTS Why Automated Performance Testing? How to Automate Performance Testing? - Historical Analysis w/ kmemtracer - Measuring Performance - Controlling UI
  11. 11. Why Automated Performance Testing?
  12. 12. If you can’t measure it, you can’t manage it. Peter F. Drucker (1909~2005)
  13. 13. If you can’t measure it, you can’t manage it. Peter F. Drucker (1909~2005) If you can’t automate the measurement of it, it is difficult to improve it.
  14. 14. Diversity or Fragmentation Platform Versions http://developer.android.com/about/dashboards/index.html
  15. 15. Diversity or Fragmentation Platform Versions Screen Sizes and Densities http://developer.android.com/about/dashboards/index.html
  16. 16. http://www.mactrast.com/2012/05/visualized-the-truth-about-android-fragmentation/
  17. 17. How to Automate Performance Testing? - Historical Analysis w/ kmemtracer - Measuring Performance - Controlling UI
  18. 18. Why Historical Analysis? Source: Memory and Performance at the 11th Korea Android Conference
  19. 19. Why Historical Analysis? Source: Memory and Performance at the 11th Korea Android Conference
  20. 20. Why Historical Analysis? Activity Navigation & Lifecycle Source: Memory and Performance at the 11th Korea Android Conference
  21. 21. How to Track Activity Navigation & Lifecycle?
  22. 22. How to Track Activity Navigation & Lifecycle? Override onCreate, onStart, … of your Activity classes
  23. 23. How to Track Activity Navigation & Lifecycle? Modify android.app.Activity in the framework
  24. 24. How to Track Activity Navigation & Lifecycle? Is there a way that does not require the modification of an application or framework?
  25. 25. How to Track Activity Navigation & Lifecycle? Is there a way that does not require the modification of an application or framework? Instrumentation
  26. 26. Android instrumentation is a set of control methods or "hooks" in the Android system. These hooks control an Android component independently of its normal lifecycle. They also control how Android loads applications. (http://developer.android.com/tools/testing/testing_android.html)
  27. 27. Historical Analysis w/ kmemtracer Application Package Control android.test. Instrumentation TestRunner Test Package
  28. 28. Historical Analysis w/ kmemtracer https://github.com/snailee/kmemtracer-libs Application Package Control Track android.test. Instrumentation TestRunner org.kandroid. memtracer.Memory Instrumentation Test Package Trace Package
  29. 29. android.app.Instrumentation void void void void void void void void void void void void void callActivityOnCreate(Activity, Bundle) callActivityOnDestroy(Activity) callActivityOnNewIntent(Activity, Intent) callActivityOnPause(Activity) callActivityOnPostCreate(Activity, Bundle) callActivityOnRestart(Activity) callActivityOnRestoreInstanceState(Activity, Bundle) callActivityOnResume(Activity) callActivityOnSaveInstanceState(Activity, Bundle) callActivityOnStart(Activity) callActivityOnStop(Activity) callActivityOnUserLeaving(Activity) callApplicationOnCreate(Application)
  30. 30. android.app.Instrumentation void void void void void void void void void void void void void callActivityOnCreate(Activity, Bundle) callActivityOnDestroy(Activity) callActivityOnNewIntent(Activity, Intent) callActivityOnPause(Activity) callActivityOnPostCreate(Activity, Bundle) callActivityOnRestart(Activity) callActivityOnRestoreInstanceState(Activity, Bundle) callActivityOnResume(Activity) callActivityOnSaveInstanceState(Activity, Bundle) callActivityOnStart(Activity) callActivityOnStop(Activity) callActivityOnUserLeaving(Activity) callApplicationOnCreate(Application) Call for Control
  31. 31. android.app.Instrumentation void void void void void void void void void void void void void callActivityOnCreate(Activity, Bundle) callActivityOnDestroy(Activity) callActivityOnNewIntent(Activity, Intent) callActivityOnPause(Activity) callActivityOnPostCreate(Activity, Bundle) callActivityOnRestart(Activity) callActivityOnRestoreInstanceState(Activity, Bundle) callActivityOnResume(Activity) callActivityOnSaveInstanceState(Activity, Bundle) callActivityOnStart(Activity) callActivityOnStop(Activity) callActivityOnUserLeaving(Activity) callApplicationOnCreate(Application) Call for Control Override for Track
  32. 32. org.kandroid.memtracer.MemoryInstrumentation public class MemoryInstrumentation extends Instrumentation { private static final String ARGUMENT_INSTRUMENT_CLASS = "class"; private MemoryTracer mMemoryTracer; private String mMainActivityName; ... @Override public void onCreate(Bundle arguments) { mMainActivityName = arguments.getString(ARGUMENT_INSTRUMENT_CLASS); mMemoryTracer = createMemoryTracer(); mMemoryTracer.startTracing(getTargetContext().getPackageName()); start(); } @Override public void callActivityOnCreate(Activity activity, Bundle icicle) { String tag = activity.getLocalClassName()+"-OnCreate"; Bundle snapshot = mMemoryTracer.addSnapshot(tag); super.callActivityOnCreate(activity, icicle); }
  33. 33. How to Use kmemtracer?
  34. 34. How to Use kmemtracer? 1. Create an Android Test Project for the trace package.
  35. 35. How to Use kmemtracer? 1. Create an Android Test Project for the trace package. 2. Add ‘kmemtracer-libs.jar’ in the ‘libs’ directory.
  36. 36. How to Use kmemtracer? 1. Create an Android Test Project for the trace package. 2. Add ‘kmemtracer-libs.jar’ in the ‘libs’ directory. 3. Edit the <instrumentation> element in the Manifest file. <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.apis.test" android:versionCode="1" android:versionName="1.0"> <instrumentation android:name="org.kandroid.memtracer.MemoryInstrumentation" android:targetPackage="com.example.android.apis" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <application android:label="@string/app_name" android:icon="@drawable/ic_launcher“> <uses-library android:theme="android.text.runner“> </application> </manifest>
  37. 37. How to Use kmemtracer? 4. Install the trace package as well as the application package. $ adb install –r ApiDemos.apk $ adb install –r ApiDemosTest.apk
  38. 38. How to Use kmemtracer? 4. Install the trace package as well as the application package. $ adb install –r ApiDemos.apk $ adb install –r ApiDemosTest.apk 5. Start the instrumentation with ‘am instrument’ in the shell. $ > > > adb shell am instrument -e class com.example.android.apis.ApiDemos com.example.android.apis.tests/ org.kandroid.memtracer.MemoryInstrumentation
  39. 39. How to Use kmemtracer? 4. Install the trace package as well as the application package. $ adb install –r ApiDemos.apk $ adb install –r ApiDemosTest.apk 5. Start the instrumentation with ‘am instrument’ in the shell. $ > > > adb shell am instrument -e class com.example.android.apis.ApiDemos com.example.android.apis.tests/ org.kandroid.memtracer.MemoryInstrumentation 6. Do interact with the application.
  40. 40. How to Use kmemtracer? 4. Install the trace package as well as the application package. $ adb install –r ApiDemos.apk $ adb install –r ApiDemosTest.apk 5. Start the instrumentation with ‘am instrument’ in the shell. $ > > > adb shell am instrument -e class com.example.android.apis.ApiDemos com.example.android.apis.tests/ org.kandroid.memtracer.MemoryInstrumentation 6. Do interact with the application. 7. Pull the trace file ‘kmemtrace.csv’ from /sdcard/kmemtracer. $ adb pull /sdcard/kmemtracer/kmemtrace.csv .
  41. 41. How to Use kmemtracer? 8. Open the trace file with Excel and create charts.
  42. 42. How to Automate Performance Testing? - Historical Analysis w/ kmemtracer - Measuring Performance - Controlling UI
  43. 43. What to Measure? Rendering (or GUI) Performance Frame Rate (FPS), Frame Time , Jankiness, Input Latency, … Resource Consumption Memory, CPU, I/O (Disk, Network), Battery, … Network Performance Response time, Throughput, … …
  44. 44. What to Measure? Rendering (or GUI) Performance Frame Rate (FPS), Frame Time , Jankiness, Input Latency, … Resource Consumption Memory, CPU, I/O (Disk, Network), Battery, … Network Performance Response time, Throughput, … …
  45. 45. How to Measure Resource Consumption?
  46. 46. How to Measure Resource Consumption? API cmds
  47. 47. How to Measure Resource Consumption? cmds API Public Internal
  48. 48. How to Measure Resource Consumption? cmds API Public Internal Android Linux
  49. 49. How to Measure Resource Consumption? cmds API Public Easy Internal Android Linux Flexible
  50. 50. Measuring Memory Usage
  51. 51. Measuring Memory Usage Public android.app.ActivityManager.MemoryInfo android.os.Debug android.os.Debug.MemoryInfo
  52. 52. Measuring Memory Usage Public Internal android.app.ActivityManager.MemoryInfo android.os.Debug android.os.Debug.MemoryInfo dalvik.system.VMDebug
  53. 53. Measuring Memory Usage Public Internal Android android.app.ActivityManager.MemoryInfo android.os.Debug android.os.Debug.MemoryInfo dalvik.system.VMDebug adb shell dumpsys meminfo [pid|pname] adb shell procrank
  54. 54. Measuring Memory Usage Public Internal Android Linux android.app.ActivityManager.MemoryInfo android.os.Debug android.os.Debug.MemoryInfo dalvik.system.VMDebug adb shell dumpsys meminfo [pid|pname] adb shell procrank adb shell cat /proc/meminfo adb shell cat /proc/<pid>/[s]maps adb shell cat /proc/vmstat adb shell top adb shell ps
  55. 55. Measuring CPU Usage
  56. 56. Measuring CPU Usage Public android.os.Process android.os.Debug.InstructionCount
  57. 57. Measuring CPU Usage Public Internal android.os.Process android.os.Debug.InstructionCount com.android.internal.os.ProcessStats
  58. 58. Measuring CPU Usage Public Internal Android android.os.Process android.os.Debug.InstructionCount com.android.internal.os.ProcessStats adb shell dumpsys cpuinfo
  59. 59. Measuring CPU Usage Public Internal Android android.os.Process android.os.Debug.InstructionCount com.android.internal.os.ProcessStats adb shell dumpsys cpuinfo adb shell cat /proc/stat adb shell top Linux
  60. 60. Measuring I/O Usage
  61. 61. Measuring I/O Usage Public android.net.TrafficStats
  62. 62. Measuring I/O Usage Public Internal android.net.TrafficStats android.net.NetworkStats android.net.NetworkStatsHistory
  63. 63. Measuring I/O Usage Public Internal Android android.net.TrafficStats android.net.NetworkStats android.net.NetworkStatsHistory adb shell dumpsys netstats adb shell dumpsys diskstats
  64. 64. Measuring I/O Usage Public Internal Android android.net.TrafficStats android.net.NetworkStats android.net.NetworkStatsHistory adb shell dumpsys netstats adb shell dumpsys diskstats /proc/net/* Linux
  65. 65. Measuring Battery Usage
  66. 66. Measuring Battery Usage Public android.os.BatteryManager
  67. 67. Measuring Battery Usage Public Internal android.os.BatteryManager android.os.BatteryStats com.android.internal.os.PowerProfile
  68. 68. Measuring Battery Usage Public Internal Android android.os.BatteryManager android.os.BatteryStats com.android.internal.os.PowerProfile adb shell dumpsys battery adb shell dumpsys batteryinfo
  69. 69. Measuring Battery Usage Public Internal Android android.os.BatteryManager android.os.BatteryStats com.android.internal.os.PowerProfile adb shell dumpsys battery adb shell dumpsys batteryinfo None (?) Linux
  70. 70. Tracing Performance Snapshots in kmemtracer public class MemoryInstrumentation extends Instrumentation {
  71. 71. Tracing Performance Snapshots in kmemtracer public class MemoryInstrumentation extends Instrumentation { ... private MemoryTracer mMemoryTracer; ... @Override public void onCreate(Bundle arguments) { ... mMemoryTracer = createMemoryTracer(); ... } ... Create an instance of MemoryTracer
  72. 72. Tracing Performance Snapshots in kmemtracer public class MemoryInstrumentation extends Instrumentation { ... private MemoryTracer mMemoryTracer; ... @Override public void onCreate(Bundle arguments) { ... mMemoryTracer = createMemoryTracer(); ... } ... @Override public void callActivityOnCreate(Activity activity, Bundle icicle) { String tag = activity.getLocalClassName()+"-OnCreate"; Bundle snapshot = mMemoryTracer.addSnapshot(tag); ... } ... } Create an instance of MemoryTracer Add performance snapshot
  73. 73. MemoryTracer$addSnapshot public Bundle addSnapshot(String label) {
  74. 74. MemoryTracer$addSnapshot public Bundle addSnapshot(String label) { ... long nativeMax = Debug.getNativeHeapSize() / 1024; long nativeAllocated = Debug.getNativeHeapAllocatedSize() / 1024; long nativeFree = Debug.getNativeHeapFreeSize() / 1024; Debug.MemoryInfo memInfo = new Debug.MemoryInfo(); Debug.getMemoryInfo(memInfo); ... Get usage data
  75. 75. MemoryTracer$addSnapshot public Bundle addSnapshot(String label) { ... long nativeMax = Debug.getNativeHeapSize() / 1024; long nativeAllocated = Debug.getNativeHeapAllocatedSize() / 1024; long nativeFree = Debug.getNativeHeapFreeSize() / 1024; Debug.MemoryInfo memInfo = new Debug.MemoryInfo(); Debug.getMemoryInfo(memInfo); ... Bundle snapshot = new Bundle(); snapshot.putString(METRIC_KEY_LABEL, label); ... snapshot.putLong(METRIC_KEY_NATIVE_SIZE, nativeMax); snapshot.putLong(METRIC_KEY_NATIVE_ALLOCATED, nativeAllocated); snapshot.putLong(METRIC_KEY_NATIVE_FREE, nativeFree); ... Get usage data Save data to a bundle
  76. 76. MemoryTracer$addSnapshot public Bundle addSnapshot(String label) { ... long nativeMax = Debug.getNativeHeapSize() / 1024; long nativeAllocated = Debug.getNativeHeapAllocatedSize() / 1024; long nativeFree = Debug.getNativeHeapFreeSize() / 1024; Debug.MemoryInfo memInfo = new Debug.MemoryInfo(); Debug.getMemoryInfo(memInfo); ... Bundle snapshot = new Bundle(); snapshot.putString(METRIC_KEY_LABEL, label); ... snapshot.putLong(METRIC_KEY_NATIVE_SIZE, nativeMax); snapshot.putLong(METRIC_KEY_NATIVE_ALLOCATED, nativeAllocated); snapshot.putLong(METRIC_KEY_NATIVE_FREE, nativeFree); ... if (mResultsWriter != null) { mResultsWriter.writeTraceSnapshot(snapshot); } return snapshot; } Get usage data Save data to a bundle Write date using ResultsWriter
  77. 77. MemoryTracerCsvWriter$writeTraceSnapshot public class MemoryTraceCsvWriter implements MemoryTracer.ResultsWriter {
  78. 78. MemoryTracerCsvWriter$writeTraceSnapshot public class MemoryTraceCsvWriter implements MemoryTracer.ResultsWriter { ... public MemoryTraceCsvWriter(String[] metricKeys) { mMetricKeys = metricKeys; } ... Create an instance with metrics to print
  79. 79. MemoryTracerCsvWriter$writeTraceSnapshot public class MemoryTraceCsvWriter implements MemoryTracer.ResultsWriter { ... public MemoryTraceCsvWriter(String[] metricKeys) { mMetricKeys = metricKeys; } ... private void openTraceFile(String filename) { ... mTraceOut = new PrintStream(new FileOutputStream(traceFile)); ... } ... Create an instance with metrics to print Open a trace file in the sdcard at init
  80. 80. MemoryTracerCsvWriter$writeTraceSnapshot public class MemoryTraceCsvWriter implements MemoryTracer.ResultsWriter { ... public MemoryTraceCsvWriter(String[] metricKeys) { mMetricKeys = metricKeys; } ... private void openTraceFile(String filename) { ... mTraceOut = new PrintStream(new FileOutputStream(traceFile)); ... } ... @Override public void writeTraceSnapshot(Bundle snapshot) { PrintStream out = mTraceOut; for (String key : mMetricKeys) { out.print(snapshot.get(key)); out.print(','); } out.println(); out.flush(); } ... } Create an instance with metrics to print Open a trace file in the sdcard at init Write snapshot to a line of the file
  81. 81. To Do’s
  82. 82. To Do’s Add more tracers CpuTracer IOTracer BatteryTracer
  83. 83. To Do’s Add more tracers CpuTracer IOTracer BatteryTracer Make metrics to gather configurable
  84. 84. To Do’s Add more tracers CpuTracer IOTracer BatteryTracer Make metrics to gather configurable Make trace output destination configurable Trace out to internal file (not on sdcard) Trace out to an analytics server
  85. 85. To Do’s Add more tracers CpuTracer IOTracer BatteryTracer Make metrics to gather configurable Make trace output destination configurable Trace out to internal file (not on sdcard) Trace out to an analytics server Welcome contributions https://github.com/snailee/kmemtracer-libs
  86. 86. How to Automate Performance Testing? - Historical Analysis w/ kmemtracer - Measuring Performance - Controlling UI
  87. 87. Automate Controlling UI Application Package Control Track android.test. Instrumentation TestRunner org.kandroid. memtracer.Memory Instrumentation Test Package Trace Package
  88. 88. Automate Controlling UI Application Package Control Track android.test. Instrumentation TestRunner org.kandroid. memtracer.Memory Instrumentation Test Package Trace Package
  89. 89. Automate Controlling UI Application Package Control Track android.test. Instrumentation TestRunner org.kandroid. memtracer.Memory Instrumentation Test Package Trace Package
  90. 90. Three Alternatives
  91. 91. Three Alternatives Instrumentation API Level 1 ~ Single activity Framework APIs White-box http://developer.android.com/tools/testing/testing_android.html
  92. 92. Three Alternatives Instrumentation API Level 1 ~ Single activity Framework APIs White-box Robotium 2010/01 ~ Multiple activities High-level APIs White-box & black-box http://developer.android.com/tools/testing/testing_android.html https://code.google.com/p/robotium/
  93. 93. Three Alternatives Instrumentation API Level 1 ~ Single activity Framework APIs White-box Robotium uiautomator 2010/01 ~ Multiple activities API Level 17 ~ High-level APIs White-box & black-box Multiple processes Simple APIs Black-box http://developer.android.com/tools/testing/testing_android.html https://code.google.com/p/robotium/ http://developer.android.com/tools/testing/testing_ui.html
  94. 94. Case Study: ApiDemos https://github.com/snailee/deview-2013-samples
  95. 95. Case Study: ApiDemos https://github.com/snailee/deview-2013-samples Click
  96. 96. Case Study: ApiDemos https://github.com/snailee/deview-2013-samples Click
  97. 97. Case Study: ApiDemos https://github.com/snailee/deview-2013-samples Click Scroll down
  98. 98. Case Study: ApiDemos https://github.com/snailee/deview-2013-samples Click Scroll down
  99. 99. Case Study: ApiDemos https://github.com/snailee/deview-2013-samples Click Scroll down Click
  100. 100. Case Study: ApiDemos https://github.com/snailee/deview-2013-samples Click Scroll down Click
  101. 101. Case Study: ApiDemos https://github.com/snailee/deview-2013-samples Click Scroll down Click Click
  102. 102. Case Study: ApiDemos https://github.com/snailee/deview-2013-samples Click Scroll down Click Click
  103. 103. Controlling UI Using Instrumentation
  104. 104. Controlling UI Using Instrumentation 1. Create an Android Test Project for the test package. $ android create test-project --main ../ApiDemos > –-name ApiDemosInstrumentTest --path ApiDemosInstrumentTest
  105. 105. Controlling UI Using Instrumentation 1. Create an Android Test Project for the test package. $ android create test-project --main ../ApiDemos > –-name ApiDemosInstrumentTest --path ApiDemosInstrumentTest 2. Add a test class inheriting ActivityInstrumentationTestCase2. public class ApiDemosInstrumentTest extends ActivityInstrumentationTestCase2<ApiDemos> { ... public ApiDemosInstrumentTest() { super(ApiDemos.class); }
  106. 106. Controlling UI Using Instrumentation 1. Create an Android Test Project for the test package. $ android create test-project --main ../ApiDemos > –-name ApiDemosInstrumentTest --path ApiDemosInstrumentTest 2. Add a test class inheriting ActivityInstrumentationTestCase2. public class ApiDemosInstrumentTest extends ActivityInstrumentationTestCase2<ApiDemos> { ... public ApiDemosInstrumentTest() { super(ApiDemos.class); } 3. Add a test method and launch the activity. public void testNavigate() { final ApiDemos apiDemos = getActivity(); ... }
  107. 107. Controlling UI Using Instrumentation 4. Find and act on a control. public void testNavigate() {
  108. 108. Controlling UI Using Instrumentation 4. Find and act on a control. Find a view to control public void testNavigate() { ... final ListView demoList = apiDemos.getListView(); final View graphicsDemo = getChildViewByText(demoList, "Graphics"); assertNotNull("Graphics demo should exist", graphicsDemo);
  109. 109. Controlling UI Using Instrumentation 4. Find and act on a control. Find a view to control public void testNavigate() { ... final ListView demoList = apiDemos.getListView(); final View graphicsDemo = getChildViewByText(demoList, "Graphics"); assertNotNull("Graphics demo should exist", graphicsDemo); apiDemos.runOnUiThread(new Runnable() { public void run() { int pos = demoList.getPositionForView(graphicsDemo); demoList.smoothScrollToPosition(pos); demoList.setSelection(pos); demoList.performItemClick(graphicsDemo, pos, graphicsDemo.getId()); } }); ... Act on the view
  110. 110. Controlling UI Using Instrumentation 4. Find and act on a control. Find a view to control public void testNavigate() { ... final ListView demoList = apiDemos.getListView(); final View graphicsDemo = getChildViewByText(demoList, "Graphics"); assertNotNull("Graphics demo should exist", graphicsDemo); apiDemos.runOnUiThread(new Runnable() { public void run() { int pos = demoList.getPositionForView(graphicsDemo); demoList.smoothScrollToPosition(pos); demoList.setSelection(pos); demoList.performItemClick(graphicsDemo, pos, graphicsDemo.getId()); } }); ... Act on the view
  111. 111. Controlling UI Using Instrumentation 4. Find and act on a control: getChildViewByText. private View getChildViewByText(ListView listView, String text) {
  112. 112. Controlling UI Using Instrumentation 4. Find and act on a control: getChildViewByText. private View getChildViewByText(ListView listView, String text) { View view = null; int count = listView.getCount(); Log.e(TAG, “no. children = " + count); for (int i = 0; i < count; i++) { TextView textView = (TextView) listView.getChildAt(i); Log.e(TAG, i + "-th text view is " + textView); Iterate through child views
  113. 113. Controlling UI Using Instrumentation 4. Find and act on a control: getChildViewByText. private View getChildViewByText(ListView listView, String text) { View view = null; int count = listView.getCount(); Log.e(TAG, “no. children = " + count); for (int i = 0; i < count; i++) { TextView textView = (TextView) listView.getChildAt(i); Log.e(TAG, i + "-th text view is " + textView); if (textView != null && textView.getText().equals(text)) { view = textView; break; } Iterate through child views Compare texts
  114. 114. Controlling UI Using Instrumentation 4. Find and act on a control: getChildViewByText. private View getChildViewByText(ListView listView, String text) { View view = null; int count = listView.getCount(); Log.e(TAG, “no. children = " + count); for (int i = 0; i < count; i++) { TextView textView = (TextView) listView.getChildAt(i); Log.e(TAG, i + "-th text view is " + textView); if (textView != null && textView.getText().equals(text)) { view = textView; break; } } return view; } Iterate through child views Compare texts
  115. 115. Controlling UI Using Instrumentation 4. Find and act on a control: getChildViewByText. private View getChildViewByText(ListView listView, String text) { View view = null; int count = listView.getCount(); Log.e(TAG, “no. children = " + count); for (int i = 0; i < count; i++) { TextView textView = (TextView) listView.getChildAt(i); Log.e(TAG, i + "-th text view is " + textView); if (textView != null && textView.getText().equals(text)) { view = textView; break; } } return view; } com.example.android.apis.instrument.test.ApiDemosInstrumentTest: INSTRUMENTATION_RESULT: shortMsg=junit.framework.AssertionFailedError INSTRUMENTATION_RESULT: longMsg= junit.framework.AssertionFailedError: OpenGL ES demo should exist INSTRUMENTATION_CODE: 0 Iterate through child views Compare texts
  116. 116. Controlling UI Using Instrumentation 4. Find and act on a control: Revised getChildViewByText. private View getChildViewByText(final ListView listView, String text) { ... for (int i = 0; i < count; i++) { TextView textView = (TextView) listView.getChildAt(i); if (textView != null && textView.getText().equals(text)) { view = textView; break; } if (textView == null) { final int lastPos = listView.getLastVisiblePosition(); getInstrumentation().runOnMainSync(new Runnable() { public void run() { listView.smoothScrollToPosition(lastPos + 5, lastPos); } }); getInstrumentation().waitForIdleSync(); i = listView.getFirstVisiblePosition(); } } return view; }
  117. 117. Controlling UI Using Instrumentation 4. Find and act on a control: Revised getChildViewByText. private View getChildViewByText(final ListView listView, String text) { ... for (int i = 0; i < count; i++) { TextView textView = (TextView) listView.getChildAt(i); if (textView != null && textView.getText().equals(text)) { view = textView; break; } if (textView == null) { final int lastPos = listView.getLastVisiblePosition(); getInstrumentation().runOnMainSync(new Runnable() { public void run() { listView.smoothScrollToPosition(lastPos + 5, lastPos); } }); getInstrumentation().waitForIdleSync(); i = listView.getFirstVisiblePosition(); } } return view; } Scroll down
  118. 118. Controlling UI Using Instrumentation 5. Monitor a new Activity to launch. public void testNavigate() { ... Instrumentation.ActivityMonitor graphicsDemoActivityMonitor = getInstrumentation().addMonitor( ApiDemos.class.getName(), null, false); final ApiDemos graphicsDemoActivity = (ApiDemos) graphicsDemoActivityMonitor.waitForActivity(); assertNotNull("Graphics Demo (ApiDemos) activity should not be null", graphicsDemoActivity); ...
  119. 119. Controlling UI Using Instrumentation 5. Monitor a new Activity to launch. public void testNavigate() { ... Instrumentation.ActivityMonitor graphicsDemoActivityMonitor = getInstrumentation().addMonitor( ApiDemos.class.getName(), null, false); final ApiDemos graphicsDemoActivity = (ApiDemos) graphicsDemoActivityMonitor.waitForActivity(); assertNotNull("Graphics Demo (ApiDemos) activity should not be null", graphicsDemoActivity); ... 6. Iterate step 4 & 5.
  120. 120. Controlling UI Using Instrumentation 7. Build and Install the test package. $ cd ApiDemosInstrumentTest $ ant debug $ adb install –r bin/ApiDemosInstrumentTest-debug.apk
  121. 121. Controlling UI Using Instrumentation 7. Build and Install the test package. $ cd ApiDemosInstrumentTest $ ant debug $ adb install –r bin/ApiDemosInstrumentTest-debug.apk 8. Run the test and see the result. $ adb shell am instrument -w > com.example.android.apis.instrument.test/ > android.test.InstrumentationTestRunner
  122. 122. Controlling UI Using Instrumentation 7. Build and Install the test package. $ cd ApiDemosInstrumentTest $ ant debug $ adb install –r bin/ApiDemosInstrumentTest-debug.apk 8. Run the test and see the result. $ adb shell am instrument -w > com.example.android.apis.instrument.test/ > android.test.InstrumentationTestRunner $ ant test
  123. 123. Controlling UI Using Robotium
  124. 124. Controlling UI Using Robotium 1. Create an Android Test Project for the test package. $ android create test-project --main ../ApiDemos > –-name ApiDemosRobotiumTest --path ApiDemosRobotiumTest
  125. 125. Controlling UI Using Robotium 1. Create an Android Test Project for the test package. $ android create test-project --main ../ApiDemos > –-name ApiDemosRobotiumTest --path ApiDemosRobotiumTest 2. Add ‘robotium-solo-<ver>.jar’ in the ‘libs’ directory.
  126. 126. Controlling UI Using Robotium 1. Create an Android Test Project for the test package. $ android create test-project --main ../ApiDemos > –-name ApiDemosRobotiumTest --path ApiDemosRobotiumTest 2. Add ‘robotium-solo-<ver>.jar’ in the ‘libs’ directory. 3. Add a test class inheriting ActivityInstrumentationTestCase2. public class ApiDemosRobotiumTest extends ActivityInstrumentationTestCase2<ApiDemos> { ... public ApiDemosRobotiumTest() { super(ApiDemos.class); } ...
  127. 127. Controlling UI Using Robotium 4. Create an instance of Solo in the setUp method and close open activities in the tearDown method. ... private Solo solo; ... @Override public void setUp() throws Exception { solo = new Solo(getInstrumentation(), getActivity()); } @Override public void tearDown() throws Exception { solo.finishOpenedActivities(); } ...
  128. 128. Controlling UI Using Robotium 4. Find and act on a control. public void testNavigate() { solo.assertCurrentActivity("Should be on ApiDemos", ApiDemos.class); solo.clickOnText("^Graphics$", 1, true); solo.assertCurrentActivity("Should be on a new ApiDemos", ApiDemos.class, true); solo.clickOnText("^OpenGL ES$", 1, true); solo.assertCurrentActivity("Should be on a new ApiDemos", ApiDemos.class, true); solo.clickOnText("^Kube$", 1, true); solo.assertCurrentActivity("Should be on a Kube", Kube.class, true); solo.sleep(3000); }
  129. 129. Controlling UI Using Robotium 6. Build and Install the test package. $ cd ApiDemosRobotiumTest $ ant debug $ adb install –r bin/ApiDemosRobotiumTest-debug.apk
  130. 130. Controlling UI Using Robotium 6. Build and Install the test package. $ cd ApiDemosRobotiumTest $ ant debug $ adb install –r bin/ApiDemosRobotiumTest-debug.apk 7. Run the test and see the result. $ adb shell am instrument -w > com.example.android.apis.robotium.test/ > android.test.InstrumentationTestRunner
  131. 131. Controlling UI Using Robotium 6. Build and Install the test package. $ cd ApiDemosRobotiumTest $ ant debug $ adb install –r bin/ApiDemosRobotiumTest-debug.apk 7. Run the test and see the result. $ adb shell am instrument -w > com.example.android.apis.robotium.test/ > android.test.InstrumentationTestRunner $ ant test
  132. 132. Controlling UI Using uiautomator 1. Create an Java Project for the test jar.
  133. 133. Controlling UI Using uiautomator 1. Create an Java Project for the test jar. 2. Add ‘android.jar’ and ‘uiautomator.jar’ in the build path.
  134. 134. Controlling UI Using uiautomator 1. Create an Java Project for the test jar. 2. Add ‘android.jar’ and ‘uiautomator.jar’ in the build path. 3. Add a test class inheriting UiAutomatorTestCase. public class ApiDemosUiAutoTest extends UiAutomatorTestCase { ... }
  135. 135. Controlling UI Using uiautomator 4. Launch ApiDemos. public void testNavigate() throws UiObjectNotFoundException {
  136. 136. Controlling UI Using uiautomator 4. Launch ApiDemos. public void testNavigate() throws UiObjectNotFoundException { getUiDevice().pressHome(); Press home button
  137. 137. Controlling UI Using uiautomator 4. Launch ApiDemos. public void testNavigate() throws UiObjectNotFoundException { getUiDevice().pressHome(); UiObject allAppsButton = new UiObject( new UiSelector().description("Apps")); allAppsButton.clickAndWaitForNewWindow(); Press home button Click ‘All Apps’ button
  138. 138. Controlling UI Using uiautomator 4. Launch ApiDemos. public void testNavigate() throws UiObjectNotFoundException { getUiDevice().pressHome(); UiObject allAppsButton = new UiObject( new UiSelector().description("Apps")); allAppsButton.clickAndWaitForNewWindow(); Press home button Click ‘All Apps’ button UiObject appsTab = new UiObject(new UiSelector().text("Apps")); appsTab.click(); Click ‘Apps’ tab
  139. 139. Controlling UI Using uiautomator 4. Launch ApiDemos. public void testNavigate() throws UiObjectNotFoundException { getUiDevice().pressHome(); UiObject allAppsButton = new UiObject( new UiSelector().description("Apps")); allAppsButton.clickAndWaitForNewWindow(); Press home button Click ‘All Apps’ button UiObject appsTab = new UiObject(new UiSelector().text("Apps")); appsTab.click(); Click ‘Apps’ tab UiScrollable appList = new UiScrollable( new UiSelector().scrollable(true)); appList.setAsHorizontalList(); UiObject apiDemos = appList.getChildByText( new UiSelector().className(TextView.class.getName()), "API Demos"); apiDemos.clickAndWaitForNewWindow(); Click ‘ApiDemos’ icon
  140. 140. Controlling UI Using uiautomator 4. Launch ApiDemos. public void testNavigate() throws UiObjectNotFoundException { getUiDevice().pressHome(); UiObject allAppsButton = new UiObject( new UiSelector().description("Apps")); allAppsButton.clickAndWaitForNewWindow(); Press home button Click ‘All Apps’ button UiObject appsTab = new UiObject(new UiSelector().text("Apps")); appsTab.click(); Click ‘Apps’ tab UiScrollable appList = new UiScrollable( new UiSelector().scrollable(true)); appList.setAsHorizontalList(); UiObject apiDemos = appList.getChildByText( new UiSelector().className(TextView.class.getName()), "API Demos"); apiDemos.clickAndWaitForNewWindow(); Click ‘ApiDemos’ icon Validate the launch of ‘ApiDemos’ UiObject apiDemosPackage = new UiObject( new UiSelector().packageName("com.example.android.apis")); assertTrue(“Should be on ApiDemos", apiDemosPackage.exists()); ...
  141. 141. Controlling UI Using uiautomator 5. Find and act on a control.
  142. 142. Controlling UI Using uiautomator 5. Find and act on a control. ... UiScrollable demoList = new UiScrollable( new UiSelector().className("android.widget.ListView"));
  143. 143. Controlling UI Using uiautomator 5. Find and act on a control. ... UiScrollable demoList = new UiScrollable( new UiSelector().className("android.widget.ListView")); UiObject graphicsDemo = demoList.getChildByText( new UiSelector().className(TextView.class.getName()), “Graphics");
  144. 144. Controlling UI Using uiautomator 5. Find and act on a control. ... UiScrollable demoList = new UiScrollable( new UiSelector().className("android.widget.ListView")); UiObject graphicsDemo = demoList.getChildByText( new UiSelector().className(TextView.class.getName()), “Graphics"); graphicsDemo.clickAndWaitForNewWindow();
  145. 145. Controlling UI Using uiautomator 5. Find and act on a control. ... UiScrollable demoList = new UiScrollable( new UiSelector().className("android.widget.ListView")); UiObject graphicsDemo = demoList.getChildByText( new UiSelector().className(TextView.class.getName()), “Graphics"); graphicsDemo.clickAndWaitForNewWindow(); UiObject alphaBitmapDemo = new UiObject( new UiSelector().text(“AlphaBitmap")); assertTrue(“AlphaBitmap should be visible", alpahBitmapDemo.exists()); ...
  146. 146. Controlling UI Using uiautomator 5. Find and act on a control. ... UiScrollable demoList = new UiScrollable( new UiSelector().className("android.widget.ListView")); UiObject graphicsDemo = demoList.getChildByText( new UiSelector().className(TextView.class.getName()), “Graphics"); graphicsDemo.clickAndWaitForNewWindow(); UiObject alphaBitmapDemo = new UiObject( new UiSelector().text(“AlphaBitmap")); assertTrue(“AlphaBitmap should be visible", alpahBitmapDemo.exists()); ... 6. Iterate step 5.
  147. 147. Controlling UI Using uiautomator 7. Compile your test case into a JAR file. $ > $ $ android create uitest-project --name ApiDemosUiAutoTest --target 1 --path ApiDemosUiAutoTest cd ApiDemosUiAutoTest ant build
  148. 148. Controlling UI Using uiautomator 7. Compile your test case into a JAR file. $ > $ $ android create uitest-project --name ApiDemosUiAutoTest --target 1 --path ApiDemosUiAutoTest cd ApiDemosUiAutoTest ant build 8. Install the jar on your test device. $ adb push bin/ApiDemosUiAutoTest.jar /data/local/tmp/
  149. 149. Controlling UI Using uiautomator 7. Compile your test case into a JAR file. $ > $ $ android create uitest-project --name ApiDemosUiAutoTest --target 1 --path ApiDemosUiAutoTest cd ApiDemosUiAutoTest ant build 8. Install the jar on your test device. $ adb push bin/ApiDemosUiAutoTest.jar /data/local/tmp/ 9. Run the test and view the test result. $ adb shell uiautomator runtest ApiDemosUiAutoTest.jar > –c com.example.android.apis.uiauto.test.ApiDemosUiAutoTest
  150. 150. Controlling UI Using uiautomator 7. Compile your test case into a JAR file. $ > $ $ android create uitest-project --name ApiDemosUiAutoTest --target 1 --path ApiDemosUiAutoTest cd ApiDemosUiAutoTest ant build 8. Install the jar on your test device. $ adb push bin/ApiDemosUiAutoTest.jar /data/local/tmp/ 9. Run the test and view the test result. $ adb shell uiautomator runtest ApiDemosUiAutoTest.jar > –c com.example.android.apis.uiauto.test.ApiDemosUiAutoTest $ ant test
  151. 151. Controlling UI Using uiautomator 7. Compile your test case into a JAR file. $ > $ $ android create uitest-project --name ApiDemosUiAutoTest --target 1 --path ApiDemosUiAutoTest cd ApiDemosUiAutoTest ant build 8. Install the jar on your test device. $ adb push bin/ApiDemosUiAutoTest.jar /data/local/tmp/ 9. Run the test and view the test result. $ adb shell uiautomator runtest ApiDemosUiAutoTest.jar > –c com.example.android.apis.uiauto.test.ApiDemosUiAutoTest $ ant test
  152. 152. Doing both Controlling and Tracking
  153. 153. Doing both Controlling and Tracking 1. Modify org.kandroid.memtracer.MemoryInstrumentation. public class MemoryInstrumentation extends InstrumentationTestRunner { ... @Override public void onCreate(Bundle arguments) { ... start(); super.onCreate(arguments); } @Override public void onStart() { String mainActivityName = getMainActivityName(); if (mainActivityName != null && mainActivityName.length() > 0) { launchMainActivity(getTargetContext().getPackageName(), getMainActivityName()); } else { super.onStart(); } } ...
  154. 154. Doing both Controlling and Tracking 1. Modify org.kandroid.memtracer.MemoryInstrumentation. public class MemoryInstrumentation extends InstrumentationTestRunner { ... @Override public void onCreate(Bundle arguments) { ... start(); super.onCreate(arguments); } @Override public void onStart() { String mainActivityName = getMainActivityName(); if (mainActivityName != null && mainActivityName.length() > 0) { launchMainActivity(getTargetContext().getPackageName(), getMainActivityName()); } else { super.onStart(); } } ...
  155. 155. Doing both Controlling and Tracking 1. Modify org.kandroid.memtracer.MemoryInstrumentation. public class MemoryInstrumentation extends InstrumentationTestRunner { ... @Override public void onCreate(Bundle arguments) { ... start(); super.onCreate(arguments); } @Override public void onStart() { String mainActivityName = getMainActivityName(); if (mainActivityName != null && mainActivityName.length() > 0) { launchMainActivity(getTargetContext().getPackageName(), getMainActivityName()); } else { super.onStart(); } } ...
  156. 156. Doing both Controlling and Tracking 1. Modify org.kandroid.memtracer.MemoryInstrumentation. public class MemoryInstrumentation extends InstrumentationTestRunner { ... @Override public void onCreate(Bundle arguments) { ... start(); super.onCreate(arguments); } @Override public void onStart() { String mainActivityName = getMainActivityName(); if (mainActivityName != null && mainActivityName.length() > 0) { launchMainActivity(getTargetContext().getPackageName(), getMainActivityName()); } else { super.onStart(); } } ...
  157. 157. Doing both Controlling and Tracking 2. Add ‘kmemtracer-libs.jar’ in the ‘libs’ directory.
  158. 158. Doing both Controlling and Tracking 2. Add ‘kmemtracer-libs.jar’ in the ‘libs’ directory. 3. Edit the <instrumentation> element in the manifest file.
  159. 159. Doing both Controlling and Tracking 2. Add ‘kmemtracer-libs.jar’ in the ‘libs’ directory. 3. Edit the <instrumentation> element in the manifest file. 4. Build and Install the test package. $ cd ApiDemosInstrumentTest $ ant debug $ adb install –r bin/ApiDemosInstrumentTest-debug.apk
  160. 160. Doing both Controlling and Tracking 2. Add ‘kmemtracer-libs.jar’ in the ‘libs’ directory. 3. Edit the <instrumentation> element in the manifest file. 4. Build and Install the test package. $ cd ApiDemosInstrumentTest $ ant debug $ adb install –r bin/ApiDemosInstrumentTest-debug.apk 5. Run the test and see the result. $ adb shell am instrument -w > com.example.android.apis.instrument.test/ > org.kandroid.memtracer.MemoryInstrumentation
  161. 161. Doing both Controlling and Tracking 2. Add ‘kmemtracer-libs.jar’ in the ‘libs’ directory. 3. Edit the <instrumentation> element in the manifest file. 4. Build and Install the test package. $ cd ApiDemosInstrumentTest $ ant debug $ adb install –r bin/ApiDemosInstrumentTest-debug.apk 5. Run the test and see the result. $ adb shell am instrument -w > com.example.android.apis.instrument.test/ > org.kandroid.memtracer.MemoryInstrumentation 6. Pull the trace file ‘kmemtrace.csv’ from /sdcard/kmemtracer. $ adb pull /sdcard/kmemtracer/kmemtrace.csv .
  162. 162. SUMMARY
  163. 163. SUMMARY Why Automated Performance Testing? Measure to improve / Fragmentation
  164. 164. SUMMARY Why Automated Performance Testing? Measure to improve / Fragmentation How to Automate Performance Testing? - Historical Analysis w/ kmemtracer Instrumentation for track
  165. 165. SUMMARY Why Automated Performance Testing? Measure to improve / Fragmentation How to Automate Performance Testing? - Historical Analysis w/ kmemtracer Instrumentation for track - Measuring Performance API (Public / Internal) / cmds (Android / Linux)
  166. 166. SUMMARY Why Automated Performance Testing? Measure to improve / Fragmentation How to Automate Performance Testing? - Historical Analysis w/ kmemtracer Instrumentation for track - Measuring Performance API (Public / Internal) / cmds (Android / Linux) - Controlling UI Instrumentation / Robotium / uiautomator
  167. 167. Q&A
  168. 168. THANK YOU
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×