Android Programming by Hellman Erik
Author:Hellman, Erik
Language: eng
Format: epub, pdf
Publisher: Wiley
Published: 2013-10-13T16:00:00+00:00
Chapter 10
Writing Automated Tests
If I had to pick one thing that developers of mobile apps often miss, it would be testing, despite the fact that high-quality software is the result of thorough testing. Consequently, this may be the most important chapter in this book.
The traditional way of developing software has been to design the software architecture, implement the code, and finally test the code, maybe by using automated tests to some degree. However, when testing is the last thing done in the development cycle, often too little testing is done or the wrong things are tested.
Test Driven Development (TDD) takes a different approach to software development, and its principles lead to high-quality software. With TDD, you start by defining your tests based on how your application will be used. Then you start implementing code that fulfills these tests, continuing until all the tests are satisfied. At this point, you can refactor your application code to optimize it for performance and to improve the overall design.
Using TDD involves a number of tools and techniques. First, you need a unit-testing framework for writing the automated tests. This framework, which is included in the Android APIs, is the main focus of this chapter. Second, you need a continuous integration and build server. This server automatically builds your application and performs all the automated tests for every change in the code. Finally, you need a code-coverage tool that tells you how much of the applicationâs code is really being tested.
Android Testing Principles
On Android, you can divide tests into two categories: unit and instrumentation tests. Although within the field of TDD, there are other types of tests (for example, integration, functional, system, and component tests) in the context of Android, Iâm focusing on unit and instrumentation tests.
Unit testing works on a very fine-grained level, usually on individual methods and classes with all external dependencies removed. On the other hand, instrumentation tests focus on verifying the behavior of a component (Activity, Service, BroadcastReceiver or ContentProvider) in the overall system.
The goal with unit testing is to verify that your methods behave as expected and that they can handle erroneous input without crashing. A framework called JUnit was developed for the Java programming language. JUnit is also part of the official Android APIs in the junit package along with the Android-specific testing framework under android.test. To do unit testing, you call a method in your application code and test its result for the expected output. This is called, asserting the result, and there is a ready-made utility class named Assert for this purpose. Each test you write should perform an assertion on the value, which in turn tells the testing framework whether the test passed.
Each test is called a test case, and a set of test cases is called a test suite. Each test case starts with a setup where all dependencies are created and initialized. When the test case is complete, a teardown is performed to release the resources that were created during setup.
Because the
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
2021 Beginners Guide to Python Programming Language: A Crash Course to Mastering Python in One Hour by Elmer Gary & Elmer Gary(1832)
API Testing and Development with Postman by Dave Westerveld(1727)
Learning C# by Developing Games with Unity 2020 by Harrison Ferrone(1583)
Machine Learning for Algorithmic Trading by Stefan Jansen(1502)
Software Architecture for Busy Developers by Stéphane Eyskens(1496)
Hands-On ROS for Robotics Programming by Bernardo Ronquillo Japón(1466)
Delphi GUI Programming with FireMonkey by Andrea Magni(1337)
Cloud Native with Kubernetes by Alexander Raul(1300)
Game Development Projects with Unreal Engine by Hammad Fozi & Goncalo Marques & David Pereira & Devin Sherry(1285)
Automate It with Zapier by Kelly Goss(1248)
Software Architecture Patterns for Serverless Systems by John Gilbert(1245)
Practical System Programming for Rust Developers by Prabhu Eshwarla(1224)
Datadog Cloud Monitoring Quick Start Guide by Thomas Kurian Theakanath(1221)
Practical Node-RED Programming by Taiji Hagino(1208)
Mastering React Test-Driven Development by Daniel Irvine(1197)
Delphi Programming Projects by William Duarte(1188)
Developing Multi-Platform Apps with Visual Studio Code by Ovais Mehboob Ahmed Khan & Khusro Habib & Chris Dias(1155)
Learn Spring for Android Application Development by S. M. Mohi Us Sunnat(1154)
Ghidra Software Reverse Engineering for Beginners by A. P. David(1153)