Learning Android Application Testing
Read it now on the O’Reilly learning platform with a 10-day free trial.
O’Reilly members get unlimited access to books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.
Book description
Improve your Android applications through intensive testing and debugging
This book is a practical introduction to readily available techniques, frameworks, and tools to thoroughly test your Android applications and improve project development.
You will learn the Java testing framework, how to create a test case and debug it. Next, you'll be walked through using the Android SDK to test using the ActivityTestCase and ActivityUnitTest classes as well as discussing popular testing libraries. Through examples you will test files, databases, ContentProviders, exceptions, services, and test your app using Espresso. You will discover how to manage your Android testing environment using Android emulators, deep dive into how adb and the emulator can super charge your testing automation, and also test user interactions with monkeyrunner. You will be guided through different testing methodologies including Test-driven Development and Behavior-driven Development and will learn how to perform Unit and Functional testing applying them to your Android projects. You will also use continuous integration techniques for ultimate application quality control using Gradle and Jenkins.
By the end of the book, you'll be looking through alternative testing tactics including Fest and Spoon to build upon and expand your Android testing range and finesse.
What You Will Learn
- Apply testing techniques and utilize tools to improve Android application development
- Get to grips with the nuances of testing on Android, including how to architect an application to facilitate better testing
- Explore the Android instrumentation testing framework to optimize your activities, services, content providers, and usage of other Android components
- Understand different development methodologies including Test-driven Development and Behavior-driven Development
- Apply the continuous integration technique for ultimate application quality control
- Improve application performance by analyzing the results returned from performance tests
- Expose your application to a wide range of conditions and configurations to simulate real-life network conditions and detect problems in the application
- Explore further tools to improve application quality such as micro benchmarks and code coverage
Show and hide more
Table of contents Product information
Table of contents
- Learning Android Application Testing
- Table of Contents
- Learning Android Application Testing
- Credits
- About the Authors
- About the Reviewers
- www.PacktPub.com
- Support files, eBooks, discount offers, and more
- Why subscribe?
- Free access for Packt account holders
- What this book covers
- What you need for this book
- Who this book is for
- Conventions
- Reader feedback
- Customer support
- Downloading the example code
- Errata
- Piracy
- Questions
- Questions
- Why, what, how, and when to test?
- What to test
- Activity lifecycle events
- Database and filesystem operations
- Physical characteristics of the device
- Unit tests
- The setUp() method
- The tearDown() method
- Outside the test method
- Inside the test method
- Mock objects
- UI tests
- Test case scenario
- Android Studio and other IDE support
- Instrumentation
- Gradle
- Test targets
- Package explorer
- Creating a test case
- Test annotations
- Running the tests
- Running all tests from Android Studio
- Running a single test case from your IDE
- Running from the emulator
- Running tests from the command line
- Running all tests
- Running tests from a specific test case
- Running a specific test by name
- Running specific tests by category
- Running tests using Gradle
- Creating a custom annotation
- Running performance tests
- Dry run
- The demonstration application
- Assertions in depth
- Custom messages
- Static imports
- An overview of MockContext
- The IsolatedContext class
- Alternate route to file and database operations
- The MockContentResolver class
- The default constructor
- The given name constructor
- The setName() method
- The assertActivityRequiresPermission() method
- Description
- Example
- Description
- Example
- Description
- Example
- The ActivityMonitor inner class
- Example
- The launchActivity and launchActivityWithIntent methods
- The sendKeys and sendRepeatedKeys methods
- The runTestOnUiThread helper method
- The scrubClass method
- The constructor
- The setUp method
- The tearDown method
- The constructor
- An example
- The constructor
- Android unit tests
- Testing activities and applications
- Mocking applications and preferences
- The RenamingMockContext class
- Mocking contexts
- The BrowserProvider tests
- Importing libraries
- Mockito usage example
- The EditNumber filter tests
- Android assets
- Creating Android Virtual Devices
- Running AVDs from the command line
- Headless emulator
- Disabling the keyguard
- Cleaning up
- Terminating the emulator
- Simulating network conditions
- The client-server monkey
- Getting test screenshots
- Record and playback
- Building Android applications manually using Gradle
- Git – the fast version control system
- Creating a local Git repository
- Installing and configuring Jenkins
- Creating the jobs
- Obtaining Android test results
- Getting started with TDD
- Writing a test case
- Running all tests
- Refactoring the code
- Advantages of TDD
- Understanding the requirements
- List of requirements
- User interface concept design
- Creating the project
- Creating the fixture
- Creating the user interface
- Testing the existence of the user interface components
- Getting the IDs defined
- Translating requirements to tests
- Empty fields
- View properties
- Temperature conversion
- The EditNumber class
- The TemperatureConverter unit tests
- The EditNumber tests
- The TemperatureChangeWatcher class
- More TemperatureConverter tests
- The InputFilter tests
- Given, When, and Then
- FitNesse
- Running FitNesse from the command line
- Creating a TemperatureConverterTests subwiki
- Adding child pages to the subwiki
- Adding the acceptance test fixture
- Adding the supporting test classes
- Creating the test scenario
- Ye Olde Logge method
- Timing logger
- Performance tests in Android SDK
- Launching the performance test
- Creating the LaunchPerformanceBase instrumentation
- Creating the TemperatureConverterActivityLaunchPerformance class
- Caliper microbenchmarks
- Benchmarking the temperature converter
- Running Caliper
- Code coverage
- Jacoco features
- Generating code coverage analysis report
- Covering the exceptions
- Adding Robotium
- Creating the test cases
- The testFahrenheitToCelsiusConversion() test
- Testing between Activities
- Comparing the performance gain
- Adding Android to the picture
- Installing Robolectric
- Adding resources
- Writing some tests
Show and hide more
Product information
- Title: Learning Android Application Testing
- Author(s): Paul Blundell, Diego Torres Milano
- Release date: March 2015
- Publisher(s): Packt Publishing
- ISBN: 9781784395339