Debugging Testing Profiling Team activity...

17
Mobile Programming Practice Debugging Testing Profiling Team activity (project) 1 Prof. Hwansoo Han T.A. Sungin Hong T.A. Minseop Jeong

Transcript of Debugging Testing Profiling Team activity...

Page 1: Debugging Testing Profiling Team activity (project)arcs.skku.edu/pmwiki/uploads/Courses/SWPractice3/13_Debugging.… · Android Studio profile tools (2/2) 1. Android Profiler shows

Mobile Programming Practice

▪ Debugging

▪ Testing

▪ Profiling

▪ Team activity (project)

1

Prof. Hwansoo Han

T.A. Sungin Hong

T.A. Minseop Jeong

Page 2: Debugging Testing Profiling Team activity (project)arcs.skku.edu/pmwiki/uploads/Courses/SWPractice3/13_Debugging.… · Android Studio profile tools (2/2) 1. Android Profiler shows

Debug

▪ Android Studio provides a debugger

• Select a device to debug your app on

• Set breakpoints in your Java, Kotlin, and C/C++ code

• Examine variables and evaluate expressions at

runtime

▪ IntelliJ IDEA debugging docs

2

Page 3: Debugging Testing Profiling Team activity (project)arcs.skku.edu/pmwiki/uploads/Courses/SWPractice3/13_Debugging.… · Android Studio profile tools (2/2) 1. Android Profiler shows

Enable debugging

▪ Install LLDB

• If your project includes C/C++ code, you need to install

LLDB from the SDK Manager

▪ Enable debugging on your device

• If you’re using the emulator, this is enabled by default

• But for a connected device, you need to enable

debugging in the device developer options

3

Page 4: Debugging Testing Profiling Team activity (project)arcs.skku.edu/pmwiki/uploads/Courses/SWPractice3/13_Debugging.… · Android Studio profile tools (2/2) 1. Android Profiler shows

Start debugging

1. Set some breakpoints

2. In the toolbar, click Debug

3. Select a deployment target and click OK

4. If the Debug window is not open, select View

> Tool Windows > Debug

4

Page 5: Debugging Testing Profiling Team activity (project)arcs.skku.edu/pmwiki/uploads/Courses/SWPractice3/13_Debugging.… · Android Studio profile tools (2/2) 1. Android Profiler shows

Work with breakpoints (1/2)

▪ To add a line breakpoint,

• Locate the line of code, then either click the left gutter

along that line

• Or press ctrl + F8

• If your app is already running, add the breakpoint and

just click Attach debugger to Android process

5

Page 6: Debugging Testing Profiling Team activity (project)arcs.skku.edu/pmwiki/uploads/Courses/SWPractice3/13_Debugging.… · Android Studio profile tools (2/2) 1. Android Profiler shows

Work with breakpoints (2/2)

6

Resume Program

(F9)

Step Over

(F8)

Step Into

(F7)

Step Out

(shift + F8)

To advance to the next line in the code (without entering a method), click Step Over

To advance to the first line inside a method call, click Step Into

To advance to the next line outside the current method, click Step Out

To continue running the app normally, click Resume Program

Page 7: Debugging Testing Profiling Team activity (project)arcs.skku.edu/pmwiki/uploads/Courses/SWPractice3/13_Debugging.… · Android Studio profile tools (2/2) 1. Android Profiler shows

Use the system log

7

import android.util.Log;

...

public class MyActivity extends Activity {

private static final String TAG = MyActivity.class.getSimpleName();

...

@Override

public void onCreate(Bundle savedInstanceState) {

...

if (savedInstanceState != null) {

Log.d(TAG, "onCreate() Restoring previous state");

/* restore state */

} else {

Log.d(TAG, "onCreate() No saved state available");

/* initialize app */

}

}

}

▪ Write log messages in your code

Page 8: Debugging Testing Profiling Team activity (project)arcs.skku.edu/pmwiki/uploads/Courses/SWPractice3/13_Debugging.… · Android Studio profile tools (2/2) 1. Android Profiler shows

View the system log

8

1. Clear logcat

2. Scroll to the end

3. Up the stack trace and Down the stack trace

4. Use soft wraps

5. Print

6. Restart

7. Logcat header

8. Screen capture

9. Screen record

Page 9: Debugging Testing Profiling Team activity (project)arcs.skku.edu/pmwiki/uploads/Courses/SWPractice3/13_Debugging.… · Android Studio profile tools (2/2) 1. Android Profiler shows

Testing

▪ Testing your app is an integral part of the app

development process

▪ By running tests against your app consistently, you

can verify your app’s correctness, functional behavior,

and usability

9

*V-model

from GeeksforGeeks

Page 10: Debugging Testing Profiling Team activity (project)arcs.skku.edu/pmwiki/uploads/Courses/SWPractice3/13_Debugging.… · Android Studio profile tools (2/2) 1. Android Profiler shows

Espresso

▪ To write reliable Android UI tests

▪ Espresso setup

• https://developer.android.com/training/testing/espresso/setup

10

@Test

public void greeterSaysHello() {

onView(withId(R.id.name_field)).perform(typeText("Steve"));

onView(withId(R.id.greet_button)).perform(click());

onView(withText("Hello Steve!")).check(matches(isDisplayed()));

}

Example of an Espresso test

Page 11: Debugging Testing Profiling Team activity (project)arcs.skku.edu/pmwiki/uploads/Courses/SWPractice3/13_Debugging.… · Android Studio profile tools (2/2) 1. Android Profiler shows

Espresso – API components

▪ Espresso – Entry point to interactions with views

• via onView() and onData()

▪ ViewMatchers – A collection of objects

• implement the Matcher<? super View> interface

• You can pass one or more of these to the onView() method to locate a

view within the current view hierarchy

▪ ViewActions – A collection of ViewAction objects

• can be passed to the ViewInteraction.perform() method, such as click()

▪ ViewAssertions – A collection of ViewAssertion objects

• can be passed the ViewInteraction.check() method

11

Page 12: Debugging Testing Profiling Team activity (project)arcs.skku.edu/pmwiki/uploads/Courses/SWPractice3/13_Debugging.… · Android Studio profile tools (2/2) 1. Android Profiler shows

Profile

▪ An app is considered to have poor

performance

• if it responds slowly, shows choppy animations,

freezes, crashes, or consumes a lot of power

▪ To avoid these performance problems, use

the profiling and benchmarking tools to

identify where your app is making inefficient

use of resources

12

Page 13: Debugging Testing Profiling Team activity (project)arcs.skku.edu/pmwiki/uploads/Courses/SWPractice3/13_Debugging.… · Android Studio profile tools (2/2) 1. Android Profiler shows

Android Studio profile tools (1/2)

▪ provide real-time resources usage

• CPU, memory, network, battery, and GPU

13

Page 14: Debugging Testing Profiling Team activity (project)arcs.skku.edu/pmwiki/uploads/Courses/SWPractice3/13_Debugging.… · Android Studio profile tools (2/2) 1. Android Profiler shows

Android Studio profile tools (2/2)

1. Android Profiler shows the process and device currently being

profiled.

2. In the Sessions pane, choose which session to view, or start a

new profiling session.

3. Use the zoom buttons to control how much of the timeline to view,

or use the Attach to livebutton to jump to the real-time updates.

4. The event timeline shows events related to user input, including

keyboard activity, volume control changes, and screen rotations.

5. The shared timeline view, which includes graphs for CPU,

memory, network, and energy usage.

14

Page 15: Debugging Testing Profiling Team activity (project)arcs.skku.edu/pmwiki/uploads/Courses/SWPractice3/13_Debugging.… · Android Studio profile tools (2/2) 1. Android Profiler shows

Measure app perf.

with Android Studio

15

▪ To open the Profiler window, choose View >

Tool Windows > Profiler

Page 16: Debugging Testing Profiling Team activity (project)arcs.skku.edu/pmwiki/uploads/Courses/SWPractice3/13_Debugging.… · Android Studio profile tools (2/2) 1. Android Profiler shows

CPU profiler overview

1. Event timeline

2. CPU timeline

3. Thread activity timeline

• Green : the thread is active or ready to use the CPU

• Yellow : the thread is active but it’s waiting on an I/O operation

• Gray : the thread is sleeping

16

Page 17: Debugging Testing Profiling Team activity (project)arcs.skku.edu/pmwiki/uploads/Courses/SWPractice3/13_Debugging.… · Android Studio profile tools (2/2) 1. Android Profiler shows

For more info. of profiler

▪ CPU activity

• https://developer.android.com/studio/profile/cpu-profiler

▪ Java heap and memory

• https://developer.android.com/studio/profile/memory-profiler?hl=en

▪ Network traffic

• https://developer.android.com/studio/profile/network-profiler?hl=en

▪ Battery usage

• https://developer.android.com/studio/profile/battery-historian?hl=en

▪ GPU rendering speed

• https://developer.android.com/studio/profile/inspect-gpu-rendering?hl=en

17