Android Testing Guidelines Enhanced with ChatGPT

Fahed Hermoza

--

A Brief Narrative

In the last month, I have been involved in a proof of concept with the goal of establishing testing guidelines for the Android engineering team of a banking client in Peru. This endeavor included collecting the best practices used in Android testing, with a particular focus on exploring the use of an AI tool like ChatGPT. The initial objective was to simplify the creation of test templates.

Before starting this project, I briefly worked as an Android Prompt Engineer for a team in Spain. During that time, my main focus was on refining prompts to achieve a high level of efficiency, surpassing 80%. This experience was especially fascinating, considering the evolving ecosystems built around such tools.

After presenting the proof of concept and the guidelines to the team, I can confidently state that we have achieved significantly shorter development times for test case generation, test data creation, and the creation of explanatory comments. We acknowledge that thorough testing takes time, and in some instances, the learning curve is steep, given the variability of frameworks across different projects.

Essentially, this proposal suggests that if a solution offers a 60% to 70% improvement through foundational templates, it represents a considerable step forward. Personally, I would welcome such a solution without hesitation, recognizing the potential for substantial time savings and increased efficiency in the testing process.

Repository Overview

Upon reviewing web content, there is no documented case of a specific implementation of Artificial Intelligence (AI) tools in a particular process within software development. The purpose of this repository is to provide a concrete implementation of using AI tools, such as “ChatGPT,” in the testing process, aligning it with the current standards used by an Android engineering team.

Foto de Igor Omilaev en Unsplash

Precepts of the Repository

Android Testing:

In the realm of Android development, the architectural style known as Clean Architecture, proposed by Robert C. Martin, has been almost universally adopted. This approach segments the system’s responsibilities into independent layers (Presentation, Domain, and Data) with specific functions for each. Additionally, Google recommends using the MVVM (Model-View-ViewModel) architecture pattern, compatible with Android Jetpack’s ViewModel and LiveData libraries.

Testing Approach:

Now, focusing on testing within Android, three types of tests are recognized: unit testing, integration testing, and user interface testing. The choice of which type of test to write depends on the granularity required to meet established objectives. A significant benefit of clean architecture in the testing context is the ability to perform tests at every layer of the architecture, contributing to the robustness and reliability of the system.

Artificial Intelligence (AI) Tool: ChatGPT

ChatGPT is a natural language processing artificial intelligence tool developed by OpenAI. While ChatGPT can offer valuable assistance, it’s crucial to emphasize that it should not be considered a replacement for thorough code reviews, rigorous testing, or professional advice when addressing critical tasks in software development. Software engineers should use ChatGPT as a complementary tool to enhance their productivity and problem-solving skills, especially in specific cases such as testing.

Taking advantage of its ability to generate coherent and relevant text, we will focus on three key applications of ChatGPT in software testing:

  1. Test Case Generation: ChatGPT can assist in automatically generating test cases in natural language. Describing the expected behavior of a function or feature allows ChatGPT to generate detailed test cases.
  2. Test Data Generation: ChatGPT can be used to generate realistic test data, valuable for evaluating software performance and scalability.
  3. Documentation, Comments, and Support: ChatGPT can be a valuable tool for creating documentation, both for end-users and internal use. It facilitates explaining how to use various functions and provides answers to frequently asked questions.

In summary, ChatGPT integrates effectively as a complementary tool in the software testing process, utilizing its unique ability to generate content consistently and contextually.

Context in ChatGPT:

In the context of using ChatGPT, a crucial feature to consider is “Context,” which plays a crucial role in the coherence and relevance of the model’s generated responses.

Context in ChatGPT covers information and the history of conversations. This element is fundamental for the model to generate responses aligned with the current thread of the conversation. ChatGPT’s architecture is specifically designed to retain and understand context within an interaction, enabling the model to comprehend and respond effectively.

It’s essential to recognize that context has its limitations. As the conversation progresses, the model may “forget” less relevant details. Additionally, there is a maximum token limit, usually around 4096 tokens, restricting the duration of the conversation history the model can consider. If this limit is reached, ChatGPT may start a new conversation or restart it through a specific message.

Understanding context in ChatGPT is crucial to maximize its effectiveness and anticipate possible limitations. Proper context management is fundamental to fully leverage the capabilities of this advanced language model.

Generation of Similar Functions:

When generating prompts, we often face the challenge of obtaining similar responses, but our goal is to create functions identical to the established base classes according to testing guidelines.

To address this, it’s fundamental to understand the concept of Seed and Generator in the realm of pseudo-random numbers. The “seed” is an initial value used to start a pseudo-random number generator, and the “generator” is the algorithm that produces the sequence of numbers. The choice of the seed can affect the sequence of pseudo-random numbers generated and is used to control and ensure reproducibility in applications where it is essential.

In our case, the seed will be a pre-designed sample test class containing all the mentioned guidelines and will be identified by ChatGPT. The generator will have the guidelines defined in detail with the test class or function to be analyzed. This will enable us to generate test functions that maintain the structure and guidelines of the example class.

As ChatGPT has the ability to maintain context, we can carry out the generation of similar functions through prompt messages for both the seed and the generator.

Foto de Markus Spiske en Unsplash

Custom Instructions:

This feature allows customizing ChatGPT’s responses according to preferences and can be adjusted or removed at any time for future conversations.

There are two questions, and each response is limited to 1500 characters. These two questions serve as input for the seed and the generator. It is crucial to consider the character limit to optimize prompt responses effectively.

ChatGPT controversy:

Currently, there is a significant controversy surrounding ChatGPT. While the input and output data are not owned by ChatGPT, they utilize this information to train their model, which is the source of the controversy.

To sidestep this controversy, it is recommended to use the paid version of ChatGPT. This ensures that the entered content should not encounter issues. In an engineering team, having licensed tools that aid developers is crucial.

Repository

This post encapsulates a journey of exploration, implementation, and advancements in the realm of Android testing and AI integration.

--

--

No responses yet

Write a response