Any part of your mobile app that has a potential to change when users interact with it should be seriously tested before the app goes out for public. Naturally, there are several ways to enable efficient testing of those parts and one thing to consider for your mobile app development process is the data-driven testing (aka DDT).
Basically, data-driven testing is like automating your test automation. You store the test data in any external location (e.g. file, database, spreadsheet) and then use that data iteratively as a part of your test. In a nutshell, you can run automated tests that simulate user actions over an application with different input data fetched from that external location.
In this blog we’ll take a look at Robotium example of how data-driven testing could be applied to mobile app testing. However, the code snippets shown below are usable for other frameworks as well as it is generic Java.
The Benefits of Data-Driven Testing
Let’s look at some of the benefits of data-driven testing:
1. Start Any Moment During Your Development
Data-driven testing – and designing and planning those data assets can be done at any phase of the development. A data-driven test case is typically tied to a single procedure but it can be also used in multiple test cases, simultaneously or parallel. A procedure that inputs or processes data may include many test cases relating to individual elements of the data or steps in the sequence.
2. Repeatability and Reusability
Data-driven testing enables an approach where any test script can be executed even thousands of times with different data assets each time. For some verticals, such as banking and video streaming app providers, feeding different types of data – either valid and invalid – can be really efficient to enable versatile testing of their mobile apps.
3. Clean Separation of Test Case and Test Data
One of the greatest benefits of data-driven testing is that it allows developers and testers to separate the logic of their test cases/scripts from the test data. Testers can test their app using lots of different data values and parameters without building any complexity in test case/script themselves. Also, the data asset is easy to add, remove and configure and doesn’t have any implication to test cases.
4. Get More Realistic Test Cases
When you have capability to continually change the test data and use it instantly it offers you a realistic test bed and can potentially found other defects you would not find otherwise.
5. Reduction in Number of Test Cases/Scripts
When your test cases are more modular and relying on test data assets that easy to add, remove and configure, you actually need less test cases/scripts. The unnecessary duplicates of tests cannot be always avoided but data-driven testing offers you way to build your testing more modular.
A Basic Example of Data-Driven Testing
To get started we need a basic set of data and the following example illustrates “a database” of people’s contact details.
So, let’s see an file read example. Typically when you are creating data-driven tests with scripts, you use loops to iterate through the data. Here is an example that uses the loop to retrieve data from the file (contacts.txt), and calls the function addContact in order to process the data.
And here is the addContact function:
A complete Java source code for Robotium example can be found here.
More information about using Robotium or any other testing framework can be found at help.testdroid.com.