Location>code7788 >text

ChatGPT Best Practices for Test Case Generation (III)

Popularity:830 ℃/2024-12-18 10:27:10

Remember in Chapter 1, we used ChatGPT to generate business use cases? This kind of business use case generation is actually very similar to the scenario approach to use case design, can we also directly input the business use case into ChatGPT and let it output test cases? I entered the relevant prompt words to let it add the test cases based on the business cases in the requirements specification, ChatGPT output as shown in Figure 3-5.

 

Figure 3-5 ChatGPT output of test cases partially supplemented based on the business cases in the requirements specification specification

Below are the complete test cases supplemented by ChatGPT's output based on the business use cases in the requirements specification.

ChatGPTOutput of complete test cases supplemented with business use cases based on the requirements specification.

According to the business use case UC-01, here are some test cases related to this use case to ensure the correctness and completeness of Baidu's keyword search function:

Test No.

test objective

pre-conditions

test step

Expected results

TC019

Basic Keyword Search - Valid Input

Users have entered the Baidu search page

1. Enter a valid keyword (e.g. "test") in the search box. <br> 2. Click the Search button.

Displays a page of search results related to the keyword.

TC020

Basic keyword search - multiple valid inputs

Users have entered the Baidu search page

1. Enter multiple valid keywords in the search box (e.g. "software testing methods"). <br> 2. Click the Search button.

Displays a page of search results related to multiple keywords.

TC021

Basic Keyword Search - No relevant results

Users have entered the Baidu search page

1. Enter a keyword in the search box, but the system is unable to find relevant results (e.g. "unknown keyword"). <br> 2. Click the Search button.

Display the appropriate notification to the user (e.g. "No relevant results found").

TC022

Basic Keyword Search - Cancel Search

Users have entered the Baidu search page

1. Enter a valid keyword in the search box (e.g. "test"). <br> 2. Cancel the search operation before it is executed.

The search operation is canceled and the use case ends.

TC023

Basic Keyword Search - Multiple Searches

Users have entered the Baidu search page

1. Enter a valid keyword (e.g. "test") in the search box. <br> 2. Click the Search button. <br> 3. Repeat steps 1 and 2 several times.

Search results are displayed correctly and search history is retained.

TC024

Basic Keyword Search - Boundary Value Testing

Users have entered the Baidu search page

1. Enter a very small keyword (e.g. "a") in the search box. <br> 2. Click the Search button.

Displays a page of search results related to the keyword.

TC025

Basic Keyword Search - Boundary Value Testing

Users have entered the Baidu search page

1. Enter an extremely long keyword (exceeding the character limit, e.g. "a" * 1000) into the search box. <br> 2. Click the Search button.

Displays an error message alert.

These test cases cover different scenarios in the main business use case UC-01, including valid input, no relevant results, cancel search operation, multiple searches, and boundary value testing. They help to verify that the Baidu keyword search function works properly according to the specification.

ChatGPT supplemented the test cases based on the business use case UC-01, which resulted in a more comprehensive coverage of the test cases in terms of usage scenarios for the operational processes.

4) Review and Improvement of Test Cases: The review and improvement of test cases is a key part of ensuring software quality. Combined with the functional and security test cases generated by ChatGPT in the previous section, the internal test case review of the test team was conducted. During the internal review, the test team members found the following problems.

  • Some test cases have test steps interspersed with <br> HTML tags.
  • Some test cases have sequential numbers for test steps with only 1 step.
  • Some test cases are duplicated, such as the TC001 (see Figure 3-3) and TC019 test cases, which are very similar.
  • Some test cases do not necessarily contain real database tables, such as the TC011 SQL injection attack test case, the users table may not exist, etc., and you need to further confirm with the R&D staff whether the table exists.
  • Is there a text input field that needs to be clarified, such as the maximum number of characters that can be entered in a keyword text input box is 1000? Is it allowed to input 1000 English characters, or 1000 Chinese or English characters? These need to be further clarified with the product staff.

 

Limited to space, the author only lists a few points, the test team for the review of the relevant test cases to amend the problem and clarify the question, after the test cases after the de-emphasis, the formation of Baidu keyword search business based on the functionality and security test case set, as shown in Table 3-1.

a meter (measuring sth)3-1 Baidu Keyword Search Business Based Functional and Security Test Case Set

Test No.

test objective

pre-conditions

test step

Expected results

TC001

Test for legal keywords in search input box

Users open Baidu search page

1. Enter a valid keyword in the search input box (e.g. "test")

2. Click on the search button

Displays the search results page.

TC002

Test for multiple legal keywords in search input box

Users open Baidu search page

1. Enter multiple valid keywords in the search input box (e.g. "software testing methods")

2. Click on the search button

Displays the search results page.

TC003

Test for search input box containing special characters

Users open Baidu search page

1. Enter special characters in the search input box (e.g. "#$%^")

2. Click on the search button

Displays an error message alert.

TC004

Basic Keyword Search - No relevant results

Users have entered the Baidu search page

1. A keyword is entered into the search box, but the system is unable to find relevant results (e.g., "unknown keyword").

2. Click the Search button.

Display the appropriate notification to the user (e.g. "No relevant results found").

TC005

Basic Keyword Search - Cancel Search

Users have entered the Baidu search page

1. Enter a valid keyword in the search box (e.g. "test").

2. Cancel the search operation before it is executed.

The search operation is canceled and the use case ends.

TC006

Basic Keyword Search - Multiple Searches

Users have entered the Baidu search page

1. Enter a valid keyword in the search box (e.g. "test").

2. Click the Search button.

3. Repeat steps 1 and 2 several times.

Search results are displayed correctly and search history is retained.

TC007

Basic Keyword Search - Boundary Value Testing

Users have entered the Baidu search page

1. Enter a very small keyword (e.g., "a") in the search box.

2. Click the Search button.

Displays a page of search results related to the keyword.

TC008

Basic Keyword Search - Boundary Value Testing

Users have entered the Baidu search page

1. Enter an extremely long keyword (exceeding the character limit, e.g., "a" * 1000) into the search box.

2. Click the Search button.

Displays an error message alert.

TC009

Search Suggestion Display Test

Users open Baidu search page

Enter some of the keywords in the search input box (e.g. "measure")

Displays a list of search suggestions.

TC010

Search suggests multiple partial keyword tests

Users open Baidu search page

Enter multiple partial keywords in the search input box (e.g. "software measurement")

Displays a list of search suggestions.

TC011

Validation against search results

The user enters a legitimate keyword and clicks the search button

Check the search results page

Displays relevant search results.

TC012

Next Page Button Test

The user enters a legitimate keyword and clicks the search button

Click on the Next Page button

Displays the next page of search results.

TC013

Previous Button Test

The user enters a legitimate keyword and clicks the search button

Click on the previous page button

Displays the search results from the previous page.

TC014

Sort Tests by Relevance

The user enters a legitimate keyword and clicks the search button

Select Sort by Relevance

Results are sorted by relevance.

TC015

Sort Tests by Time

The user enters a legitimate keyword and clicks the search button

Select to sort by time

Results are sorted by time.

TC016

SQL Injection Attack Test

User enters malicious SQL query in search input box (e.g., "'; DROP TABLE Users --")

Checking search results or page behavior

The query is rejected and an error message is displayed.

TC017

XSS Attack Test

The user enters the keyword containing the XSS script in the search input box (e.g., "<script>alert('XSS Attack')</script>")

Checking search results or page behavior

Filters and displays plain text.

TC018

Minimum Boundary Value Test for Search Input Box

Users open Baidu search page

Enter a space in the search input box

Displays search suggestions or search history.

TC019

Maximum boundary value test for search input box

Users open Baidu search page

Enter a long string in the search input box that exceeds the character limit (e.g., 1000 characters, 500 Chinese characters).

Displays an error message alert.

TC020

Search for suggested minimum boundary value tests

Users open Baidu search page

Enter a character in the search input box (e.g., "a").

Displays a list of search suggestions.

TC021

Search for suggested maximum boundary value tests

Users open Baidu search page

Entering multiple characters in the search input box is not enough to display search suggestions (e.g.: "abcde")

The list of search suggestions is not displayed.

TC022

Minimum Boundary Value Test for Search Results

The user enters a legitimate keyword and clicks the search button

Check the search results page

Displays relevant search results.

TC023

Maximum boundary value test for search results

The user enters a legitimate keyword and clicks the search button

Enter a keyword so that the number of results exceeds the limit (e.g., more than 1,000 results).

Displays an error message alert.

Often the test cases should also be carried out outside the not review. Inform the project team members of the storage location of the completed functional and security test case set based on Baidu keyword search business. It is necessary to set aside a certain amount of time to facilitate the reading of the project team's R&D and product personnel, so as not to take up too much time to familiarize themselves with the content of the relevant test cases at the project team's test case review meeting. In the project team test case review meeting, the relevant personnel actively review the test cases and put forward the following points.

1) For the test cases TC008, TC019 and TC023, the product staff clarified the characters of the search input box, i.e., whether it is Chinese or English characters, the maximum number of input characters is 100, whether it is Chinese characters, English characters or a mixture of Chinese and English characters, the front and back ends need to do the check, if the front-end input is more than 100 characters, the first 100 characters will be automatically intercepted. If the front-end input exceeds 100 characters, the first 100 characters will be automatically intercepted.

2) For the test case TC016, the product staff clarified the requirements, i.e., the SQL injection statement will be filtered and processed as ordinary text, and at the same time, the back-end developers also clarified the existence of users table.

3) For test case TC023, the product staff clarified the requirement that there is no limit to the number of search results.