Software testing/test development丨Use artificial intelligence ChatGPT to generate test data in batches

Click here for more relevant information

Introduction

Test data refers to a set of data focused on serving testing. It can be used as input for functions to verify output, and can also trigger various abnormal scenarios.

The design of test data is particularly important. Test case design methods such as equivalence classes, boundary values, and orthogonal methods are all designed to design the corresponding test data set more comprehensively.

Practical drills

When generating test data in batches, we need to clarify the data type, format, and requirements. Then input this information into ChatGPT, and ChatGPT will help us automatically generate test data.

So how to let ChatGPT automatically generate test data?

1. Provide the corresponding demand information to ChatGPT.

2. Specify the output format of the data.

Assume the following is our requirement:

It is required to add an input box. The input box can only enter Chinese mobile phone numbers. Then we can write our prompt words in the following way:

  • Prompt word: It is required to add an input box. The input box can only enter Chinese mobile phone numbers. Please help me generate some test data based on the above requirements.
很抱歉,由于我目前无法直接操作图形界面或添加实际的输入框,我无法为您生成实际的测试数据。但是,我可以为您提供一些模拟的测试数据,以供参考。请注意,这些数据是随机生成的,仅用于测试目的。
模拟的中国手机号码测试数据:
1. 13812345678
2. 15098765432
3. 13456789012
4. 13987654321
5. 13678901234

请确保在实际测试中使用合法的手机号码,并根据您的需求进行适当的验证。

Such return information obviously does not take into account abnormal scenarios and does not meet our needs. We can continue to make further additions.

  • Tip: Please consider the test data of abnormal scenarios
当然,为了全面测试输入框的有效性和鲁棒性,您可以考虑以下异常场景的测试数据:

1. 非数字字符:
   - 输入:abcde123456
   - 输入:1a2b3c4d5e6

2. 长度不正确的手机号码:
   - 输入:1391234567(缺少一位)
   - 输入:138123456789(超过11位)

3. 非中国手机号码:
   - 输入:+8613812345678
   - 输入:02012345678(固定电话)

4. 特殊字符:
   - 输入:13912#45678
   - 输入:15098&65432

5. 空输入:
   - 输入:(留空)

6. 其他异常情况:
   - 输入:00000000000(看起来像是假号码)
   - 输入:19912345678(虽然长度和格式正确,但可能是未来的号码)

请确保您的输入框能够正确地识别并处理这些异常情况,并向用户提供相应的错误提示或反馈。这样可以确保用户输入的有效性和系统的稳定性。

This will make the generated test data more complete.

Insert image description here

In addition, the format information of the generated test data can also be limited. For example, if the generated test data needs to be used by the code, the format of the generated test data can be limited.

  • Tip: Please use yaml format to output the above test data.

In this way, test cases that meet the needs can be generated through different prompt words.

Summarize

The generation of test data actually follows the techniques and principles of prompt words:

  1. Write clear requirements: It is necessary to clarify the content range, data type, etc. of the test data.
  2. Split complex tasks into simpler subtasks: If you plan to generate a relatively complex data information from the beginning, you can gradually disassemble it from the input range, format, etc.
  3. System test changes: If the data output by the intermediate steps does not meet the needs, you can correct and supplement it through prompt words.

Guess you like

Origin blog.csdn.net/Ceshiren666/article/details/134398408