Mobile Application
Development (MAP711S)
Testing & Debugging Apps
Simon H. Muchinenyik
a
Testing & Debugging Apps
T ble of Contents
• Testing Software
• Automated testing, manual testing
• Debugging
• Sources of Bugs, Bene ts of Debugging, Android Studio Debugging Tools
• Project Structure
• Source Code, Resources, Gradle, etc.
• Testing Frameworks
• JUnit, Expresso
a
fi
Testing & Debugging Apps
Testing Softw re
• structured way of checking if software if working correctly;
• Bene ts:
• rapid feedback on failures, allowing bugs to be removed before code releases;
• early failure detection in the development cycle;
• safer code refactoring;
• stable development velocity.
• when an app is small, with limited functionality, testing is easy. However it becomes
complex as the application grows.
3
fi
a
Testing & Debugging Apps
Types of Tests: Subject
• functional testing:
• Is the app doing what it is supposed to do?
• performance testing
• Does the app do it quickly & e ciently?
• accessibility testing
• Does the app work well with accessibility services?
• compatibility testing:
• Does the app work well on every device & API level?
4
ffi
Testing & Debugging Apps
Types of Tests: Scope
• the scope de nes the size or degree of isolation:
• unit tests:
• small tests that verify a small portion of app s.a., a method or a class;
• end-to-end tests
• big tests that veri es a larger part of an app e.g., a whole screen or user ow;
• medium tests:
• their scope is in between as they check integration between two or more units.
5
fi
fi
fl
Testing & Debugging Apps
Autom ted Testing
• uses code to check if another piece of code is working correctly;
• two types: unit tests & instrumentation test;
• a fully developed developer writes tests alongside app code as this reducing manual
testing greatly.
6
a
Testing & Debugging Apps
Instrumented Tests Vs Loc l Tests
// When the Continue button is clicked
•
onView(withText("Continue"))
Instrumented Tests .perform(click())
•
// Then the Welcome screen is displayed
runs on either simulated or physical Android device; onView(withText("Welcome"))
.check(matches(isDisplayed()))
• app built and installed alongside the test app that injects commands and reads
state;
• usually UI tests, launching an app & interacting with it.
• Local Tests
• aka host-side tests;
• execute on a development machine or server.
7
a
Testing & Debugging Apps
JUnit
• a library that drives unit tests;
• @Test annotation imported from [Link] library must be added for each test
function;
• Example:
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}
• an annotation is metadata tags that changes the way a piece of code is run.
8
Testing & Debugging Apps
Assertion Methods
• unit tests are based on assertion methods;
• Examples: See [Link]
• assertEquals()
• assertThat()
• assertTrue()
• assertNull()
• assertNotSame()
• message arguments are displayed when an assert fails.
9
Testing & Debugging Apps
Debugging
• the process of nding and removing bugs.
• So, what are bugs? Any of these anomalies can be classi ed as a bug:
• incorrect behaviour in an app;
• excessively consuming resources, e.g., memory, network, etc.
• freezing or crashing.
10
fi
fi
Testing & Debugging Apps
C uses of Bugs
• errors in design or implementation;
• inherent Android framework bugs;
• missed requirements;
• device limitations.
• …
11
a
Testing & Debugging Apps
The Debugger
• app can be run on debug mode:
• Run => Debug “app”. This opens the Debug window
• a debugger is attached to a running app:
• Run => Attach debugger to Android process
• one can also stop or resume program during debugging
12
Testing & Debugging Apps
Bre kpoints
• a line used to pause code execution:
• to examine variable, or
• to evaluate expressions, or
• executing code line by line to gure out the cause of runtime errors.
• to add a breakpoint identify the line and go to Run => Toggle Line Breakpoint;
• conditional breaks are only observed if the rest of the condition is true;
• muting a breakpoint temporarily disables it without removing it from code.
Removing it loses all conditions that were set for the breakpoint.
13
a
fi
Testing & Debugging Apps
Fr mes
• a frame is a combination of class and methods;
• the Frames pane shows the current execution stack and the frame that caused the
breakpoint to be reached;
• each class and method called by the app are shown in the execution stack starting
with the most recent one.
14
a
Testing & Debugging Apps
W tches
• shows values of present variable watches;
• makes it possible to keep track of one variable in a program.
15
a
Testing & Debugging Apps
V ri bles P ne
• shows variables and their corresponding values in the current scope;
• the expand icon on each variable lists the object properties of the variable.
16
a
a
a
Testing & Debugging Apps
Further Study
• Android Assert: [Link]
17
Testing & Debugging Apps
References
• JUnit: [Link]
• Testing Apps: [Link]
18
Testing & Debugging Apps
Th nk You
Questions?
T: +264 61 207 2054
F: +264 61 207 9054
E: smuchinenyika@[Link]
a