Data processing method and related device

By automatically building test cases and generating test data, the problems of repeated construction and missed detection in existing unit tests are solved, and the efficiency and accuracy of unit detection are improved.

CN119149389APending Publication Date: 2024-12-17MASHANG CONSUMER FINANCE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410996905.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-23
Publication Date
2024-12-17

AI Technical Summary

Technical Problem

Existing unit testing methods require manual construction of test cases for each data to be tested, resulting in repeated construction of test data and possible missed detection, affecting efficiency and accuracy.

Method used

By automatically building test cases based on the type of data to be tested, including data unit nouns, request parameters, dependency data units, expected return data samples and verification methods, test data are generated for automatic testing, avoiding repeated detection and missed detection.

Benefits of technology

Improve the efficiency and accuracy of unit detection, simplify the generation process of test cases, and ensure full coverage of test data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119149389A_ABST
    Figure CN119149389A_ABST
Patent Text Reader

Abstract

The invention provides a data processing method and a related device, and the method comprises the steps: determining to-be-tested data in a first data set; constructing a test case corresponding to the to-be-tested data, wherein the test case comprises a data unit noun, a request parameter, a dependent data unit, an expected return data sample and a verification mode; generating test data according to the test case; and testing the to-be-tested data according to the test data to obtain a test result. According to the method, the test case corresponding to the to-be-tested data can be automatically constructed, and the test data is generated according to the test case for data testing, so that the data is automatically tested, and the data testing efficiency is improved; in addition, the data unit noun, the request parameter, the dependent data unit, the expected return data sample and the verification mode included in the test case are generated at a time, the generation mode of the test case is simplified, and the data test efficiency is further improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a data processing method and related devices. Background Art

[0002] Unit testing refers to the inspection and verification of the smallest testable unit in the software, and its purpose is to verify the correctness of the basic components of the software. A unit test is a small piece of code written by the developer to verify whether a small and clear function of the tested code is correct. Generally speaking, a unit test is used to determine the behavior of a specific function under a specific condition (or scenario). For example, you can put a large value into an ordered list and then confirm that the value appears at the end of the list. Or, you can delete characters that match a certain pattern from a string and then confirm that the string no longer contains these characters. Summary of the invention

[0003] In view of this, the present application provides a data processing method and related devices, which can automatically construct corresponding test cases based on the type of data to be tested, while avoiding missed detection and repeated detection of the same data to be tested, greatly improving the efficiency of unit detection.

[0004] In a first aspect, an embodiment of the present application provides a data processing method, the method comprising:

[0005] Determine the data to be tested in the first data set;

[0006] Constructing a test case corresponding to the data to be tested, wherein the test case includes a data unit noun, a request parameter, a dependent data unit, an expected return data sample, and a verification method;

[0007] Generate test data according to the test case;

[0008] The data to be tested is tested according to the test data to obtain a test result.

[0009] In a second aspect, an embodiment of the present application provides a data processing device, the device comprising:

[0010] A determination unit, used to determine the data to be tested in the first data set;

[0011] A construction unit, used to construct a test case corresponding to the data to be tested, wherein the test case includes a data unit noun, a request parameter, a dependent data unit, an expected return data sample, and a verification method;

[0012] A generating unit, used for generating test data according to the test case;

[0013] The testing unit is used to test the data to be tested according to the test data to obtain a test result.

[0014] In a third aspect, an embodiment of the present application provides an electronic device, comprising a processor, a memory, a communication interface, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the processor, and the program includes instructions for executing the steps of any method in the first aspect of the embodiment of the present application.

[0015] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program for electronic data exchange, wherein the computer program enables a computer to execute part or all of the steps described in any method of the first aspect of the embodiment of the present application.

[0016] In a fifth aspect, an embodiment of the present application provides a computer program product, wherein the computer program product includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to cause a computer to execute some or all of the steps described in any method of the first aspect of the embodiment of the present application. The computer program product may be a software installation package.

[0017] It can be seen that in the embodiment of the present application, test cases corresponding to the data to be tested are automatically constructed, and test data is generated according to the test cases for data testing, thereby realizing automatic testing of the data and improving data testing efficiency. In addition, the data unit nouns, request parameters, dependent data units, expected return data samples and verification methods included in the test cases are generated at one time, which simplifies the test case generation method and further improves data testing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying any creative work.

[0019] Figure 1 A system architecture diagram of a data processing method provided in an embodiment of the present application;

[0020] Figure 2 A flowchart of a data processing method provided in an embodiment of the present application;

[0021] Figure 3 A flowchart of another data processing method provided in an embodiment of the present application;

[0022] Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application;

[0023] Figure 5 A block diagram of the functional units of a data processing device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0024] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0025] The terms "first", "second", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices.

[0026] It should be understood that the term "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article indicates that the associated objects before and after are in an "or" relationship. The "plurality" appearing in the embodiments of the present application refers to two or more.

[0027] In the embodiments of the present application, "at least one item" or similar expressions refer to any combination of these items, including any combination of single items or plural items, and refer to one or more, and multiple refers to two or more. For example, at least one item of a, b, or c can represent the following seven situations: a, b, c, a and b, a and c, b and c, a, b, and c. Among them, each of a, b, and c can be an element or a set containing one or more elements.

[0028] The "connection" that appears in the embodiments of the present application refers to various connection methods such as direct connection or indirect connection to achieve communication between devices, and the embodiments of the present application do not impose any limitations on this.

[0029] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0030] The following is an explanation of the relevant contents, concepts, meanings, technical issues, technical solutions, beneficial effects, etc. involved in the embodiments of the present application.

[0031] I. Related terms

[0032] JavaScript Object Notation (JSON): is a lightweight data exchange format used for data transmission, storage, and exchange between the front-end and back-end. JSON formatted data consists of key-value pairs, where key-value pairs are separated by commas. In JSON, both keys and values ​​must be enclosed in double quotes.

[0033] JSON Schema: A standard for defining JSON data constraints. Based on this agreed model, both parties exchanging data can understand the requirements and constraints of JSON data, and can also verify the data accordingly to ensure the correctness of data exchange.

[0034] JSON Path: By using JsonPath, you can easily find nodes and get the desired data.

[0035] A call graph is a control flow graph that represents the calling relationship between subroutines in a computer program. Each node represents a process.

[0036] Mockito: The main function of the mock testing framework is to simulate the behavior of classes / objects. Mockito is generally used to control the return value of external calls, allowing us to only care about and test our own business logic.

[0037] Virtual implementation Mock: refers to a virtual implementation of an object, which has the same methods and properties as the real object, but the methods are not actually executed.

[0038] 2. Application scenarios and electronic devices

[0039] 1. Application scenarios

[0040] The embodiments of the present application can be applied to the following application scenarios, including but not limited to: unit testing in product development process, software development process, and system writing process. The unit testing in the embodiments of the present application is to verify whether the functional module code written by the relevant personnel has realized the functions that should be realized under normal circumstances, and to handle any other possible defects accordingly and correctly. After the unit test is completed, a large number of errors and bugs are usually found, and then the developers deal with them, which can reduce the cost of maintaining the code in the later stage. No specific limitation is made here.

[0041] 2. Electronic equipment

[0042] The electronic device in the embodiment of the present application may be a portable electronic device that also includes other functions such as a personal digital assistant and / or a music player function, such as a mobile phone, a tablet computer, a wearable electronic device with a wireless communication function (such as a smart watch), etc. Exemplary embodiments of portable electronic devices include but are not limited to portable electronic devices equipped with an IOS system, an Android system, a Microsoft system, or other operating systems. The above-mentioned portable electronic device may also be other portable electronic devices, such as a laptop computer (Laptop), etc. It should also be understood that in some other embodiments, the above-mentioned electronic device may not be a portable electronic device, but a desktop computer, a server, etc.

[0043] 3. Example

[0044] See also Figure 1 , Figure 1 This is a system architecture diagram of a data processing method provided in an embodiment of the present application. Figure 1 As shown, the automatic testing system 110 is included. The automatic testing system 110 can construct suitable test cases based on the type of data to be tested, and generate test data. The test data is used to test the data to be tested to obtain test results. Based on the test results, it can be considered whether to adjust the test cases or repair the defects of the data to be tested, or to add new test data to ensure the test coverage of the data to be tested. Since a unique data format is used to construct the test cases, the test cases will not be repeatedly constructed, and the test cases can be associated with the data to be tested. While avoiding missed detection, repeated detection can also be avoided, which greatly improves the efficiency of unit detection.

[0045] It can be seen that by automatically constructing test cases corresponding to the data to be tested and generating test data according to the test cases for data testing, automatic data testing is achieved and data testing efficiency is improved. In addition, the data unit nouns, request parameters, dependent data units, expected return data samples and verification methods included in the test cases are generated at one time, which simplifies the test case generation method and further improves data testing efficiency.

[0046] The automatic testing system 110 may be mounted on the above-mentioned electronic device, which will not be described in detail here.

[0047] 3. A data processing method

[0048] In the unit detection scenario, the existing method generally constructs a corresponding test case for each data to be tested, and when constructing each test case, it constructs different types of request parameters based on the boundary analysis of the request parameters, constructs different types of request parameters and return data for the dependent function methods, calls the function to be verified, and verifies the result after the function method processes it. This involves multiple processes of repeatedly constructing test data, and the constructed test data and the function method itself are put together. The entire test method will be very long and particularly troublesome to maintain later. When checking the test scenario coverage of the method, there will also be repeated additions or lack of test scenario coverage.

[0049] To solve the above problems, the embodiments of the present application provide a data processing method and related devices, which can automatically construct corresponding test cases based on different types of data to be tested, avoid missed detection and repeated detection, and greatly improve the efficiency of unit detection.

[0050] The technical solutions, beneficial effects, concepts, etc. involved in the embodiments of the present application are described in detail below.

[0051] 1. Add new types, change types, and test data

[0052] In order to perform targeted tests on different types of data to be tested, the embodiments of the present application introduce the concepts of new types, changed types, and data to be tested.

[0053] Among them, the data to be tested can correspond to a newly added type or a changed type. The data to be tested of the newly added type can be called the first data to be tested, and the data to be tested of the changed type can be called the second data to be tested. The first data to be tested and the second data to be tested both belong to the first data set, and the first data set can be an application, project code, etc.

[0054] In the embodiment of the present application, the first data to be tested and the second data to be tested may be equivalent to the "unit" in the unit test, and the "unit" may be a function, method, class, functional module or subsystem. For example, in C language, a unit refers to a function, in Java, a unit refers to a class, and in graphical software, it may refer to a window or a menu, etc., and no specific limitation is made here. It can be understood that the data to be tested and the data unit are the same concept.

[0055] Specifically, if the first data set is regarded as the latest version, then there will be an old version of the original data, which is called the second data set. The first data to be tested is any data unit that does not exist in the second data set but is newly added to the first data set. The second data to be tested is any data unit in the first data set corresponding to the data unit in the original data after modification. For example, the second data set is {a, b, c} and the first data set is {a, b1, c, d}. It can be determined that b1 in the first data set is the second data to be tested, and d in the first data set is the first data to be tested. The above example is only for ease of understanding and does not limit the first data to be tested and the second data to be tested.

[0056] (1) How to determine the first test data in the first data set

[0057] Among them, a first data subset and a second data subset in the first data set can be determined, the type corresponding to the first data subset is the newly added type, the type of data included in the first data subset is the newly added type, the type corresponding to the second data subset is the changed type, and the types of data included in the second data subset include the newly added type and the changed type; then, a third data subset in the second data set is determined, the first data set is the data set after the data of the second data set is changed, and the second data subset is the data subset after the data of the third data subset is changed; then, based on the third data subset, determine the data in the second data subset whose data type is the newly added type, specifically, the first identifier of each data in the second data subset can be determined; determine the second identifier of each data in the third data subset; determine the data corresponding to the first identifier different from the second identifier as the data of the newly added type in the second data subset; finally, based on the data in the first data subset and the data in the second data subset whose data type is the newly added type, determine the data to be tested.

[0058] The first data subset may be newly added data, the second data subset may be changed data, the second data set may be original data, and the third data subset may be original data corresponding to the changed data.

[0059] For example, the code of the first data set can be compared with the code of the second data set to find the newly added class data and the changed class data. Taking the first data set as Java data as an example, the difference diff function of JGit can be used to find the lines in the code of the first data set that are different from the code of the second data set. However, at this time, only the changed class and the new class can be found. The data units in the new class data all belong to the new type, that is, the newly added type, but the data units in the changed class data can belong to the new type or the changed type, which needs to be further determined.

[0060] Among them, the first identifier of the data unit in the changed data can be determined; the second identifier of the data unit in the original data can be determined; the data unit corresponding to the first identifier different from the second identifier is screened out and determined as the newly added type of data unit in the changed data.

[0061] Specifically, all data units in the changed class data can be stored in the data structure Map, and all data units of the original class data corresponding to the changed class data can be stored in the data structure Map. Map is an associative container, which is a collection of key-value pairs, that is, it stores a pair of keys and values. Map can also be generally understood as an associative array, that is, each value has a one-to-one correspondence between a key and a value. Therefore, Map does not allow duplicate elements to appear. Taking the data unit as a function method as an example, the function name, request parameters, and return value of each function method can be used as the key, and the content of each function method can be used as the value. When comparing, you only need to compare the key of each data unit in the changed class data with the key of each data unit in the original class data. That is, the key of each data unit in the changed class data can be regarded as the first identifier, and the key of each data unit in the original class data can be regarded as the second identifier. The keys that exist in the changed class data but do not exist in the original class data can be found. For example, the key of the data unit included in the changed class data is {x, y}, and the key of the data unit included in the original class data is {x1}, then it can be determined that the data unit corresponding to the key y is a data unit of the newly added type.

[0062] In this way, the first data to be tested in the first data set can be found. The first data to be tested can be any data unit in the newly added data or any data unit in the changed data, which is not specifically limited here. By finding the first data to be tested, a data reference can be provided for constructing a corresponding first test case for the first data to be tested that belongs to the newly added type.

[0063] (2) How to determine the second test data in the first data set

[0064] Among them, a second data subset in the first data set can be determined, the type corresponding to the second data subset is the change type, and the types of data included in the second data subset include the new type and the change type; then, a third data subset in the second data set is determined, the first data set is the data set after the data of the second data set is changed, and the second data subset is the data subset after the data of the third data subset is changed; then, based on the third data subset, determine the data in the second data subset whose data type is the change type; finally, based on the data in the second data subset whose data type is the change type, determine the data to be tested.

[0065] Specifically, the first hash value of each data included in the second data subset can be determined; then, the second hash value of each data included in the second data set can be determined; finally, the data corresponding to the first hash value that is different from any second hash value is determined as the data of the changed type in the second data subset.

[0066] Similarly, for example, the code of the first data set can be compared with the code of the second data set to find the changed data. Taking the first data set as Java data as an example, the difference diff function of JGit can be used to find the lines in the code of the first data set that are different from the code of the second data set. However, at this time, only changed classes and newly added classes can be found. However, the data units in the changed data can belong to the newly added type or the changed type, which needs to be further determined.

[0067] In a possible embodiment, if all data units in the change type data belong to the change type, the first hash value of each data unit in the change type data can be determined, the second hash value of each data unit in the original data can be determined, and then the data units corresponding to the first hash values ​​that are different from any second hash values ​​are screened out and determined as the data units of the change type in the change type data. Finally, the second data to be tested is determined, and the second data to be tested is any data unit of the change type in the change type data.

[0068] In a possible embodiment, if not all data units in the change type data belong to the change type, the first identifier of the data unit in the change type data can be determined; the second identifier of the data unit in the original data corresponding to the change type data can be determined; the data unit corresponding to the first identifier different from the second identifier is screened out, and it is determined as the data unit of the newly added type in the change type data, and then the first hash value of each data unit other than the data unit of the newly added type in the change type data is determined, the second hash value of each data unit in the original data is determined, and then the data unit corresponding to the first hash value different from any second hash value is screened out, and it is determined as the data unit of the change type in the change type data, and finally, the second data to be tested is determined, and the second data to be tested is any data unit of the change type in the change type data.

[0069] Specifically, the VoidVisitor class method of JavaParser can be executed on the changed class data to take out each data unit therein, and the VoidVisitor class method of JavaParser can be executed on the original class data to take out each data unit therein. At this time, the data unit is a function method, and then the hash value of the method body of each function method in the changed class data is calculated, and the hash value of the method body of each function method in the original class data is calculated. When each function method in the changed class data corresponds to each function method in the original class data one by one, by comparing whether the hash values ​​are consistent, the function methods in the changed class data with inconsistent hash values ​​can be quickly found. When the function methods of the newly added type are excluding, this part of the function methods are the data units of the changed type.

[0070] In this way, the second data to be tested in the first data set can be found, and the second data to be tested can be a data unit of any change type in the change type data, which is not specifically limited here. By finding the second data to be tested, different test strategies can be executed for different situations of the subsequent second data to be tested belonging to the change type.

[0071] 2. First test case

[0072] For the first data to be tested, since the first data to be tested corresponds to a newly added type, that is, the first data to be tested is a newly added type, there is no old unit test case, so only a first test case corresponding to the first data to be tested needs to be added.

[0073] Among them, the data unit noun part of the first test case can be constructed according to the identifier of the first data to be tested. For example, when the first data to be tested is a function method, the identifier of the first data to be tested can be the function name; then, the request parameter part of the first test case can be constructed according to the first annotation text of the first data to be tested. The first annotation text here can be a pre-written text used to describe the range or specific value of the request parameter, etc.; then, the call graph of the first data set can be determined, and the first dependent data unit of the first data to be tested can be determined according to the call graph. The dependent data unit part of the first test case can be constructed according to the first dependent data unit. The first dependent data unit is the first data to be tested. According to the downstream node of the first data set, the call graph of the entire first data set can be obtained through the SootUp analysis code, and then the dependent data unit of the first data to be tested can be found through the call graph; finally, the expected return data sample part of the first test case and the verification method part of the first test case are constructed according to the second annotation text of the first data to be tested. The second annotation text can be a pre-written correct return value description and a description of the verification method as positive verification, or it can be a pre-written incorrect return value description and a description of the verification method as negative verification. The so-called correct return value description refers to a description of a return value that meets the range of request parameters, and the so-called negative return value description refers to a description of a return value that does not meet the range of request parameters.

[0074] For example, for the test data belonging to the same class, you can construct a JSON file. Each class corresponds to a JSON file. Each JSON file contains test cases corresponding to all the test data of this class. Each test case consists of five parts, namely the function noun part, the request parameter part, the dependent function part, the expected return value sample part and the verification method part. The test case can be in JSON schema format.

[0075] For ease of understanding, the format of the test case is explained below in conjunction with the code. The specific format is as follows:

[0076]

[0077] Among them, refer to the following table to determine the content of each part:

[0078]

[0079] It can be seen that by structuring the test case into several parts such as function noun, request parameters, dependent functions, expected return value samples, verification methods, etc., it is only necessary to construct the test scenario and the corresponding structured data for the data unit; for the case where the dependent function needs to simulate test data, it is only necessary to fill in the test case of this function. When adding the dependency once, there is no need to construct the simulated data again, which reduces the workload of unit testing.

[0080] 3. Processing strategy for the second test data

[0081] Since the second data to be tested is of the modified type, it is necessary to first determine whether there is an original test case corresponding to the second data to be tested. If there is an original test case, it is also necessary to determine whether the original test case is valid. The valid here means that the original test case can also test the second data to be tested and the test results meet the requirements.

[0082] Among them, the test case file corresponding to the class name of the changed class data can be determined; then, the original test case corresponding to the identifier of the second data to be tested in the test case file is determined, and the second data to be tested is tested by the original test data corresponding to the original test case. If the second data to be tested passes the test, the original test case is valid, and if the second data to be tested fails the test, the original test case is invalid. For example, the corresponding file can be found according to the changed class name, and then the corresponding original test case can be found using JsonPath through the function name and parameters, and the original test case can be checked through the compilation tool to see if it can run normally. Here, checking whether the original test case can run is equivalent to using the original test case to perform subsequent unit tests on the second data to be tested.

[0083] (1) The original test case is valid

[0084] At this point, it can be determined that the original test case of the second to-be-tested data is the final test case, and the test has been completed and the second test result has been obtained, which can improve the test efficiency.

[0085] (2) The original unit test case does not exist or the original test case is invalid

[0086] In a possible embodiment, when the original unit test case does not exist, a second test case corresponding to the second data to be tested can be constructed, and the data unit name part of the second test case can be constructed according to the identifier of the second data to be tested; the request parameter part of the second test case can be constructed according to the first annotation text of the second data to be tested; the call graph of the first data set is determined, and the second dependent data unit of the second data to be tested is determined according to the call graph, and the dependent data unit part of the second test case is constructed according to the second dependent data unit; the expected return data sample part of the second test case and the verification method part of the second test case are constructed according to the second annotation text of the second data to be tested. The structural composition of the second test case is the same as that of the first test case in 2 above, and the construction logic is also the same, so no examples are given here.

[0087] 4. Processing strategy for the caller data unit of the second test data

[0088] In order to reduce the problem of insufficient testing and reduce errors of other related callers caused by bugs that occur due to modifications, the embodiment of the present application introduces the concept of a caller data unit.

[0089] After determining the second data to be tested in the first data set, the call graph of the first data set can be determined, and the caller data unit of the second data to be tested can be determined according to the call graph. The caller data unit belongs to the upstream node of the second data to be tested. The caller test case corresponding to the caller data unit can be determined, and it can be detected whether the caller test case is valid. Specifically, the corresponding caller test case can be found using JsonPath through the function name and parameters of the caller data unit, and the caller test case can be checked through the compilation tool to see whether it can run normally. Checking whether the caller test case can run here is equivalent to using the caller test case to perform subsequent unit tests on the caller data unit; if the caller test case is invalid, a prompt message is generated, and the prompt message is used to prompt that there is an exception in the second data to be tested, so that the developer can adjust the code of the second data to be tested.

[0090] In a possible embodiment, if the caller test case is valid, it can be determined that the caller test case of the caller data unit is the final test case and the test has been completed. This can improve the test adequacy and reduce other related caller errors caused by the bugs that appear due to the modification.

[0091] 5. Unit test execution process

[0092] The unit testing process for the first data to be tested, the second data to be tested, and the caller data unit is the same, except that the data involved are different.

[0093] (1) Generation of request data

[0094] Since the request parameters are defined by JOSN schema, but are not the data for executing unit tests, the data defined by JSON schema needs to be converted into real data. A variable pool is defined here, including the data of 8 basic types of Java. The 8 basic types include: integer (byte, short, int, long), floating point (float, double), character (char) and Boolean (boolean). The role of the variable pool is to generate corresponding values ​​according to the definition of JSON schema. For example, if the request parameter defines an integer range of [1,8], the variable pool will randomly generate an integer between 1 and 8. If a string of length 20 is defined, a string of 20 characters is randomly generated. I will not go into details here.

[0095] In a possible embodiment, for the first data to be tested, when generating the first test data according to the first test case, the first request data corresponding to the request parameter part of the first test case can be determined from the variable pool.

[0096] In a possible embodiment, for the second data to be tested, when generating the second test data according to the second test case, the second request data corresponding to the request parameter part of the second test case can be determined from the variable pool.

[0097] In a possible embodiment, for the caller data unit, when generating caller test data according to the caller test case, the caller request data corresponding to the request parameter part of the caller test case can be determined from the variable pool.

[0098] (2) Generation and execution of test data

[0099] A test class file can be generated for each class. The header and footer in the test class file are generated as fixed text, and the test class name is generated in a fixed format, such as the class to be tested + the character "Test" at the end; each data unit is also generated in a fixed format, such as the name of the function to be tested plus the letter "Test" at the end.

[0100] Among them, the test data consists of three parts of code and name. The first part of the code is the request result body converted from the request data. The second part of the code can be Mock code, which can be virtually implemented by relying on the function part. You can refer to the existing Mock processing method, which will not be repeated here; the third part of the code can be generated according to the expected return data sample part and the verification method part. Finally, use the compilation tool to execute the generated code to get the test results. According to the test results, you can choose whether to repair the code, modify the test case or add a test case. No specific limitation is made here.

[0101] In a possible embodiment, for the first data to be tested, a first test name of the first test data can be generated according to the data unit name part of the first test case; a first part of code of the first test data can be generated according to the first request data; virtual implementation processing is performed on the dependent data unit part of the first test case to generate a second part of code of the first test data; and a third part of code of the first test data can be generated according to the expected return data sample part of the first test case and the verification method part of the first test case.

[0102] In a possible embodiment, for the second data to be tested, a second test name of the second test data can be generated according to the data unit name part of the second test case; a first part of code of the second test data can be generated according to the second request data; virtual implementation processing is performed on the dependent data unit part of the second test case to generate the second part of code of the second test data; and a third part of code of the second test data can be generated according to the expected return data sample part of the second test case and the verification method part of the second test case.

[0103] In a possible embodiment, for the caller data unit, the caller test name of the caller test data can be generated according to the data unit name part of the caller test case; the first part of the code of the caller test data can be generated according to the caller request data; virtual implementation processing is performed on the dependent data unit part of the caller test case to generate the second part of the code of the caller test data; and the third part of the code of the caller test data can be generated according to the expected return data sample part of the caller test case and the verification method part of the caller test case.

[0104] In a possible embodiment, newly added data units and their corresponding test cases, modified data units and their corresponding test cases, directly affected caller data units and their corresponding test cases can be listed. This allows developers to understand the test coverage of each data unit, and if it is insufficient, additional test scenarios need to be added, and expired test cases and scenarios can be deleted.

[0105] 6. An exemplary description of a data processing method

[0106] In combination with the above content, an example of a data processing method in an embodiment of the present application is introduced below.

[0107] like Figure 2 FIG. 1 is a flow chart of a data processing method according to an embodiment of the present application, and the execution subject may be the above-mentioned electronic device, which specifically includes the following steps:

[0108] Step 201: determine the data to be tested in the first data set.

[0109] The data to be tested may correspond to a newly added type or a changed type.

[0110] In a possible embodiment, the type of the data to be tested includes a newly added type, and a first data subset and a second data subset in the first data set can be determined, the type corresponding to the first data subset is the newly added type, the type of data included in the first data subset is the newly added type, the type corresponding to the second data subset is a changed type, and the types of data included in the second data subset include the newly added type and the changed type; a third data subset in the second data set is determined, the first data set is the data set after the data of the second data set is changed, and the second data subset is the data subset after the data of the third data subset is changed; based on the third data subset, determine that the data type in the second data subset is the data of the newly added type; based on the data in the first data subset and the data in the second data subset whose data type is the newly added type, determine the data to be tested.

[0111] Step 202: construct a test case corresponding to the data to be tested.

[0112] The test case includes a data unit noun, request parameters, dependent data units, expected return data samples and verification methods.

[0113] In a possible embodiment, the data unit nouns included in the test case can be constructed according to the identification of the data to be tested; the request parameters included in the test case can be constructed according to the first annotation text of the data to be tested; the call graph of the first data set is determined, the dependent data units of the data to be tested are determined according to the call graph, and the dependent data units included in the test case are constructed according to the dependent data units; and the expected return data samples and verification methods included in the test case are constructed according to the second annotation text of the data to be tested.

[0114] It can be seen that by structuring the test cases into several parts such as function name, request parameters, dependent functions, expected return value samples, verification methods, etc., it is only necessary to construct the test scenario and the corresponding structured data for the data unit; for the case where the dependent function needs to simulate test data, it is only necessary to fill in the test case of this function. When adding the dependency once, there is no need to construct the simulated data again, which reduces the workload of unit testing.

[0115] Step 203: Generate test data according to the test case.

[0116] In a possible embodiment, request data corresponding to the request parameters of the test case can be determined from a variable pool; a test name of the test data can be generated according to the data unit noun of the test case; a first part of the code of the test data can be generated according to the request data; virtual implementation processing is performed on the dependent data units of the test case to generate a second part of the code of the test data; and a third part of the code of the test data can be generated according to the expected return data sample of the test case and the verification method of the test case.

[0117] In this way, the complexity of the unit test method can be reduced and the unit test code can be kept neat by separating the test data and associating it with the test scenario of the corresponding data to be tested.

[0118] Step 204: Test the data to be tested according to the test data to obtain a test result.

[0119] It can be seen that through the above data processing method, the test cases corresponding to the data to be tested can be automatically constructed, and the test data can be generated according to the test cases for data testing, so as to realize automatic testing of the data and improve the efficiency of data testing. In addition, the data unit nouns, request parameters, dependent data units, expected return data samples and verification methods included in the test cases are generated at one time, which simplifies the generation method of test cases and further improves the efficiency of data testing. Different test strategies are adopted for the newly added types of data to be tested and the changed types of data to be tested, which greatly improves the flexibility.

[0120] For the parts not described in detail above, please refer to the description of 1-5 and will not be repeated here.

[0121] 7. Another exemplary method of data processing

[0122] In combination with the above content, another data processing method of an embodiment of the present application is introduced as an example below.

[0123] like Figure 3 FIG. 1 is a flow chart of another data processing method according to an embodiment of the present application, and the execution subject may be the above-mentioned electronic device, which specifically includes the following steps:

[0124] Step 301, determining a call graph of a first data set, and determining a caller data unit of the data to be tested according to the call graph.

[0125] The data to be tested at this time needs to be of a change type.

[0126] Step 302: determine the caller test case corresponding to the caller data unit, and detect whether the caller test case is valid.

[0127] Step 303: If the caller test case is invalid, a prompt message is generated, and the prompt message is used to prompt that the data to be tested has an abnormality, so that the developer can adjust the code of the data to be tested.

[0128] In a possible embodiment, if the caller test case is valid, it can be determined that the caller test case of the caller data unit is the final test case and the test has been completed. This can improve the test adequacy and reduce other related caller errors caused by the bugs that appear due to the modification.

[0129] For the parts not described in detail above, please refer to the description of 1-6 and will not be repeated here.

[0130] IV. Exemplary description of an electronic device

[0131] Combine the following Figure 4 An electronic device in an embodiment of the present application is described. Figure 4 4 is a schematic diagram of the structure of an electronic device according to an embodiment of the present application. The electronic device 400 includes a processor 401 , a memory 402 , and a communication bus 403 for connecting the processor 401 and the memory 402 .

[0132] In some possible implementations, the memory 402 includes but is not limited to random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM) or portable read-only memory (CD-ROM), and the memory 402 is used to store the program code executed by the electronic device 400 and the transmitted data.

[0133] In some possible implementations, the electronic device 400 further includes a communication interface for receiving and sending data.

[0134] In some possible implementations, the processor 401 may be one or more central processing units (CPUs). When the processor 401 is a central processing unit (CPU), the central processing unit (CPU) may be a single-core central processing unit (CPU) or a multi-core central processing unit (CPU).

[0135] In some possible implementations, the processor 401 may be a baseband chip, a chip, a central processing unit (CPU), a general-purpose processor, a DSP, an ASIC, an FPGA or other programmable logic device, a transistor logic device, a hardware component or any combination thereof.

[0136] In a specific implementation, the processor 401 in the electronic device 400 is used to execute the program instructions 421 stored in the memory 402 to perform the following operations:

[0137] Determine the data to be tested in the first data set;

[0138] Constructing a test case corresponding to the data to be tested, wherein the test case includes a data unit noun, a request parameter, a dependent data unit, an expected return data sample, and a verification method;

[0139] Generate test data according to the test case;

[0140] The data to be tested is tested according to the test data to obtain a test result.

[0141] It should be noted that the specific implementation of each operation can adopt the corresponding description of the method embodiment shown above, and the electronic device 400 can be used to execute the above method embodiment of the present application, which will not be described in detail.

[0142] 5. Exemplary Description of a Data Processing Device

[0143] The above mainly introduces the scheme of the embodiment of the present application from the perspective of the execution process on the method side. It is understandable that, in order to realize the above functions, the electronic device includes a hardware structure and / or software module corresponding to the execution of each function. It should be easily appreciated by those skilled in the art that, in combination with the units and algorithm steps of each example described in the embodiments provided herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present application.

[0144] The embodiment of the present application can divide the electronic device into functional units according to the above method example. For example, each functional unit can be divided according to each function, or two or more functions can be integrated into one processing unit. The above integrated unit can be implemented in the form of hardware or in the form of software functional units. It should be noted that the division of units in the embodiment of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation.

[0145] In the case of dividing each functional module into corresponding functional modules, Figure 5 This is a block diagram of the functional units of a data processing device provided in an embodiment of the present application. The data processing device 500 includes:

[0146] A determination unit 510, configured to determine the data to be tested in the first data set;

[0147] A construction unit 520 is used to construct a test case corresponding to the data to be tested, wherein the test case includes a data unit noun, a request parameter, a dependent data unit, an expected return data sample, and a verification method;

[0148] A generating unit 530, configured to generate test data according to the test case;

[0149] The testing unit 540 is used to test the data to be tested according to the test data to obtain a test result.

[0150] It can be seen that through the above-mentioned data processing method and related devices, test cases corresponding to the data to be tested can be automatically constructed, and test data can be generated according to the test cases for data testing, thereby realizing automatic testing of data and improving data testing efficiency. In addition, the data unit nouns, request parameters, dependent data units, expected return data samples and verification methods included in the test cases are generated at one time, which simplifies the test case generation method and further improves data testing efficiency.

[0151] It should be noted that the specific implementation of each operation can adopt the corresponding description of the method embodiment shown above, and the data processing device 500 can be used to execute the above method embodiment of the present application, which will not be described in detail.

[0152] 6. Other examples

[0153] An embodiment of the present application also provides a chip, including a processor, a memory, and a computer program or instructions stored in the memory, wherein the processor executes the computer program or instructions to implement the steps described in the above method embodiment.

[0154] An embodiment of the present application also provides a chip module, including a transceiver component and a chip, the chip including a processor, a memory and a computer program or instructions stored in the memory, wherein the processor executes the computer program or instructions to implement the steps described in the above method embodiment.

[0155] An embodiment of the present application also provides a computer storage medium, wherein the computer storage medium stores a computer program for electronic data exchange, wherein the computer program enables a computer to execute part or all of the steps of any method recorded in the above method embodiment, and the above computer includes an electronic device.

[0156] The embodiment of the present application also provides a computer program product, the computer program product includes a non-transitory computer-readable storage medium storing a computer program, the computer program is operable to cause a computer to execute some or all of the steps of any method described in the method embodiment. The computer program product may be a software installation package, and the computer includes an electronic device.

[0157] It should be noted that, for the above-mentioned various embodiments, for the sake of simple description, they are all expressed as a series of action combinations. Those skilled in the art should be aware that the present application is not limited by the described order of actions, because some steps in the embodiments of the present application can be performed in other orders or simultaneously. In addition, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions, steps, modules or units involved are not necessarily required by the embodiments of the present application.

[0158] In the above embodiments, the embodiments of the present application have different focuses on the description of each embodiment. For parts that are not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0159] The steps of the method or algorithm described in the embodiments of the present application can be implemented in hardware or by executing software instructions by a processor. The software instructions can be composed of corresponding software modules, and the software modules can be stored in RAM, flash memory, ROM, EPROM, electrically erasable programmable read-only memory (electrically EPROM, EEPROM), registers, hard disks, mobile hard disks, read-only compact disks (CD-ROMs) or any other form of storage medium known in the art. An exemplary storage medium is coupled to the processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can be located in an ASIC. In addition, the ASIC can be located in a terminal device or a management device. Of course, the processor and the storage medium can also be present in a terminal device or a management device as discrete components.

[0160] Those skilled in the art should be aware that in one or more of the above examples, the functions described in the embodiments of the present application can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiments of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server, or data center to another website site, computer, server, or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (digital subscriber line, DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrations. The available medium may be a magnetic medium (eg, a floppy disk, a hard disk, a magnetic tape), an optical medium (eg, a digital video disc (DVD)), or a semiconductor medium (eg, a solid state disk (SSD)).

[0161] The modules / units included in the devices and products described in the above embodiments may be software modules / units or hardware modules / units, or may be partially software modules / units and partially hardware modules / units. For example, for the devices and products applied to or integrated in the chip, the modules / units included therein may all be implemented in the form of hardware such as circuits, or at least some of the modules / units may be implemented in the form of software programs, which run on the processor integrated inside the chip, and the remaining (if any) modules / units may be implemented in the form of hardware such as circuits; for the devices and products applied to or integrated in the chip module, the modules / units included therein may all be implemented in the form of hardware such as circuits, and different modules / units may be located in the same component (such as a chip, circuit module, etc.) or in different components of the chip module, or at least some of the modules / units may be implemented in the form of software programs. The software programs run on the processor integrated inside the chip, and the remaining (if any) modules / units may be implemented in the form of hardware such as circuits. It is implemented in the form of a software program, which runs on a processor integrated inside the chip module, and the remaining (if any) modules / units can be implemented in hardware such as circuits; for various devices and products applied to or integrated in the terminal equipment, the various modules / units contained therein can be implemented in hardware such as circuits, and different modules / units can be located in the same component (for example, chip, circuit module, etc.) or in different components in the terminal equipment, or, at least some modules / units can be implemented in the form of a software program, which runs on a processor integrated inside the terminal equipment, and the remaining (if any) modules / units can be implemented in hardware such as circuits.

[0162] The specific implementation methods described above further illustrate the purpose, technical solutions and beneficial effects of the embodiments of the present application. It should be understood that the above description is only the specific implementation method of the embodiments of the present application and is not intended to limit the protection scope of the embodiments of the present application. Any modifications, equivalent substitutions, improvements, etc. made on the basis of the technical solutions of the embodiments of the present application should be included in the protection scope of the embodiments of the present application.

Claims

1. A data processing method, It is characterized in that The method comprises: Determine the data to be tested in the first data set; Constructing a test case corresponding to the data to be tested, wherein the test case includes a data unit noun, a request parameter, a dependent data unit, an expected return data sample, and a verification method; Generate test data according to the test case; The data to be tested is tested according to the test data to obtain a test result.

2. The method according to claim 1, It is characterized in that The types of the data to be tested include newly added types; The step of determining the data to be tested in the first data set includes: Determine a first data subset and a second data subset in the first data set, the type corresponding to the first data subset is the newly added type, and the type of data included in the first data subset is the newly added type, the type corresponding to the second data subset is the changed type, and the types of data included in the second data subset include the newly added type and the changed type; Determine a third data subset in the second data set, the first data set is the data set after the data of the second data set is changed, and the second data subset is the data subset after the data of the third data subset is changed; Determine, according to the third data subset, that the data type in the second data subset is the newly added type of data; The data to be tested is determined according to the data in the first data subset and the data of the new type in the second data subset.

3. The method according to claim 2, It is characterized in that The step of determining, according to the third data subset, that the data type in the second data subset is the newly added type of data includes: Determine a first identifier of each data in the second data subset; Determine a second identifier for each data in the third data subset; Data corresponding to a first identifier different from the second identifier is determined as data of the newly added type in the second data subset.

4. The method according to claim 1, It is characterized in that The type of the data to be tested includes a change type; The step of determining the data to be tested in the first data set includes: Determine a second data subset in the first data set, the type corresponding to the second data subset is the change type, and the types of data included in the second data subset include a new type and the change type; Determine a third data subset in the second data set, the first data set is the data set after the data of the second data set is changed, and the second data subset is the data subset after the data of the third data subset is changed; Determine, according to the third data subset, that the data type in the second data subset is data of the changed type; The data to be tested is determined according to the data of the data type of the changed type in the second data subset.

5. The method according to claim 4, It is characterized in that The determining, according to the third data subset, that the data type in the second data subset is data of the changed type includes: Determine a first hash value for each data included in the second data subset; determining a second hash value for each data included in the second data set; Data corresponding to the first hash value that is different from any second hash value is determined as data of the changed type in the second data subset.

6. The method according to claim 4, It is characterized in that After determining the data to be tested in the first data set, the method further includes: Determining a test case file corresponding to the second data set; Determine the original test case corresponding to the data to be tested in the test case file; Testing the data to be tested by using the original test data corresponding to the original test case, and if the data to be tested passes the test, determining that the original test case is valid; if the data to be tested fails the test, determining that the original test case is invalid; If the original test case is invalid, or does not exist, a test case corresponding to the data to be tested is constructed.

7. The method according to claim 4, It is characterized in that After determining the data to be tested in the first data set, the method further includes: Determine a call graph of the first data set, and determine caller data of the data to be tested according to the call graph; Determine a caller test case corresponding to the caller data, and detect whether the caller test case is valid; If the caller test case is invalid, a prompt message is generated, where the prompt message is used to prompt that an abnormality exists in the data to be tested.

8. The method according to claim 1 or 6, It is characterized in that The constructing of a test case corresponding to the data to be tested includes: Constructing the data unit nouns included in the test case according to the identifier of the data to be tested; Constructing the request parameters included in the test case according to the first annotation text of the data to be tested; Determine a call graph of the first data set, determine dependent data units of the data to be tested according to the call graph, and construct dependent data units included in the test case according to the dependent data units; According to the second annotation text of the data to be tested, the test case is constructed to include an expected return data sample and a verification method.

9. The method according to claim 8, It is characterized in that The generating test data according to the test case comprises: Determine request data corresponding to the request parameters of the test case from a variable pool; Generating a test name for the test data according to the data unit noun of the test case; Generate a first part of code for the test data according to the request data; Performing virtual implementation processing on the dependent data unit of the test case to generate a second part of code for the test data; The third part of the code for the test data is generated according to the expected return data sample of the test case and the verification method of the test case.

10. A data processing device, It is characterized in that The device comprises: A determination unit, used to determine the data to be tested in the first data set; A construction unit, used to construct a test case corresponding to the data to be tested, wherein the test case includes a data unit noun, a request parameter, a dependent data unit, an expected return data sample, and a verification method; A generating unit, used for generating test data according to the test case; The testing unit is used to test the data to be tested according to the test data to obtain a test result.

11. An electronic device, It is characterized in that include: A processor, a memory, and one or more programs; the one or more programs are stored in the memory and are configured to be executed by the processor, the programs comprising instructions for executing the steps in the method according to any one of claims 1-9.

12. A computer storage medium, It is characterized in that The computer storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, the processor is caused to perform the method according to any one of claims 1 to 9.

13. A computer program product, It is characterized in that The computer program product comprises a non-transitory computer-readable storage medium storing a computer program, and when the program instructions are executed by a processor, the processor is caused to perform the method according to any one of claims 1 to 9.