Method and apparatus for generating test cases and test data
Patent Information
- Application Number
- CN202210544661.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-19
- Publication Date
- 2025-08-05
- Estimated Expiration
- 2042-05-19
AI Technical Summary
而对于较为复杂的模型,用例的编写和数据的铺底都较为繁琐,且重复的工作量较大
[0034] For the test case and test data generation method and device described in this application, first obtain the requirement document of the data model, perform modular analysis on the requirement document, and determine the table structure and corresponding fields involved in the data model. The data model is a set of SQL languages used to retrieve and filter data in the database. Then, determine the constraint fields, constraint conditions, constraint values, and return fields based on the data model, the table structure, and the corresponding fields, and write the constraint fields, constraint conditions, constraint values, and return fields into a preset template. Then use Python to read the preset template to obtain the constraint fields, constraint conditions, constraint values, and return fields. Finally, generate the test cases and test data for testing the data model based on the constraint fields, constraint conditions, constraint values, and return fields. Specifically, it includes: arranging and combining the constraint conditions to obtain combined values, setting the use case attributes according to the combined values, where the use case attributes include positive cases or negative cases, determining the test case steps corresponding to the combined values and constraint conditions, using the use case attributes to determine the expected results corresponding to the return fields, determining the test cases corresponding to the use case attributes, test case steps, and expected results to obtain the test cases for testing the data model, and generating test data that meets the requirements of the test cases according to the table structure and test cases. This application is used for automatically writing test cases and automatically generating test data in the test work of the data model, saving a large amount of manual operations, thereby improving the test efficiency on the premise of ensuring the test quality.
Smart Images

Figure CN114936154B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data testing technology, and in particular, to a method and device for generating test cases and test data. Background Art
[0002] With the development of society, enterprises are increasingly demanding data models. For example, banks require audit models for various lines of business, and models for categorizing individual customers for precision marketing. Using data models to manipulate raw data can efficiently and accurately extract the data required by business personnel, eliminating duplicate and invalid data. Currently, many business operations in banking systems rely on data models to process and refine data, providing accurate and effective data to business personnel.
[0003] A data model is a collection of SQL statements that are used to retrieve and filter complex data in a database. During data model testing, testers need to verify whether the model is flawed. In addition to writing high-quality test cases, they also need to prepare a foundation of data for the tables involved in the model. This foundation data must meet the test case's requirements for the model, such as including data required for boundary value testing and reverse test cases.
[0004] To this end, during the testing process, testers not only need to consider various scenarios and write effective test cases, but also lay out the data for the tables designed for the model based on the written test cases. For more complex models, writing test cases and laying out the data is tedious and requires a lot of repetitive work. Summary of the Invention
[0005] In view of the problems mentioned above, the present application provides a method and apparatus for generating test cases and test data, which are used to automatically write test cases and automatically generate test data in the testing work of a data model.
[0006] In order to achieve the above objectives, this application provides the following technical solutions:
[0007] A method for generating test cases and test data, comprising:
[0008] Obtain a data model requirement document and perform modular analysis on the requirement document to determine the table structure and corresponding fields involved in the data model. The data model is a set of SQL language, which is used to retrieve and filter data in the database using SQL language;
[0009] Determine the constraint fields, constraint conditions, constraint values, and return fields according to the data model, the table structure, and the corresponding fields, and write the constraint fields, the constraint conditions, the constraint values, and the return fields into a preset template;
[0010] Use Python to read the preset template to obtain the constraint field, the constraint condition, the constraint value, and the return field;
[0011] According to the constraint field, the constraint condition, the constraint value and the return field, test cases and test data for the data model test are generated, which includes: arranging and combining the constraint conditions to obtain a combination value, setting use case attributes according to the combination value, the use case attributes including a forward case or a reverse case, determining the test case steps corresponding to the combination value and the constraint condition, using the use case attributes to determine the expected result corresponding to the return field, determining the test case corresponding to the use case attributes, the test case steps and the expected result, obtaining the test case for the data model test, and generating test data that meets the test case requirements according to the table structure and the test case.
[0012] Furthermore, setting the use case attribute according to the combined value includes:
[0013] When the combination value is (>&&!=), set the use case attribute to a positive use case;
[0014] When the combination value is not (>&&!=), the use case attribute is set to a reverse use case.
[0015] Furthermore, based on the table structure and the test case, test data that meets the test case requirements is generated, including:
[0016] According to the table structure, obtain the SQL statement corresponding to the test case;
[0017] Based on the sql statement, generate test data that meets the test case requirements.
[0018] Furthermore, the preset template is read using Python to obtain the constraint field, the constraint condition, the constraint value, and the return field, including:
[0019] Paste the preset template into Excel, use Python to read the Excel, and obtain the constraint field, the constraint condition, the constraint value, and the return field.
[0020] Furthermore, after using Python to read the preset template and obtain the constraint field, the constraint condition, the constraint value, and the return field, the method further includes:
[0021] Write the constraint field and the constraint condition into the Constraint_Field dictionary variable,
[0022] Write the constraint value into the Con_value variable.
[0023] Furthermore, the test case includes a test case number, test case attributes, test case steps and expected results.
[0024] A device for generating test cases and test data, comprising:
[0025] A first processing unit is configured to obtain a data model requirement document and perform modular analysis on the requirement document to determine the table structure and corresponding fields involved in the data model. The data model is a set of SQL language, and is used to retrieve and filter data in the database using the SQL language.
[0026] a second processing unit, configured to determine, based on the data model, the table structure, and the corresponding fields, a constraint field, a constraint condition, a constraint value, and a return field, and write the constraint field, the constraint condition, the constraint value, and the return field into a preset template;
[0027] A third processing unit is configured to use Python to read the preset template and obtain the constraint field, the constraint condition, the constraint value, and the return field;
[0028] The fourth processing unit is used to generate test cases and test data for the data model test based on the constraint field, the constraint condition, the constraint value and the return field, which includes: arranging and combining the constraint conditions to obtain a combination value, setting use case attributes according to the combination value, the use case attributes including a forward case or a reverse case, determining the test case steps corresponding to the combination value and the constraint condition, using the use case attributes to determine the expected result corresponding to the return field, determining the test case corresponding to the use case attributes, the test case steps and the expected result, obtaining the test case for the data model test, and generating test data that meets the test case requirements according to the table structure and the test case.
[0029] Furthermore, generating test data that meets the test case requirements based on the table structure and the test case includes:
[0030] According to the table structure, obtain the SQL statement corresponding to the test case;
[0031] Based on the sql statement, generate test data that meets the test case requirements.
[0032] A storage medium includes a stored program, wherein when the program is run, the device where the storage medium is located is controlled to execute the method for generating test cases and test data as described above.
[0033] An electronic device comprising at least one processor, and at least one memory and a bus connected to the processor; wherein the processor and the memory communicate with each other via the bus; and the processor is configured to call program instructions in the memory to execute the test case and test data generation method described above.
[0034] The method and device for generating test cases and test data described in the present application first obtain a data model requirement document and perform modular analysis on the requirement document to determine the table structure and corresponding fields involved in the data model, wherein the data model is a collection of SQL languages and is used to retrieve and filter data in a database using SQL languages; then, based on the data model, the table structure and the corresponding fields, constraint fields, constraint conditions, constraint values and return fields are determined, and the constraint fields, constraint conditions, constraint values and return fields are written into a preset template; then, Python is used to read the preset template to obtain the constraint fields, constraint conditions, constraint values and return fields; finally, based on the constraint fields, constraint conditions, constraint values and return fields, test cases and test data for testing the data model are generated according to the constraint fields, constraint conditions, constraint values and return fields, which includes: arranging and combining the constraint conditions to obtain combination values, setting use case attributes according to the combination values, the use case attributes including forward cases or reverse cases, determining the test case steps corresponding to the combination values and constraint conditions, using the use case attributes to determine the expected results corresponding to the return fields, determining the test cases corresponding to the use case attributes, test case steps and expected results, obtaining test cases for testing the data model, and generating test data that meets the test case requirements according to the table structure and the test cases. This application is used to automatically write test cases and automatically generate test data in data model testing work, eliminating a lot of manual operations, thereby improving test efficiency while ensuring test quality. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0036] Figure 1 A flowchart of a method for generating test cases and test data disclosed in an embodiment of the present application;
[0037] Figure 2 A schematic diagram of the structure of a device for generating test cases and test data disclosed in an embodiment of the present application;
[0038] Figure 3 This is a schematic structural diagram of an electronic device disclosed in an embodiment of the present application. DETAILED DESCRIPTION
[0039] The applicant found in their research that during the testing process, testers not only need to consider various situations and write effective test cases, but also need to lay the foundation for the data of the tables designed for the model based on the written test cases. The existing technical solutions for testing data models mainly use manual testing methods: by performing functional analysis on the requirements document, analyzing the specific data screening logic of the model, and using the effective equivalence class and boundary value method to write effective test cases; after the case is written, it is also necessary to sort out the tables involved in the data model, clarify the data structure of the tables involved and the screening fields required by the model, and insert the foundation data in combination with the written test cases. It should be noted that the inserted foundation data supports each written test case, ensuring that each test case will have corresponding execution results when executed; after completing the preparation of data and cases, the tester executes the data model and compares and verifies the execution results with the relevant logic of the data model to ensure the accuracy of the data model.
[0040] In the above-mentioned existing technical solutions, both test cases and test data must be manually written, and the test data must be inserted one by one according to the test cases. For more complex models, writing test cases and laying the test data are both tedious and repetitive.
[0041] Based on the above-mentioned industry pain points, this application needs to first conduct a modular analysis of the data model's requirement document, and then determine the constraint fields, constraint conditions, constraint values and return fields based on the data model, table structure and corresponding fields, and write the constraint fields, constraint conditions, constraint values and return fields into the preset template. Use Python to read the template to obtain the constraint fields, constraint conditions, constraint values and return fields, and finally automatically generate test cases and associated underlying data for data model testing based on the constraint fields, constraint conditions, constraint values and return fields, which includes: arranging and combining the constraint conditions to obtain the combination value, setting the use case attributes according to the combination value, the use case attributes include forward cases or reverse cases, determining the test case steps corresponding to the combination value and constraint conditions, using the use case attributes to determine the expected results corresponding to the return fields, determining the test cases corresponding to the use case attributes, test case steps and expected results, obtaining test cases for data model testing, and generating test data that meets the test case requirements based on the table structure and test cases.
[0042] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0043] Please see the attached Figure 1 , is a flow chart of a method for generating test cases and test data provided by an embodiment of the present application. Figure 1 As shown, an embodiment of the present application provides a method for generating test cases and test data, the method comprising the following steps:
[0044] S101: Obtain a data model requirement document and perform modular analysis on the requirement document to determine the table structure and corresponding fields involved in the data model. The data model is a set of SQL language, which is used to retrieve and filter data in the database using SQL language.
[0045] S102: Determine a constraint field, constraint conditions, constraint value, and return field based on the data model, the table structure, and corresponding fields, and write the constraint field, the constraint conditions, the constraint value, and the return field into a preset template;
[0046] S103: Using Python to read the preset template, obtain the constraint field, the constraint condition, the constraint value, and the return field;
[0047] S104: Generate test cases and test data for the data model test according to the constraint field, the constraint condition, the constraint value, and the return field;
[0048] Among them, it includes: arranging and combining the constraints to obtain a combination value, setting use case attributes according to the combination value, the use case attributes including a forward case or a reverse case, determining the test case steps corresponding to the combination value and the constraints, using the use case attributes to determine the expected result corresponding to the return field, determining the test case corresponding to the use case attributes, the test case steps and the expected result, obtaining a test case for the data model test, and generating test data that meets the test case requirements according to the table structure and the test case.
[0049] It should be noted that, in the embodiment of the present application, the above-mentioned setting of the use case attribute according to the combination value includes:
[0050] When the combination value is (>&&!=), set the use case attribute to a positive use case;
[0051] When the combination value is not (>&&!=), the use case attribute is set to a reverse use case.
[0052] In the embodiment of the present application, based on the table structure and the test case, test data that meets the test case requirements is generated, including:
[0053] According to the table structure, obtain the SQL statement corresponding to the test case;
[0054] Based on the sql statement, generate test data that meets the test case requirements.
[0055] In the embodiment of the present application, Python is used to read the preset template to obtain the constraint field, the constraint condition, the constraint value, and the return field, including:
[0056] Paste the preset template into Excel, use Python to read the Excel, and obtain the constraint field, the constraint condition, the constraint value, and the return field.
[0057] In the embodiment of the present application, after using Python to read the preset template and obtain the constraint field, the constraint condition, the constraint value, and the return field, the following steps are further included:
[0058] The constraint field and the constraint condition are written into the Constraint_Field dictionary variable, and the constraint value is written into the CON_VALUE variable.
[0059] In an embodiment of the present application, the above-mentioned test case includes a test case number, test case attributes, test case steps and expected results.
[0060] This application uses the bank's loan-to-deposit ratio model to illustrate its proposed solution. For example, a branch will conduct targeted marketing and send marketing text messages to customers whose loan-to-deposit ratio is higher than 100%. The information of customers with a loan-to-deposit ratio higher than 100% needs to be screened out.
[0061] First, analyze the loan-to-deposit ratio model. The data constraint field of this model is the loan-to-deposit ratio. The loan-to-deposit ratio is calculated as deposit balance / loan balance. This row updates the loan balance and deposit balance tables on the 1st of each month. This model performs data filtering after the data is updated on the 1st of each month. Table 1 lists the tables and fields involved in deposit balances. Table 2 lists the tables involved in loan balances. Tables 3 and 4 list the detailed table structures of tables HQYEB and DQYEB involved in deposit balances. Table 5 lists the detailed table structure of table DKYEB involved in loan balances.
[0062] Table 1 Deposit balance related tables and corresponding fields
[0063]
[0064]
[0065] Table 2 Loan balance related tables and corresponding fields
[0066]
[0067] Table 3 HQYEB specific table structure
[0068] Field Name Field English name type Primary Key Is it inevitable to lose? Customer Number CustNo VARCHAR2(50) Y Y Current account balance CurBalance INTEGER Y Updated Date Update_Date DATE Y
[0069] Table 4DQYEB specific table structure
[0070] Field Name Field English name type Primary Key Is it inevitable to lose? Customer Number CustNo VARCHAR2(50) Y Y Regular balance FixBalance INTEGER Y Updated Date Update_Date DATE Y
[0071] Table 5DKYEB specific table structure
[0072] Field Name Field English name type primary key Is it inevitable to lose? Customer Number CustNo VARCHAR2(50) Y Y Regular balance LoanBalance INTEGER Y Updated Date Update_Date DATE Y
[0073] The table structures involved in the model have been listed above one by one. Then the steps to generate cases and underlying data are as follows:
[0074] Table 6 Model constraints and return value analysis
[0075] Model Name Constraint fields Constraints Constraint Value Return Field Loan-to-deposit ratio (CurBalance+FixBalance) / LoanBalance > 100% CustNo Loan-to-deposit ratio LoanBalance != 0
[0076] Table 6 lists the model constraints and return fields. This completes the model's requirements analysis. Paste the table into Excel and read it using Python.
[0077] After that, read the Excel file, write the loan-to-deposit ratio into the Testcase_Name list variable, write the constraint field and its corresponding constraint condition into the Constraint_Field dictionary variable, and write the constraint value into the Con_value variable.
[0078] Table 7 Test case template
[0079] Test case number Use Case Properties Use Case Steps Expected Results
[0080] Table 7 is a test case template, and subsequent cases will be automatically generated according to this template.
[0081] The test case number column will be filled with Testcase_Name-i, where i is a custom variable and is initially set to 0. Each time a case number is entered, set i = i + 1, and the case attribute is either a forward or reverse case. The constraint condition in the first row is read as ">", followed by the constraint condition in the second row as "!=". The two constraints are permuted and combined. When the combination value is (>&&!=), the case attribute is written to the forward direction; when the combination value is not (>&&!=), the case attribute is written to the reverse direction. Furthermore, according to the combination value matching step, the Constraint_Field dictionary variable is used to match the dictionary index with the corresponding item in the combination value and fill in the constraint value Con_value. For example, when the combination value is (>&&!=), the loan-to-deposit ratio is filled in as >100%, and the loan balance is filled in as !=0. When the combination value is (=&&!=), the loan-to-deposit ratio is filled in as =100% and the loan balance is filled in as !=0. This process continues in this way, completing the case steps for all possible test cases. The expected result column is filled with the dependent use case attributes. According to Table 6, the return field is CustNo, and according to Tables 3, 4, and 5, the field CustNo is of type VARCHAR2(50). The value of CustNo can be randomly generated. When the use case attribute is positive, the expected result is filled in and the corresponding CustNo is successfully displayed. When the use case attribute is negative, the expected result is filled in and the corresponding CustNo value is not displayed. Based on the association relationship and generation rules between the above use cases, the test case shown in Table 8 can be obtained.
[0082] Table 8 Automatically generated model test cases
[0083]
[0084]
[0085] Finally, after obtaining the above test cases, test data is automatically generated based on the test cases. The model involves three tables: HQYEB, DQYEB, and DKYEB. Based on the table structure, the SQL statements for each case can be obtained. For example, the SQL statement associated with the case of loan-to-deposit ratio -1 is:
[0086] HQYEB: Insert into HQYEB values (CustNo of use case 1, randomly generated current account balance, 1st of the month);
[0087] DQYEB: Insert into HQYEB values (CustNo of Use Case 1, randomly generated periodic balance, 1st of the month);
[0088] DKYEB: Insert into HQYEB values (Use the CustNo of Use Case 1 to generate a random number smaller than the current and fixed deposit balances above, on the 1st of the month)
[0089] It's important to note that, according to the constraints, the loan balance in the loan balance table can be set to a random number less than the sum of the current and fixed balances, the date set to the 1st of each month, and the CustNo set to the generated CustNo for each case. Following this rule, we can ultimately obtain test data corresponding to each case.
[0090] An embodiment of the present application provides a method for generating test cases and test data. The method comprises the following steps: first, obtaining a data model requirement document, performing a modular analysis on the requirement document, determining a table structure and corresponding fields involved in the data model, wherein the data model is a collection of SQL languages and is used to retrieve and filter data in a database using the SQL language; then, determining constraint fields, constraint conditions, constraint values, and return fields based on the data model, the table structure, and corresponding fields, and writing the constraint fields, constraint conditions, constraint values, and return fields into a preset template; then, reading the preset template using Python to obtain the constraint fields, constraint conditions, constraint values, and return fields; and finally, generating test cases and test data for testing the data model based on the constraint fields, constraint conditions, constraint values, and return fields. The method comprises: arranging and combining the constraint conditions to obtain a combination value, setting a use case attribute based on the combination value, the use case attribute including a forward case or a reverse case, determining a test case step corresponding to the combination value and the constraint condition, determining an expected result corresponding to the return field using the use case attribute, determining a test case corresponding to the use case attribute, the test case step, and the expected result, obtaining a test case for testing the data model, and generating test data that meets the test case requirements based on the table structure and the test case. The embodiment of the present application is used to automatically write test cases and automatically generate test data in the testing work of the data model, eliminating a large amount of manual operations, thereby improving testing efficiency while ensuring test quality.
[0091] See also Figure 2 Based on the method for generating a test case and test data disclosed in the above embodiment, this embodiment correspondingly discloses a device for generating a test case and test data, the device comprising:
[0092] The first processing unit 201 is used to obtain a data model requirement document and perform modular analysis on the requirement document to determine the table structure and corresponding fields involved in the data model. The data model is a set of SQL language, which is used to retrieve and filter data in the database using SQL language;
[0093] A second processing unit 202 is configured to determine a constraint field, a constraint condition, a constraint value, and a return field based on the data model, the table structure, and the corresponding fields, and write the constraint field, the constraint condition, the constraint value, and the return field into a preset template;
[0094] The third processing unit 203 is configured to use Python to read the preset template and obtain the constraint field, the constraint condition, the constraint value, and the return field;
[0095] The fourth processing unit 204 is used to generate test cases and test data for the data model test based on the constraint field, the constraint condition, the constraint value and the return field, which includes: arranging and combining the constraint conditions to obtain a combination value, setting use case attributes according to the combination value, the use case attributes including a forward case or a reverse case, determining the test case steps corresponding to the combination value and the constraint condition, using the use case attributes to determine the expected result corresponding to the return field, determining the test case corresponding to the use case attributes, the test case steps and the expected result, obtaining the test case for the data model test, and generating test data that meets the test case requirements according to the table structure and the test case.
[0096] Furthermore, the fourth processing unit 204 is configured to:
[0097] According to the combined value, set the use case attributes, including:
[0098] When the combination value is (>&&!=), set the use case attribute to a positive use case;
[0099] When the combination value is not (>&&!=), the use case attribute is set to a reverse use case.
[0100] Furthermore, the fourth processing unit 204 is configured to:
[0101] Generate test data that meets the test case requirements based on the table structure and test case, including:
[0102] According to the table structure, obtain the SQL statement corresponding to the test case;
[0103] Based on the sql statement, generate test data that meets the test case requirements.
[0104] Furthermore, the third processing unit 203 is configured to:
[0105] Use Python to read the preset template to obtain the constraint field, the constraint condition, the constraint value, and the return field, including:
[0106] Paste the preset template into Excel, use Python to read the Excel, and obtain the constraint field, the constraint condition, the constraint value, and the return field.
[0107] Furthermore, after the third processing unit 203 is configured to use Python to read the preset template and obtain the constraint field, the constraint condition, the constraint value, and the return field, the following steps are further included:
[0108] Write the constraint field and the constraint condition into the Constraint_Field dictionary variable,
[0109] Write the constraint value into the Con_value variable.
[0110] Furthermore, the test case includes a test case number, test case attributes, test case steps and expected results.
[0111] The device for generating test cases and test data includes a processor and a memory. The above-mentioned first processing unit, second processing unit, third processing unit and fourth processing unit are all stored in the memory as program units, and the processor executes the above-mentioned program units stored in the memory to realize corresponding functions.
[0112] The processor contains a kernel, which retrieves the corresponding program unit from memory. One or more kernels can be configured, and by adjusting kernel parameters, test cases and test data can be automatically written for data model testing, eliminating manual work and improving test efficiency while ensuring test quality.
[0113] An embodiment of the present application provides a storage medium on which a program is stored. When the program is executed by a processor, the method for generating test cases and test data is implemented.
[0114] An embodiment of the present application provides a processor, which is used to run a program, wherein the method for generating test cases and test data is executed when the program is run.
[0115] The present application embodiment provides an electronic device, such as Figure 3 As shown, the electronic device 30 includes at least one processor 301, and at least one memory 302 and a bus 303 connected to the processor; wherein the processor 301 and the memory 302 communicate with each other through the bus 303; the processor 301 is used to call the program instructions in the memory 302 to execute the above-mentioned test case and test data generation method.
[0116] The electronic devices in this article can be servers, PCs, PADs, mobile phones, etc.
[0117] The present application also provides a computer program product which, when executed on a data processing device, is adapted to execute a program for initializing the following method steps:
[0118] Obtain a data model requirement document and perform modular analysis on the requirement document to determine the table structure and corresponding fields involved in the data model. The data model is a set of SQL language, which is used to retrieve and filter data in the database using SQL language;
[0119] Determine the constraint fields, constraint conditions, constraint values, and return fields according to the data model, the table structure, and the corresponding fields, and write the constraint fields, the constraint conditions, the constraint values, and the return fields into a preset template;
[0120] Use Python to read the preset template to obtain the constraint field, the constraint condition, the constraint value, and the return field;
[0121] According to the constraint field, the constraint condition, the constraint value and the return field, test cases and test data for the data model test are generated, which includes: arranging and combining the constraint conditions to obtain a combination value, setting use case attributes according to the combination value, the use case attributes including a forward case or a reverse case, determining the test case steps corresponding to the combination value and the constraint condition, using the use case attributes to determine the expected result corresponding to the return field, determining the test case corresponding to the use case attributes, the test case steps and the expected result, obtaining the test case for the data model test, and generating test data that meets the test case requirements according to the table structure and the test case.
[0122] Furthermore, setting the use case attribute according to the combined value includes:
[0123] When the combination value is (>&&!=), set the use case attribute to a positive use case;
[0124] When the combination value is not (>&&!=), the use case attribute is set to a reverse use case.
[0125] Furthermore, based on the table structure and the test case, test data that meets the test case requirements is generated, including:
[0126] According to the table structure, obtain the SQL statement corresponding to the test case;
[0127] Based on the sql statement, generate test data that meets the test case requirements.
[0128] Furthermore, the preset template is read using Python to obtain the constraint field, the constraint condition, the constraint value, and the return field, including:
[0129] Paste the preset template into Excel, use Python to read the Excel, and obtain the constraint field, the constraint condition, the constraint value, and the return field.
[0130] Furthermore, after using Python to read the preset template and obtain the constraint field, the constraint condition, the constraint value, and the return field, the method further includes:
[0131] Write the constraint field and the constraint condition into the Constraint_Field dictionary variable,
[0132] Write the constraint value into the Con_value variable.
[0133] Furthermore, the test case includes a test case number, test case attributes, test case steps and expected results.
[0134] The present application is described in terms of flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the steps in the flowchart and / or block diagram. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0135] In a typical configuration, the device includes one or more processors (CPUs), memory, and a bus. The device may also include input / output interfaces, network interfaces, and the like.
[0136] Memory may include non-permanent memory in a computer-readable medium, random access memory (RAM), and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory includes at least one memory chip. Memory is an example of a computer-readable medium.
[0137] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0138] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.
[0139] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present application may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0140] The above are merely embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application should all be included within the scope of the claims of the present application.
Claims
1. A method for generating test cases and test data, characterized in that: include: Obtain a data model requirement document and perform modular analysis on the requirement document to determine the table structure and corresponding fields involved in the data model. The data model is a set of SQL language, which is used to retrieve and filter data in the database using SQL language; Determine the constraint fields, constraint conditions, constraint values, and return fields according to the data model, the table structure, and the corresponding fields, and write the constraint fields, the constraint conditions, the constraint values, and the return fields into a preset template; Use Python to read the preset template to obtain the constraint field, the constraint condition, the constraint value, and the return field; Generate test cases and test data for the data model test according to the constraint field, the constraint condition, the constraint value, and the return field, including: The constraints are arranged and combined to obtain a combination value, and use case attributes are set according to the combination value, wherein the use case attributes include a forward case or a reverse case, and the test case steps corresponding to the combination value and the constraints are determined. The expected result corresponding to the return field is determined using the use case attributes, and the test case corresponding to the use case attributes, the test case steps and the expected result is determined to obtain a test case for the data model test, and test data that meets the test case requirements is generated according to the table structure and the test case.
2. The method for generating test cases and test data according to claim 1, wherein: According to the combined value, set the use case attributes, including: When the combination value is (>&&!=), set the use case attribute to a positive use case; When the combination value is not (>&&!=), the use case attribute is set to a reverse use case.
3. The method for generating test cases and test data according to claim 1, wherein: Generate test data that meets the test case requirements based on the table structure and test case, including: According to the table structure, obtain the SQL statement corresponding to the test case; Based on the sql statement, generate test data that meets the test case requirements.
4. The method for generating test cases and test data according to claim 1, wherein: Use Python to read the preset template to obtain the constraint field, the constraint condition, the constraint value, and the return field, including: Paste the preset template into Excel, use Python to read the Excel, and obtain the constraint field, the constraint condition, the constraint value, and the return field.
5. The method for generating test cases and test data according to claim 1, wherein: After using Python to read the preset template and obtain the constraint field, the constraint condition, the constraint value, and the return field, the method further includes: Write the constraint field and the constraint condition into the Constraint_Field dictionary variable, Write the constraint value into the Con_value variable.
6. The method for generating test cases and test data according to claim 1, wherein: The test case includes a test case number, test case attributes, test case steps and expected results.
7. A device for generating test cases and test data, characterized in that: include: A first processing unit is configured to obtain a data model requirement document and perform modular analysis on the requirement document to determine the table structure and corresponding fields involved in the data model, wherein the data model is a set of SQL language and is used to retrieve and filter data in the database using the SQL language; a second processing unit, configured to determine, based on the data model, the table structure, and the corresponding fields, a constraint field, a constraint condition, a constraint value, and a return field, and write the constraint field, the constraint condition, the constraint value, and the return field into a preset template; A third processing unit is configured to use Python to read the preset template and obtain the constraint field, the constraint condition, the constraint value, and the return field; The fourth processing unit is configured to generate a test case and test data for the data model test according to the constraint field, the constraint condition, the constraint value, and the return field, including: The constraints are arranged and combined to obtain a combination value, and use case attributes are set according to the combination value, wherein the use case attributes include a forward case or a reverse case, and the test case steps corresponding to the combination value and the constraints are determined. The expected result corresponding to the return field is determined using the use case attributes, and the test case corresponding to the use case attributes, the test case steps and the expected result is determined to obtain a test case for the data model test, and test data that meets the test case requirements is generated according to the table structure and the test case.
8. The device for generating test cases and test data according to claim 7, characterized in that: Generating test data that meets the test case requirements based on the table structure and the test case includes: According to the table structure, obtain the SQL statement corresponding to the test case; Based on the sql statement, generate test data that meets the test case requirements.
9. A storage medium, characterized in that: The storage medium includes a stored program, wherein when the program is run, the device where the storage medium is located is controlled to execute the method for generating test cases and test data according to any one of claims 1 to 6.
10. An electronic device, characterized in that: The electronic device includes at least one processor, and at least one memory and a bus connected to the processor; wherein the processor and the memory communicate with each other through the bus; the processor is used to call program instructions in the memory to execute the test case and test data generation method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Method and device for generating test data automatically by utilizing structured query language (SQL) sentences
CN102043720A
Testing method and device for database storage process, processing equipment and medium
CN114090457A