Test case generation method and device
By entering business data into various functions of the software project and automatically generating test cases using traffic recording, the problem of unit test case writing is solved, and efficient test case generation and code coverage is achieved.
Patent Information
- Application Number
- CN202110048255.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-01-14
- Publication Date
- 2025-02-18
- Estimated Expiration
- 2041-01-14
AI Technical Summary
The writing of unit test cases in software projects consumes a lot of effort from developers. The existing technology is difficult to ensure the coverage of functional development and test cases within a limited time, and the test data structure is complex and code branches are difficult to cover.
By entering business data into various functions of the software project, and obtaining input and output data using traffic recording, test cases are automatically generated. The method includes storing the input and output data in a database and generating a test case file using a data-driven use case. Optional steps include running the test case file, updating uncovered code information, and adjusting business data to improve code coverage.
It reduces the complexity of test data construction, improves the code coverage and problem detection rate of test cases, improves the efficiency of test case generation, and reduces the workload of developers.
Smart Images

Figure CN112749094B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer software, and in particular to a test case generation method and device. Background Art
[0002] At present, the business demand for software projects is strong, and it is difficult to construct unit test cases. Within a limited time, it is impossible to ensure both functional development and sufficient coverage of unit test cases. Test data is difficult to construct, and it is unknown what kind of input data can be used to reach certain branches in the code. The constructed test data is often only to cover the code branches. If real business data can be used, the probability of test cases detecting problems will be higher.
[0003] Therefore, writing unit test cases in software projects is a very time-consuming task for developers. In many cases, in order to meet the coverage requirements, a bunch of fake test cases with no actual value are written. Therefore, it is urgent to provide a new solution to automatically / semi-automatically generate test cases, while ensuring the quality of test cases, improving the writing speed of test cases, and allowing developers to devote more energy to the development of functional codes. Summary of the invention
[0004] In view of the problems existing in the prior art, the main purpose of the embodiments of the present invention is to provide a test case generation method and device, so as to improve the efficiency of writing test cases, reduce the difficulty of test data construction, and improve the detection rate of test case problems.
[0005] In order to achieve the above object, an embodiment of the present invention provides a test case generation method, the method comprising:
[0006] Input the acquired business data into each function of the software project, and use traffic recording to obtain the input data and output data of each function;
[0007] According to the input data and output data of each function, the test cases corresponding to each function are automatically generated using the data-driven use case method;
[0008] Generate a test case file for the software project based on the test cases corresponding to each function and the preset software project directory structure.
[0009] Optionally, in one embodiment of the present invention, the method further includes: running the test case file to determine the code coverage and uncovered code information of the test case file; and updating the business data input into each function based on the uncovered code information.
[0010] Optionally, in one embodiment of the present invention, updating the business data input into each function according to the uncovered code information includes: obtaining the business data corresponding to the uncovered code information, and using the business data corresponding to the uncovered code information as update data; and using the update data to update the business data input into each function.
[0011] Optionally, in one embodiment of the present invention, the business data is obtained by at least one of three methods: intercepting business data input by a user, generating business data using a preset data generation model, and generating business data using a preset regular expression.
[0012] Optionally, in an embodiment of the present invention, the method further includes: storing each function and its corresponding input data and output data in a database.
[0013] Optionally, in one embodiment of the present invention, the method of automatically generating test cases corresponding to each function based on the input data and output data of each function using a data-driven use case approach includes: obtaining the input data and output data of each function from a database; using the input data and output data of each function as test case input data, and automatically generating test cases corresponding to each function based on the test case input data using a data-driven use case approach.
[0014] An embodiment of the present invention further provides a test case generating device, the device comprising:
[0015] The business data acquisition module is used to input the acquired business data into each function of the software project, and obtain the input data and output data of each function by using the traffic recording method;
[0016] The test case module is used to automatically generate test cases corresponding to each function based on the input data and output data of each function using a data-driven use case approach;
[0017] The file generation module is used to generate a test case file for the software project according to the test cases corresponding to each function and a preset software project directory structure.
[0018] Optionally, in one embodiment of the present invention, the device also includes: a file running module, used to run the test case file to determine the code coverage and uncovered code information of the test case file; a business data updating module, used to update the business data input into each function according to the uncovered code information.
[0019] Optionally, in one embodiment of the present invention, the business data update module also includes: an uncovered code unit, used to obtain business data corresponding to the uncovered code information, and use the business data corresponding to the uncovered code information as update data; and a data update unit, used to use the update data to update the business data input into each function.
[0020] Optionally, in one embodiment of the present invention, the business data is obtained by at least one of three methods: intercepting business data input by a user, generating business data using a preset data generation model, and generating business data using a preset regular expression.
[0021] Optionally, in an embodiment of the present invention, the device further includes: a storage module, used to store each function and its corresponding input data and output data in a database.
[0022] Optionally, in one embodiment of the present invention, the test case module includes: a data acquisition unit, used to obtain the input data and output data of each function from a database; a case generation unit, used to use the input data and output data of each function as test case input data, and use a data-driven use case method to automatically generate test cases corresponding to each function according to the test case input data.
[0023] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above method when executing the program.
[0024] The present invention also provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program for executing the above method.
[0025] The present invention utilizes a traffic recording method and only needs to obtain entry business data, and automatically obtains input data of each internal function through the flow of business data. There is no need to construct corresponding input data for each function, which reduces the complexity of test data construction and improves the code coverage and problem detection rate of test cases. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0027] Figure 1 A flow chart of a test case generation method according to an embodiment of the present invention;
[0028] Figure 2 A flowchart of running a test case in an embodiment of the present invention;
[0029] Figure 3 A flowchart of updating service data in an embodiment of the present invention;
[0030] Figure 4 A flowchart for generating a test case in an embodiment of the present invention;
[0031] Figure 5 A flowchart of generating a test case in a specific embodiment of the present invention;
[0032] Figure 6 A schematic diagram of the structure of a system for applying a test case generation method in an embodiment of the present invention;
[0033] Figure 7 This is a structural diagram of a data preparation module in an embodiment of the present invention;
[0034] Figure 8 This is a schematic diagram of the structure of a traffic recording module in an embodiment of the present invention;
[0035] Fig. 9 A schematic diagram of the structure of a test case generation module in an embodiment of the present invention;
[0036] Fig.10 This is a schematic diagram of the structure of a code verification module in an embodiment of the present invention;
[0037] Fig.11 A schematic diagram of the structure of a test case generating device according to an embodiment of the present invention;
[0038] Fig.12 It is a structural schematic diagram of a test case generating device in a specific embodiment of the present invention;
[0039] Fig.13 This is a schematic diagram of the structure of a service data update module in an embodiment of the present invention;
[0040] Fig.14 A schematic diagram of the structure of a test case module in an embodiment of the present invention;
[0041] Fig.15 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0042] The embodiments of the present invention provide a test case generation method and device, which can be used in the financial field or other fields. It should be noted that the test case generation method and device of the present invention can be used in the financial field, and can also be used in any field other than the financial field. The application field of the test case generation method and device of the present invention is not limited.
[0043] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0044] like Figure 1 The flowchart of a test case generation method according to an embodiment of the present invention is shown. The execution subject of the test case generation method provided by the embodiment of the present invention includes but is not limited to a computer. The method shown in the figure includes:
[0045] Step S1, input the acquired business data into each function of the software project, and use the traffic recording method to obtain the input data and output data of each function.
[0046] Among them, the software project refers to an engineering project of a certain software, and the functions in the software project are functional codes written when developing the software. Business data can be obtained by intercepting business data input by testers or users, or by using the data generation model preset by the tester to automatically generate business data, or by using preset regular expressions to automatically generate business data according to the rules of regular expressions. After obtaining the business data, the business data is replayed into the software project using the playback entry method, so that the business data flows to each function in the software project, that is, the business data is input into the software project, and each function performs the corresponding operation to complete the business data processing. The input data and output data of each function are intercepted and stored through traffic recording. Among them, the input data of the function can be business data or the output data of the previous function.
[0047] Furthermore, the traffic recording method can be implemented by modifying the framework SDK (Software Development Kit) to uniformly intercept all functions passing through the framework. Specifically, for example, a unified interceptor is set in the distributed service to intercept all service requests. In addition, each function and the input and output data of each function obtained by interception are stored through database storage and other methods.
[0048] Step S2, based on the input data and output data of each function, a test case corresponding to each function is automatically generated using a data-driven use case approach.
[0049] Among them, the input data and output data of each function are used as input data for generating test cases, and the data-driven use case method (that is, using the existing method library, such as the DDT tool library) is used to automatically generate test cases corresponding to each function based on the input data and output data.
[0050] Step S3, generating a test case file for the software project according to the test cases corresponding to each function and the preset software project directory structure.
[0051] Among them, the directory structure of the software project represents the hierarchical relationship of each file in the software project. According to the preset directory structure of the software project and the test cases corresponding to each function, the test case files of the software project are generated. Specifically, for example, if functions foo1 and foo2 belong to the Bar.java file in the dir directory, then in the software project, first determine whether there is a dir / BarTest.java file. If not, create a new file, and then insert the test case code of foo1 and foo2 into the corresponding area. If a new function foo3 (also belongs to the Bar.java file) is added, the test case of foo3 can be directly inserted into the corresponding area of the BarTest.java file.
[0052] As an embodiment of the present invention, Figure 2 As shown, the method also includes:
[0053] Step S21, running the test case file to determine the code coverage and uncovered code information of the test case file.
[0054] Among them, the test case file is run to implement the test of the software project and obtain the execution status of the test case. The execution status includes whether each function has passed the test, code coverage, function coverage, and code information not covered by the test case file, that is, uncovered code information. Uncovered code information indicates which codes are not tested by the current test case file. Specifically, the function coverage is determined. For example, there are 100 functions in total, of which 70 functions are tested, and the function coverage is 70%. Specifically, regardless of whether the function is fully tested, the function can be counted as tested if it is called.
[0055] Step S22: updating the business data input into each function according to the uncovered code information.
[0056] After the uncovered code information is obtained, the business data input to each function is determined to be adjusted according to the branch logic (such as if statement) of the uncovered code, so as to update the business data.
[0057] In this embodiment, if Figure 3 As shown, updating the business data input into each function according to the uncovered code information includes:
[0058] Step S31, acquiring the service data corresponding to the uncovered code information, and using the service data corresponding to the uncovered code information as update data.
[0059] Among them, according to the business data corresponding to the code information not covered by the test case, specifically, for example, a branch code in an if statement is not tested, the business data that meets the branch logic is the business data corresponding to the code, that is, the update data.
[0060] Step S32: using the update data to update the business data input into each function.
[0061] The updated data is added to the original business data, thereby forming the updated business data. By inputting the updated business data into each function of the software project again and using the traffic recording method and other processes again, an updated test case file can be generated. The updated test case file will have a higher code coverage and better test effect.
[0062] As an embodiment of the present invention, the business data is obtained by at least one of intercepting business data input by a user, generating business data by using a preset data generation model, and generating business data by using a preset regular expression.
[0063] Among them, the business data can be obtained by intercepting the business data input by the tester or the user, or by using the data generation model preset by the tester to automatically generate the business data, or by using the preset regular expression to automatically generate the business data according to the rules of the regular expression. Specifically, the process of generating business data using the data generation model preset by the tester is: through the business data generation platform, write a simulated business operation process, for example, in the "simulated example of logging into the mailbox, writing a letter, and then launching the mailbox", first call the browser driver instance, then implicitly wait for 5 seconds, open the mailbox website, call the login interface to log in, and then call the letter writing function to send an email, log in after completion, and after writing the simulation process, initiate the business process by running the model to obtain business data. The process of generating business data using the preset regular expression is: through the business data generation platform, write a regular expression, for example, to test the file upload function, write a regular expression for the rename function, and when calling the file upload interface, the incoming parameters are converted according to the regular expression for renaming, and the parameters of different file names are obtained.
[0064] As an embodiment of the present invention, the method further includes: storing each function and its corresponding input data and output data in a database.
[0065] Among them, each function, as well as the input data and output data of each function obtained by interception are stored by means of database storage, etc. In addition, each function and its input data and output data can be stored in the corresponding position of the software project.
[0066] In this embodiment, if Figure 4 As shown, according to the input data and output data of each function, the test cases corresponding to each function are automatically generated using the data-driven use case method, including:
[0067] Step S41, obtaining input data and output data of each function from a database.
[0068] The input data and output data of each function stored in the database are retrieved as input data for generating test cases.
[0069] Step S42, using the input data and output data of each function as test case input data, and using a data-driven use case approach to automatically generate a test case corresponding to each function according to the test case input data.
[0070] Among them, using the data-driven use case method, such as the DDT tool library, the test case input data is input into the DDT tool library, and the DDT tool library automatically generates test cases corresponding to each function. Among them, the test case input data includes the file path, file name, function name, parameter object type, version information, etc. of the corresponding function.
[0071] In a specific embodiment of the present invention, Figure 5 The flowchart for generating test cases is shown, which includes:
[0072] Step S101: intercepting the tester / user input information and obtaining business data;
[0073] Step S102: Obtaining business data according to the model constructed by the automated tester;
[0074] Step S103: business data may also be obtained by configuring a regular expression according to the rules of the regular expression;
[0075] Step S104: Based on the business data obtained through the above three ways, the business data is made to flow through various functions within the software project through the playback entry method, and the input and output data of each function are intercepted through the flow recording method;
[0076] Step S105: store functions, parameter object types, input and output data and other information into a database; taking Java development language as an example: the parameter object class can be a built-in object type, such as string, integer, array, list, enumeration value, etc.; it can also be a custom object type, which is any combination of built-in object types.
[0077] Step S106: by means of data-driven use cases (using the existing method library in the industry, such as the DDT tool library), the stored data is used as the test case input data of the function to automatically generate the required test cases;
[0078] Step S107: Generate the required test case files in combination with the software project directory structure, and place them in the location corresponding to the software project test case;
[0079] Step S108: Run the generated test case file to check the execution status of the test case file; the execution status includes code coverage, and coverage statistics of the function code in the software project can be obtained according to the coverage statistics tool;
[0080] Step S109: Obtain uncovered code information, and determine the adjustments that need to be made to the business data based on the code branch logic;
[0081] Step S110: Adjust one of step S101, step S102, and step S103 to obtain new business data and quickly generate a new test case file so that the uncovered code is protected by the test case file.
[0082] In a specific embodiment of the present invention, Figure 6 The figure shows a schematic diagram of the structure of a system for applying a test case generation method in an embodiment of the present invention, wherein the system shown in the figure includes: a data preparation module 1, a traffic recording module 2, a test case generation module 3, and a code verification module 4. The data preparation module 1 is connected to the traffic recording module 2; the traffic recording module 2 is connected to the test case generation module 3; and the test case generation module 3 is connected to the code verification module 4.
[0083] In this embodiment, if Figure 7 As shown, the data preparation module 1 includes a business input submodule 11, an automated testing submodule 12 and a regular generation submodule 13, wherein:
[0084] The business input submodule 11 is used to intercept the input information of the tester / user based on the developed functions after deployment in the test environment / production environment, and use it as business data after data desensitization;
[0085] The automated testing submodule 12 is used to obtain business data according to the model constructed by the automated testing personnel;
[0086] The regular expression generation module 13 is used to support the configuration of regular expressions and automatically generate business data according to the rules of regular expressions.
[0087] In this embodiment, if Figure 8 As shown, the traffic recording module 2 includes a traffic recording submodule 21 and a data storage submodule 22, wherein:
[0088] The traffic recording submodule 21 is used to use the traffic recording method to record the input data and output data received by each internal function. Among them, the traffic recording can be modified based on the framework SDK to uniformly intercept all functions passing through the framework. For example, a unified interceptor is set in the distributed service framework to intercept all service requests; TCP messages can also be intercepted at the network card layer, and the requested information can be "translated" from the binary stream by message reassembly and deserialization;
[0089] The data storage submodule 22 is used to store the input and output data of each function obtained in the traffic recording submodule 21 through a database or other means for use in subsequent processes.
[0090] In this embodiment, if Fig. 9 As shown, the test case generation module 3 includes a data-driven use case submodule 31 and a code generation submodule 32, wherein:
[0091] The data-driven use case storage module 31 is used to automatically generate the required test cases based on the data (mainly function names, input and output data) stored in the data storage submodule 22, by means of data-driven use cases (using the existing method library in the industry, such as the DDT tool library), using the stored data as the test case input data of the function;
[0092] The code generation submodule 32 is used to generate the required test case files based on the code generated by the data-driven use case submodule 31 in combination with the software project directory structure, and store them in the location corresponding to the software project test case.
[0093] In this embodiment, if Fig.10 As shown, the code verification module 4 includes a test case running submodule 41 and a coverage statistics submodule 42, wherein:
[0094] The test case running submodule 41 is used to run the generated test case based on the test case file generated by the code generation submodule 32 and check the execution status of the test case;
[0095] The coverage statistics submodule 42 is used to obtain the coverage statistics of the function codes in the software project according to the coverage statistics tool, and in combination with the generated test case code, it can adjust the data input of the data preparation module 1 in turn, and finally make the coverage meet the requirements of the software project. Specifically, for example, for a payment function, the coverage statistics show that the water and electricity related codes have been covered (that is, the generated test case code), but the natural gas related branches have not, so a natural gas payment service can be initiated from the service entrance.
[0096] Through the test case generation method of the present invention, developers can focus on the development of functional codes and generate test cases by running existing codes; they only need to pay attention to business data and automatically obtain the input of each internal function through the flow of business data, without having to construct corresponding data input for each internal function, thereby reducing the complexity of test data construction; for functions that have been launched, the user's real business data can be used as business data to improve the code coverage and problem detection rate of the test cases.
[0097] like Fig.11 FIG. 1 is a schematic diagram of a structure of a test case generating device according to an embodiment of the present invention. The device shown in the figure includes:
[0098] The business data acquisition module 10 is used to input the acquired business data into each function of the software project, and obtain the input data and output data of each function by using the traffic recording method;
[0099] The test case module 20 is used to automatically generate test cases corresponding to each function by using a data-driven use case method according to the input data and output data of each function;
[0100] The file generation module 30 is used to generate a test case file for the software project according to the test cases corresponding to each function and a preset directory structure of the software project.
[0101] As an embodiment of the present invention, Fig.12 As shown, the device also includes:
[0102] A file running module 40 is used to run the test case file and determine the code coverage and uncovered code information of the test case file;
[0103] The business data updating module 50 is used to update the business data input into each function according to the uncovered code information.
[0104] In this embodiment, if Fig.13 As shown, the business data updating module 50 also includes:
[0105] The uncovered code unit 501 is used to obtain the service data corresponding to the uncovered code information, and use the service data corresponding to the uncovered code information as update data;
[0106] The data updating unit 502 is used to update the business data input into each function using the update data.
[0107] As an embodiment of the present invention, the business data is obtained by at least one of intercepting business data input by a user, generating business data by using a preset data generation model, and generating business data by using a preset regular expression.
[0108] As an embodiment of the present invention, the device further includes: a storage module, which is used to store each function and its corresponding input data and output data in a database.
[0109] In this embodiment, if Fig.14 As shown, the test case module 20 includes:
[0110] A data acquisition unit 201 is used to acquire input data and output data of each function from a database;
[0111] The case generation unit 202 is used to use the input data and output data of each function as test case input data, and automatically generate test cases corresponding to each function according to the test case input data by using a data-driven use case approach.
[0112] Based on the same application concept as the above-mentioned test case generation method, the present invention also provides the above-mentioned test case generation device. Since the principle of solving the problem by the test case generation device is similar to that of the test case generation method, the implementation of the test case generation device can refer to the implementation of the test case generation method, and the repeated parts will not be repeated.
[0113] The present invention utilizes a traffic recording method and only needs to obtain entry business data, and automatically obtains input data of each internal function through the flow of business data. There is no need to construct corresponding input data for each function, which reduces the complexity of test data construction and improves the code coverage and problem detection rate of test cases.
[0114] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above method when executing the program.
[0115] The present invention also provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program for executing the above method.
[0116] like Fig.15 As shown, the electronic device 600 may further include: a communication module 110, an input unit 120, an audio processor 130, a display 160, and a power supply 170. It is worth noting that the electronic device 600 does not necessarily have to include Fig.15 In addition, the electronic device 600 may also include Fig.15 For components not shown, reference may be made to the prior art.
[0117] like Fig.15As shown, the central processor 100 is sometimes also referred to as a controller or an operation control, and may include a microprocessor or other processor devices and / or logic devices. The central processor 100 receives inputs and controls the operations of various components of the electronic device 600.
[0118] The memory 140 may be, for example, one or more of a cache, a flash memory, a hard drive, a removable medium, a volatile memory, a non-volatile memory or other suitable devices. The above-mentioned information related to the failure may be stored, and a program for executing the relevant information may also be stored. The CPU 100 may execute the program stored in the memory 140 to implement information storage or processing.
[0119] The input unit 120 provides input to the CPU 100. The input unit 120 is, for example, a key or a touch input device. The power supply 170 is used to provide power to the electronic device 600. The display 160 is used to display display objects such as images and text. The display may be, for example, an LCD display, but is not limited thereto.
[0120] The memory 140 may be a solid-state memory, such as a read-only memory (ROM), a random access memory (RAM), a SIM card, etc. It may also be a memory that saves information even when the power is off, can be selectively erased, and is provided with more data, examples of which are sometimes referred to as EPROMs, etc. The memory 140 may also be some other type of device. The memory 140 includes a buffer memory 141 (sometimes referred to as a buffer). The memory 140 may include an application / function storage unit 142, which is used to store application programs and function programs or processes for executing the operation of the electronic device 600 through the central processor 100.
[0121] The memory 140 may also include a data storage unit 143 for storing data, such as contacts, digital data, pictures, sounds, and / or any other data used by the electronic device. The driver storage unit 144 of the memory 140 may include various drivers for communication functions of the electronic device and / or for executing other functions of the electronic device (such as messaging applications, address book applications, etc.).
[0122] The communication module 110 is a transmitter / receiver that transmits and receives signals via the antenna 111. The communication module (transmitter / receiver) 110 is coupled to the central processor 100 to provide input signals and receive output signals, which may be the same as the case of a conventional mobile communication terminal.
[0123] Based on different communication technologies, multiple communication modules 110 may be provided in the same electronic device, such as a cellular network module, a Bluetooth module and / or a wireless LAN module. The communication module (transmitter / receiver) 110 is also coupled to a speaker 131 and a microphone 132 via an audio processor 130 to provide an audio output via the speaker 131 and receive an audio input from the microphone 132, thereby realizing a common telecommunication function. The audio processor 130 may include any suitable buffer, decoder, amplifier, etc. In addition, the audio processor 130 is also coupled to the central processor 100, so that the sound can be recorded on the local machine through the microphone 132, and the sound stored on the local machine can be played through the speaker 131.
[0124] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0125] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. 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 produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes 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.
[0126] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0127] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0128] The present invention uses specific embodiments to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A test case generation method, characterized in that: The method comprises: The acquired business data is input into each function of the software project by using the playback entry method, and the input data and output data of each function are obtained by using the traffic recording method; wherein the business data is obtained by at least one of the three methods of intercepting the business data input by the user, generating the business data by using a preset data generation model, and generating the business data by using a preset regular expression; wherein the input data of the function includes the business data and the output data of the upper-level function; According to the input data and output data of each function, the test cases corresponding to each function are automatically generated using the data-driven use case method; Generate a test case file for the software project according to the test cases corresponding to each function and the preset software project directory structure; Wherein, the method further comprises: Run the test case file, and determine the code coverage and uncovered code information of the test case file according to the obtained test case execution status; According to the uncovered code information, the business data input into each function is updated; Wherein, updating the business data input into each function according to the uncovered code information includes: Acquire the service data corresponding to the uncovered code information, and use the service data corresponding to the uncovered code information as update data; The business data input into each function is updated using the update data.
2. The method according to claim 1, characterized in that The method further includes: storing each function and its corresponding input data and output data in a database.
3. The method according to claim 2, characterized in that The method of automatically generating test cases corresponding to each function by using a data-driven use case method according to the input data and output data of each function includes: Get the input data and output data of each function from the database; The input data and output data of each function are used as test case input data, and a data-driven use case approach is used to automatically generate test cases corresponding to each function according to the test case input data.
4. A test case generating device, characterized in that: The device comprises: A business data acquisition module is used to input the acquired business data into each function of the software project by means of playback entry, and obtain the input data and output data of each function by means of traffic recording; wherein the business data is obtained by at least one of the following three methods: intercepting business data input by a user, generating business data by means of a preset data generation model, and generating business data by means of a preset regular expression; wherein the input data of a function includes business data and output data of a previous function; The test case module is used to automatically generate test cases corresponding to each function based on the input data and output data of each function using a data-driven use case approach; A file generation module, used to generate a test case file for the software project according to the test cases corresponding to each function and a preset software project directory structure; Wherein, the device further comprises: A file running module, used to run the test case file, and determine the code coverage and uncovered code information of the test case file according to the obtained test case execution status; A business data updating module, used for updating the business data input into each function according to the uncovered code information; Among them, the business data update module also includes: an uncovered code unit, used to obtain business data corresponding to the uncovered code information, and use the business data corresponding to the uncovered code information as update data; a data update unit, used to use the update data to update the business data input into each function.
5. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the method according to any one of claims 1 to 3 is implemented.
6. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program for executing the method according to any one of claims 1 to 3.
Citation Information
Patent Citations
Unit test case automatic recording and executing method and device
CN111221721A