Techniques to Use ChatGPT to Generate High-Quality Test Cases

The sophisticated large language model ChatGPT was trained using a variety of methods in this article, with the goal of producing high-quality test cases. ChatGPT has applications in many different sectors and is renowned for its capacity to produce text responses that resemble those of humans. We can use ChatGPT to help with test case creation for software development, quality assurance, and other related tasks.

Let's look at some methods to train ChatGPT, its features, and potential uses in different fields. We will also offer helpful hints and best practices for utilizing ChatGPT for test case creation.

The first method is using forefront.ai. For this, go to https://chat.forefront.ai/ and set up your preferences if you want to train your persona or use the GPT-4 version:

  • Click on “Enable personas”
  • Select the role of your preferences; in this case, we are using “Software Engineer”
  • Enable the Access Internet option

Screenshot 2023-08-03 at 3.43.05 PM

You may now play the part of a software engineer using ChatGPT and start asking it to write test cases based on user stories, acceptance criteria, or any other pieces of information.

An alternative is to use prompt templates; to achieve this, download the AIPRM for ChatGPT plugin for Chrome. This will give you access to already created prompts to generate test cases.

Here, you can choose a template according to your interest:

Screenshot 2023-08-03 at 3.46.12 PM

After you have selected the template let's discuss some strategies for generating high-quality test cases:
  • Understanding the user story: To start, make sure you fully comprehend the user story and its acceptance requirements. This will assist you in determining the essential behaviors and features that require testing.
  • Utilize techniques for requirement analysis: Use tools for requirement analysis like decision tables, state transition diagrams, or case diagrams to better comprehend the behavior of the system and pinpoint various test scenarios.
  • Focus on examining the limits of the input values via boundary value analysis: Find the values that fall just below and just above the minimum and maximum valid values. Testing at these crucial moments aids in identifying any flaws.
  • Partitioning based on equivalence: Classify inputs and outputs according to how they behave. Test representative values from each class because flaws in one class frequently affect all the classes.
  • Pairwise testing: When there are several input parameters, utilize pairwise testing to choose a small number of test cases that account for all potential parameter combinations. This method offers good coverage while reducing the number of test cases.
  • Examine negative eventualities: Test cases should take into account negative eventualities in addition to expected actions. Check how the system responds to invalid inputs or unexpected conditions, as well as how errors and exceptions are handled.
  • Prioritize your test cases by considering the risks involved with the various functionalities.: Concentrate on essential elements, challenging aspects, or troublesome locations.


Keep in mind that these tactics are intended to be suggestions and that their usefulness will rely on the particulars of your project and setting. Create test cases according to your needs, always keeping in mind the viewpoint of the end user.

A Real Example of Using ChatGPT to Generate Test Cases

For this, we will use OpenAI’s ChatGPT. In your prompt, make sure to indicate the parameters of inputs and which steps you want to follow for the specific technique, for example:

Prompt: Using the equivalence class technique, find the representative test cases to verify the following functionality:

The Pets Friends store has the following discount policy:

  • There are 4 types of customers: Normal, Silver, Gold, and Platinum Gold.
  • Platinum customers are the only ones eligible to request discounts.
  • To be eligible for the discount, the purchase amount must be equal to or greater than USD 500 and must include products from the "Purina" brand.
  • Also, indicate the number of test cases that were eliminated because they were not useful.

The inputs are Customer type, Purchase amount, and Product brand.

Write down the final test cases in a table. The steps are as follows:

  1. Identify the inputs.
  2. Identify equivalent classes: valid and invalid classes.
  3. Calculate the number of test cases (total and useful).
  4. Make combinations.
  5. Set up the test case table.

Result

Screenshot 2023-08-03 at 3.52.57 PM

Screenshot 2023-08-03 at 3.53.07 PMBased on The Pets Friends store's discount policy, the table displays the results of the final test instances. The analogous class technique was used to identify representative inputs. The only customer type that is permitted is "Platinum Gold," and only these clients are allowed to seek discounts. The accepted price is greater than or equal to 50,000 colones, and the accepted product brand is "Purina." Test cases 2, 3, 4, 5, and 6 were dropped since they didn't adhere to the guidelines. The remaining test cases guarantee that discounts for qualified clients who make the required purchase quantity and include the specified product brand are applied properly.

In conclusion, creating high-quality test cases based on user stories and utilizing design methodologies are crucial for successful testing. The testing process is improved by using strategies like comprehending the user story, applying design approaches like equivalence partitioning and boundary value analysis, and prioritizing test cases. It's also relevant to incorporate worst-case scenarios. To ensure quality over quantity, apply these tactics to your project, work with stakeholders, and concentrate on significant scenarios. You boost your chances of identifying errors, enhancing software quality, and producing a dependable, user-friendly product by adhering to these guidelines.

Key Takeaways

  • Establish specific directions and guidelines: ChatGPT needs clear rules and instructions to produce test cases that are in line with the intended requirements. Clearly define the inputs, expected behaviors, and any constraints or requirements for the test cases.
  • If you want to have more accurate results, you must train your ChatGPT by using the techniques mentioned above or by providing all the steps that you need on the first prompt.
  • Validate the generated test cases by giving them a thorough review and verification, verify that they are comprehensive, adhere to the criteria supporting the intended test objectives, and use your skills and domain knowledge to spot any potential faults or gaps.
  • Combine ChatGPT with conventional methods: GenAI tools should be used in conjunction with conventional methods for creating test cases. To assure a comprehensive collection of test cases, use ChatGPT to supplement current techniques like equivalence partitioning, boundary value analysis, decision tables, etc.
  • Aim for balance: Strike a balance between the necessity for human intervention, validation, and the ability to generate test cases using the tool. While retaining human judgment to assure the overall quality and relevance of the test cases, use ChatGPT as a tool to accelerate the development of test cases and boost coverage.

About Encora

Fast-growing tech companies partner with Encora to outsource product development and drive growth. Contact us to learn more about our software engineering capabilities.

 

 

Share this post

Table of Contents