A method and apparatus for generating test cases

By obtaining component storage path information and execution information of click operation, test cases are dynamically generated, which solves the problem that unit test cases cannot obtain method running time and context information in the prior art, and achieves high-quality unit test data acquisition and code quality improvement.

CN113254340BActive Publication Date: 2025-06-20BEIJING WODONG TIANJUN INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110583758.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-05-27
Publication Date
2025-06-20
Estimated Expiration
2041-05-27

AI Technical Summary

Technical Problem

Existing unit test cases cannot dynamically obtain the running time and context information of the method, making it difficult to construct complete simulation data, the process is complex and unintuitive, affecting development efficiency and code quality.

Method used

By obtaining the component storage path information and execution information corresponding to the click operation, including entry parameters, return values, and context information before and after execution, test cases are generated dynamically.

Benefits of technology

It achieves the real and reliable unit test data, and the generated test cases can be run directly and passed tests, improving development efficiency and code quality, and simplifying the simulation data construction process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113254340B_ABST
    Figure CN113254340B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and device for generating test cases, relating to the field of computer technology. A specific embodiment of the method includes: obtaining the storage path information and execution information of each component corresponding to the click operation, where the execution information includes the input parameters, return values, pre-execution context information, and post-execution context information of the execution method within the component; generating a test case corresponding to the click operation according to the storage path information and the execution information. This embodiment can directly use real data online, eliminating the cumbersome process of constructing simulated data, improving the quality of project code, enhancing development efficiency, and reducing development costs.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular, to a method and device for generating test cases. Background Art

[0002] In application development, unit test cases are required to perform unit tests on each module in the application to verify the code logic.

[0003] Existing unit test cases perform static code text analysis on the methods defined in the components, and cannot obtain the running time and context information of each method. Moreover, unit tests require complete test cases and complete simulated data to support tests in different scenarios. The process is complex and not intuitive, resulting in difficulty in constructing complete simulated data. Summary of the Invention

[0004] In view of this, embodiments of the present invention provide a method and device for generating test cases, which can obtain relatively complete real data, improve development efficiency and code quality, and thereby enhance the user experience.

[0005] To achieve the above object, according to one aspect of the embodiments of the present invention, a method for generating test cases includes:

[0006] Obtaining the storage path information and execution information of each component corresponding to a click operation, where the execution information includes the input parameters, return value, pre-execution context information, and post-execution context information of the method executed within the component;

[0007] Generating a test case corresponding to the click operation according to the storage path information and the execution information.

[0008] Optionally, the storage path information and the execution information of each component corresponding to the click operation are obtained in a real-time or timed manner.

[0009] Optionally, obtaining the execution information of each component corresponding to a click operation includes:

[0010] For any execution method of any component, obtaining the pre-execution context information and input parameters of the any execution method;

[0011] Calling the execution method according to the pre-execution context information and the input parameters, and obtaining the return value;

[0012] Obtaining the post-execution context information of the execution method according to the return value.

[0013] Optionally, before obtaining the pre-execution context information and input parameters of any execution method, it is determined that the number of the execution methods being executed is not greater than a preset threshold.

[0014] Optionally, it further includes:

[0015] Obtain the click position information corresponding to the click operation, and store the click position information, the storage path information, and the execution information correspondingly according to the identifier of the click operation.

[0016] Optionally, before generating the test case corresponding to the click operation according to the storage path information and the execution information, it further includes:

[0017] Deduplicate the execution information according to the method name of the execution method.

[0018] Optionally, generating the test case corresponding to the click operation according to the storage path information and the execution information includes:

[0019] Generate environment code according to the storage path information, generate test code according to the execution information, and assemble the environment code and the test code to generate the test case.

[0020] According to another aspect of the embodiments of the present invention, there is provided a test case generation device, including:

[0021] A data collection module that obtains the storage path information and execution information of each component corresponding to the click operation, where the execution information includes the input parameters, return values, pre-execution context information, and post-execution context information of the execution method within the component;

[0022] A use case generation module that generates a test case corresponding to the click operation according to the storage path information and the execution information.

[0023] According to yet another aspect of the embodiments of the present invention, there is provided an electronic device, including:

[0024] One or more processors;

[0025] A storage device for storing one or more programs,

[0026] When the one or more programs are executed by the one or more processors, the one or more processors implement the test case generation method of the embodiments of the present invention.

[0027] According to yet another aspect of the embodiments of the present invention, there is provided a computer-readable medium, on which a computer program is stored, and when the program is executed by a processor, the test case generation method of the embodiments of the present invention is implemented.

[0028] One embodiment of the above invention has the following advantages or beneficial effects: The test case generation method provided by the embodiment of the present invention can visually and automatically generate relatively complete and high-quality test case codes for developers. By clicking operations, the click position information corresponding to the click operations, the storage paths of each component, and the execution information can be obtained, that is, the timing and context information of the execution method running are dynamically obtained, and a test case can be obtained for each click operation. This method can obtain real and reliable unit test data, and the generated unit test cases can be directly run and pass the test. This method can directly use the real data online, saving the cumbersome process of constructing simulated data; moreover, by combining static code analysis to automatically introduce environment codes, it can more efficiently ensure the quality of project codes, thereby improving the user experience. At the same time, this method can also help developers quickly locate problems from the obtained context information to troubleshoot and solve problems when encountering development vulnerabilities, improving the application development efficiency.

[0029] The further effects of the above non-conventional optional methods will be described below in conjunction with specific embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] The drawings are used to better understand the present invention and do not constitute an improper limitation to the present invention. Among them:

[0031] Figure 1 is a schematic diagram of the main process of a test case generation method according to an embodiment of the present invention;

[0032] Figure 2 is a schematic diagram of the main process of another test case generation method according to an embodiment of the present invention;

[0033] Figure 3 is a schematic diagram of the main process of yet another test case generation method according to an embodiment of the present invention;

[0034] Figure 4 is a schematic flowchart of a method for obtaining execution information according to an embodiment of the present invention;

[0035] Figure 5 is a schematic flowchart of a method for obtaining test case data according to an embodiment of the present invention;

[0036] Figure 6 is a schematic flowchart of a method for generating environment codes and use case codes according to an embodiment of the present invention;

[0037] Figure 7 is a schematic diagram of the main modules of a test case generation device according to an embodiment of the present invention;

[0038] Figure 8 is an exemplary system architecture diagram to which an embodiment of the present invention can be applied;

[0039] Figure 9 It is a schematic structural diagram of a computer system of a terminal device or a server suitable for implementing the embodiments of the present invention. Detailed implementation manners

[0040] The following describes exemplary embodiments of the present invention with reference to the accompanying drawings. Various details of the embodiments of the present invention are included to assist understanding, and they should be considered merely exemplary. Therefore, those of ordinary skill in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, descriptions of well-known functions and structures are omitted below.

[0041] In enterprise-level application development, the code quality of a project directly affects the user experience of the product. Therefore, high-quality code output requires minimizing logical errors as much as possible, and the logical stability of business modules is relatively important. To ensure code quality, unit testing of each module in the project is essential during the development process. The purpose of writing unit test code is to allow developers to verify the code logic to ensure that previous business modules will not be affected by the addition of new requirements during the rapid iteration of the business. Therefore, developers need to pay attention to business logic when writing unit test code for the project. However, the existing code analysis and generation tools only perform static code text analysis on the methods defined in the components, cannot accurately obtain the running time and context information of each method, and it is difficult to construct complete mock data. Therefore, the embodiments of the present invention provide a method for generating test cases, which can dynamically obtain the running situation of the executed methods and construct relatively complete mock data.

[0042] Figure 1 It is a method for generating test cases according to an embodiment of the present invention, as Figure 1 shown. The method includes:

[0043] Step S101: Obtain the storage path information and execution information of each component corresponding to the click operation. The execution information includes the input parameters, return values, pre-execution context information, and post-execution context information of the execution methods within the component;

[0044] Step S102: Generate a test case corresponding to the click operation according to the storage path information and the execution information.

[0045] The method of the embodiment of the present invention can be a method for automatically generating unit test case codes for front-end applications when running based on the Vue framework. Unit testing is to check and verify the smallest testable units in application software by writing codes. Vue is a progressive JavaScript framework for building user interfaces. The output of a front-end application is a functional page that can be operably interacted with in a browser or on a mobile device. The core of unit testing for front-end modules is to test whether components can work properly on the page, that is, whether the life cycles and methods defined inside the components can run normally. If all the operation logics on the page meet the expectations, it indicates that the functions of this front-end application system are normal.

[0046] The click operation can be a click operation or an interaction operation performed by a user in a visualization window. For example, it can be a click operation by a user using the application on a certain button on the page.

[0047] A page or a function is composed of multiple components, and multiple execution methods are defined inside each component. When a click operation is performed on the page, one click operation may correspond to the execution of multiple execution methods inside multiple components, so that the method of the embodiment of the present invention is a method for generating unit test cases for multiple components. When multiple click operations are performed on multiple positions on the page, all the execution methods of all components on the page can be called, and thus relatively complete test case simulation data can be obtained.

[0048] In the embodiment of the present invention, before step S102, the method further includes: obtaining click position information corresponding to the click operation, and storing the click position information and execution information correspondingly according to the identifier of the click operation. Among them, the click operation can be one or more click operations, and the click operation can be performed on the same position or multiple different positions.

[0049] Set the click operation identifier, such as setting it as key. When a click operation of the user is monitored, set the key value corresponding to the click operation. The click operation can be recorded by using a counter. For example, when a click operation is monitored, the counter is incremented by 1, and the key value is 1. Each click operation corresponds to click position information, storage path information and execution information of each corresponding component. Store the click position information, storage path information and execution information correspondingly according to the identifier of the click operation, so as to bind the click position information with the storage path information and execution information, which is convenient for verifying the correctness of the logic and knowing the triggering method of the operation during subsequent reuse testing.

[0050] A single click operation may call multiple execution methods within multiple components. When a user's click operation is detected, obtain the click position information corresponding to this click operation, as well as the storage path information and execution information of each component corresponding to this click operation. The execution information includes the input parameters, return values, pre-execution context information, and post-execution context information of the execution methods within each component called by this click operation.

[0051] The storage path information of a component is the storage location of the component in the local directory. An execution method can correspond to a function, and multiple execution methods can correspond to multiple functions. For a single click operation, it can correspond to the execution of multiple functions. Among them, the pre-execution context information and post-execution context information can be the state changes before and after a function is called. For example, for x = 1 and the function f(x) = x + 1, before f(x) is called, x = 1, and after f(x) is called, x = 2. Then, the state changes before and after the function is called can be obtained, and the function of the function f(x) can be obtained, so that test case code can be written for the function f(x).

[0052] In the embodiments of the present invention, the storage path information and execution information of each component corresponding to the click operation can be obtained in real-time or at regular intervals. For example, it can be obtained by using a timer at regular intervals, or it can be obtained in real-time by means of monitoring.

[0053] In the embodiments of the present invention, as Figure 2 shown, obtaining the execution information of each component corresponding to the click operation includes:

[0054] Step S201: For any execution method of any component, obtain the pre-execution context information of the execution method and the input parameters of the execution method;

[0055] Step S202: Call the execution method according to the pre-execution context information and the input parameters, and obtain the return value;

[0056] Step S203: Obtain the post-execution context information of the execution method according to the return value.

[0057] For a single click operation involving multiple execution methods in multiple components, for any execution method of any component, obtain the input parameters, return value, pre-execution context information, and post-execution context information of any execution method. Optionally, before any execution method is executed, determine whether the component corresponding to any execution method is from a third-party component. If it is not a third-party component, continue to execute the execution method. If it is from a third-party component, do not perform any additional processing and directly determine the function return value according to the Vue framework. Among them, a third-party component is a component referenced during application development, not a component to be tested within the project and not within the test scope. Therefore, it is necessary to exclude the execution methods from third-party components.

[0058] Before step S201, it further includes: determining that the number of execution methods being executed is less than a preset threshold.

[0059] In the embodiment of the present invention, to avoid page operation jamming caused by the same execution method, that is, the same execution method when performing the above steps, a flow-limiting process is performed on the same execution method. For example, for the method in the list rendering component that is frequently executed, a flow-limiting process is performed. Optionally, the number of execution methods with the same method name being executed is not greater than a preset threshold. That is to say, for the execution methods with the same method name, the number of execution methods being executed is limited to play a role in flow limiting. The preset threshold can be 1, 2, or other numbers, which can be limited according to the actual situation to ensure that the page does not jam. For example, it can be limited that only one execution method with the same method name is in the executing state.

[0060] In an optional implementation manner, an execution identifier can be set for the execution method. The same execution method, that is, the execution method with the same method name, is set with the same execution identifier, that is, the execution methods with different method names are set with different execution identifiers and do not affect each other. The execution identifier can indicate the state of the execution method as being executed and not being executed. For example, the execution identifier of execution method A can be set as Flag, the execution identifier Flag of being executed is set as false, and the execution identifier Flag of not being executed is set as true. When a certain execution method is being executed, the execution identifier Flag of this execution method is false, so that this execution method can execute step S201.

[0061] A timer can be used to control the execution identifier of the execution method, so that the execution identifier of the execution method can alternately change between the states of being executed and not being executed within a preset time. For example, it can be set that the execution identifiers of the same execution method alternate within 1 s. When it changes to the execution identifier of being executed, the above steps can be executed.

[0062] After obtaining the execution method execution information, i.e., the pre-execution context information, input parameters, return value, and post-execution context information, it is determined whether the execution method is currently being executed. If it is in a non-executing state, such as Flag being true, the function return value is directly returned. If it is in an executing state, such as Flag being false, the execution flag Flag is changed to non-executing true, and a timer is set. After a preset time, the execution flag is changed back to the executing state. For example, Flag can be set to false after 1s to facilitate the re-execution of the execution method.

[0063] The method of the embodiment of the present invention realizes obtaining or intercepting the execution information of each component involved in the click operation and the execution methods in each component, so as to provide a data source for the generation of subsequent test cases.

[0064] Since the method of the embodiment of the present invention is for a front-end application using the Vue framework, when developing components with Vue, the life cycle of the components and the coding of their internal methods need to comply with certain specifications, and then be parsed by the runtime module of Vue, and finally generate code that can run on multiple terminals. Before the project runs, Vue will perform initialization operations on the states, methods, and life cycles defined inside each component to mount them on the instances of each component.

[0065] In the embodiment of the present invention, a higher-order function is used to encapsulate the initialization process of the execution methods in the Vue source code to obtain the execution information of the execution methods in each component corresponding to the click operation, and the execution information and the storage path information of each component are thrown out through the Vue communication mechanism. Since the Vue front-end application is composed of multiple components, multiple components can form a component tree. Any component can find the root component layer by layer upwards, and the root component throws an event to the outside through $emit, and then the event thrown by $emit can be received through $on.

[0066] The storage path information of the component and the execution information of the execution method in the component can be obtained in real-time or at regular intervals. For example, the storage path information of the component and the execution information of the execution method in the component can be encapsulated as a methods-called (method call) event and thrown out. By listening in real-time, the methods-called event is obtained, and then the storage path information of the component and the execution information of the execution method are obtained.

[0067] In the embodiment of the present invention, before step S102, it further includes: removing duplicates from the execution information according to the method names of the execution methods.

[0068] When a click operation is monitored, obtain the click position information corresponding to the click operation. By monitoring the methods-called event, obtain the storage path information and execution information of each component involved in the click operation, and de-duplicate the execution information according to the method name. The obtained execution information is the execution information of the execution methods in each component called by the click operation. It may call execution methods with the same method name in different components. The execution information indicates the corresponding component name and method name. When the execution information has the same method name, delete the duplicate execution information according to the method name.

[0069] In the embodiments of the present invention, the de-duplicated execution information and storage path information obtained, which may also include the click position information, are sent as the data source of the test case to generate a test case.

[0070] Such as Figure 3 shown, generating a test case corresponding to the click operation according to the storage path information and execution information includes the following steps:

[0071] Step S301: Generate environment code according to the storage path information;

[0072] Step S302: Generate test code according to the execution information;

[0073] Step S303: Assemble the environment code and the test code to generate a test case.

[0074] A piece of front-end unit test case code can be divided into three parts: environment code, mock data declaration, and test assertions. For the three parts of content, preset code templates for the three parts, and fill the obtained data into the code templates to obtain the code of the test case.

[0075] The environment code is repeated for the test of each component and can be generated uniformly. The process of generating the environment code includes code such as introducing a test framework, introducing the component to be tested, and introducing dependent third-party packages.

[0076] In some embodiments, step S301 includes: obtaining the storage path and method name of the component; according to the method name, obtaining the source code of the execution method, converting the source code into an AST (Abstract Syntax Tree), and using babel (a toolchain mainly used to convert ECMAScript2015+ version code into backward-compatible JavaScript syntax so that it can run in current and older versions of browsers or other environments) for AST analysis, analyzing the asynchronous methods and their dependent modules in the component, and generating environment code in combination with the analysis results.

[0077] In the embodiments of the present invention, the environmental code is introduced by automatically introducing the environmental code through static code file analysis, so as to efficiently provide project code quality assurance and avoid the problem of low development efficiency caused by a large amount of repetitive environmental code writing.

[0078] In some embodiments, step S302 includes: according to the method name of the execution method, obtaining the input parameters, return value of the execution method corresponding to the method name, as well as the pre-execution context information and post-execution context information, performing a difference analysis on the pre-execution context information and the post-execution context information to obtain difference information, and filling the return value and the difference information into the code template to obtain test case code. For example, the pre-execution context information before of the execution method with the method name getDelivery is {x:1,y:1}, and the post-execution context information after is {x:2,y:1}, then the difference information is x: 2. Then, the input parameters, return value and difference information of the execution method are filled into the code templates of mock data declaration and test assertion to obtain test case code.

[0079] In some embodiments, step S302 includes: generating test case code according to the execution information and the click position information. The data of the click position information is filled into the corresponding code template and combined with the test code of the execution information to generate test case code.

[0080] In some embodiments, in step S303, by assembling the environmental code and the test case code, test case code is obtained, and then a test case is generated, that is, a unit test case of the front-end application is generated.

[0081] Such as Figure 4The following is a schematic flowchart of a method for obtaining execution information according to an embodiment of the present invention. In response to a user's click operation, traverse each execution method in each component involved in the user's click operation, and determine whether any execution method comes from a third-party component. If so, directly return the function return value and end the process. If not, set the Flag of an execution method with the same method name to false, obtain the pre-execution context information of the execution method from the component of the execution method and assign it to before and the input parameters of the execution method, then execute the execution method, and determine whether the execution method is an asynchronous method. If it is not an asynchronous method, obtain the return value res of the execution method. If it is an asynchronous method, obtain the asynchronous return value res.promise of the execution method, then obtain the post-execution context information of the execution method and assign it to after, and then determine whether the Flag of the execution method is false. If not, directly return the function return value res; if so, set Flag to true and throw a methods-called event, the data of which includes input parameters, return value, before, and after, then return the function return value res and end the process.

[0082] As Figure 5 The following is a schematic flowchart of a working process for obtaining test case data according to an embodiment of the present invention. First, define a counter as 0 and the operation data object data as an empty object, listen for click operations on the page. When a click operation occurs, increment the counter by 1, obtain the click position information (domdata) of the clicked object. When the methods-called event corresponding to the click operation is detected, obtain the storage path information and execution information corresponding to the click operation (denote the storage path information and execution information as clickdata), remove duplicates from the execution information in clickdata by method name, then use the counter as the key to store domdata and clickdata correspondingly. Then the obtained domdata and clickdata are the data for generating test cases, and then pass the obtained data to the use case generation module.

[0083] As Figure 6The following is a schematic flowchart of a method for generating environment code and use case code according to an embodiment of the present invention. Receive domdata and clickdata, obtain the file storage path path of the component of the execution method whose execution information has changed, and the method name methodName of the execution method. Parse the.vue file under the path path, find the source code of the execution method with the method name methodName, convert the source code into an AST, obtain the input parameter information of the function (such as which input parameters, the number of input parameters, etc.), match the expressions and assignment statements starting with this, such as this.xxx = yyy, analyze the import statements of the vue file, generate an object importObj with the imported method name as the key and the import path as the value, then determine whether there is a then statement or an await keyword in the code. If so, recursively traverse the expressions before the then statement block or after the await keyword to obtain the asynchronous request method name, and then match the method name from importObj to generate the environment code. If not, execute step S302 to generate the use case code according to the execution information.

[0084] The test case generation method provided by the embodiment of the present invention can visually and automatically generate relatively complete and high-quality test case code for developers. By clicking, obtain the click position information corresponding to the click operation, the storage paths of each component, and the execution information, that is, dynamically obtain the timing and context information of the execution method running. For each click operation, a test case can be obtained. This method can obtain real and reliable unit test data, and the generated unit test cases can be directly run and pass the test. The test case generation method of the embodiment of the present invention can directly use the real data online, saving the cumbersome process of constructing mock data. Moreover, by combining static code analysis to automatically introduce environment code, it can more efficiently ensure the quality of project code, thereby improving the user experience. At the same time, this method can also help developers quickly locate problems from the obtained context information to troubleshoot and solve problems when encountering development vulnerabilities, improving the application development efficiency.

[0085] According to another aspect of the embodiment of the present invention, as Figure 7 shown, a test case generation device 700 is provided, including a data collection module 701 and a use case generation module 702.

[0086] The data collection module 701 obtains the storage path information and execution information of each component corresponding to the click operation. The execution information includes the input parameters, return values, pre-execution context information, and post-execution context information of the execution method within the component.

[0087] The use case generation module 702 generates a test case corresponding to the click operation according to the storage path information and execution information.

[0088] In an embodiment of the present invention, the data collection module 701 includes an interceptor and a plug-in tool.

[0089] In an embodiment of the present invention, the data collection module 701 is further configured to: obtain the storage path information and execution information of each component corresponding to the click operation in a real-time or timed manner, which can be implemented by the interceptor.

[0090] In an embodiment of the present invention, the data collection module 701 is further configured to: for any execution method of any component, obtain the pre-execution context information and input parameters of the execution method; call the execution method according to the pre-execution context information and input parameters to obtain the return value; obtain the post-execution context information of the execution method according to the return value, which can be implemented by the interceptor.

[0091] In an embodiment of the present invention, the data collection module 701 is further configured to: determine that the number of execution methods being executed is not greater than a preset threshold, which can be implemented by the interceptor.

[0092] In an embodiment of the present invention, the data collection module 701 is further configured to: obtain the click position information corresponding to the click operation, and store the click position information, the storage path information, and the execution information correspondingly according to the identifier of the click operation, which can be implemented by the plug-in tool.

[0093] In an embodiment of the present invention, before generating a test case corresponding to the click operation according to the storage path information and the execution information, the data collection module 701 further includes: removing duplicates from the execution information according to the method name of the execution method, which can be implemented by the plug-in tool.

[0094] In an embodiment of the present invention, the test case generation module 702 is further configured to: generate environment code according to the storage path information; generate test code according to the execution information; assemble the environment code and the test code to generate the test case.

[0095] According to the test case generation device of the embodiment of the present invention, when the application runs, all click operations of the user on the front-end interface will be recorded. The recorded content includes the pre-execution context information and post-execution context information, input parameters, return values, component storage path information, and click position information of the execution methods in the component brought by the click operation. The recorded content is real and reliable data online and can be directly run and ensure passing the test as the data for generating the test case.

[0096] The test case generation device according to an embodiment of the present invention intercepts the data involved in each component during the user operation process in order to obtain the data of the user interaction operation, and analyzes the overall process of the data from the input component to the final output on the interface as the data source of the test case; at the same time, a plug-in tool such as a Vue plug-in is adopted. When the interceptor obtains the data, the plug-in tool de-duplicates the clickdata according to the method name, and can also combine the domdata and clickdata and pass them to the use case generation module, so as to realize the simple and intuitive generation of test case code.

[0097] According to another aspect of the embodiments of the present invention, there is provided an electronic device, including one or more processors; a storage device for storing one or more programs, which when executed by the one or more processors, cause the one or more processors to implement the test case generation method of the embodiments of the present invention.

[0098] According to still another aspect of the embodiments of the present invention, there is provided a computer-readable medium, on which a computer program is stored, and when the program is executed by a processor, the test case generation method of the embodiments of the present invention is implemented.

[0099] Figure 8 An exemplary system architecture 800 is shown to which the test case generation method or the test case generation device according to the embodiments of the present invention can be applied.

[0100] As Figure 8 shown, the system architecture 800 may include terminal devices 801, 802, 803, a network 804, and a server 805. The network 804 is used to provide a medium for a communication link between the terminal devices 801, 802, 803 and the server 805. The network 804 may include various connection types, such as wired, wireless communication links, or fiber optic cables, etc.

[0101] Users can use the terminal devices 801, 802, 803 to interact with the server 805 through the network 804 to receive or send messages, etc. Various communication client applications may be installed on the terminal devices 801, 802, 803, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only as examples).

[0102] The terminal devices 801, 802, 803 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, and desktop computers, etc.

[0103] The server 805 can be a server that provides various services. For example, it can be a background management server (only an example) that supports shopping websites browsed by users using the terminal devices 801, 802, and 803. The background management server can analyze and process data such as product information query requests received, and feedback the processing results (such as target push information, product information - only examples) to the terminal devices.

[0104] It should be noted that the test case generation method provided by the embodiments of the present invention is generally executed by the server 805. Correspondingly, the test case generation device is generally set in the server 805.

[0105] It should be understood that Figure 8 the numbers of terminal devices, networks, and servers in

[0106] are merely illustrative. According to actual needs, there can be any number of terminal devices, networks, and servers. Figure 9 is a schematic structural diagram of a computer system 900 of a terminal device suitable for implementing the embodiments of the present invention. Figure 9 The terminal device shown is merely an example and should not impose any limitations on the functions and usage scope of the embodiments of the present invention.

[0107] As Figure 9 shown, the computer system 900 includes a central processing unit (CPU) 901, which can execute various appropriate actions and processes according to the program stored in the read-only memory (ROM) 902 or the program loaded from the storage section 908 into the random access memory (RAM) 903. In the RAM 903, various programs and data required for the operation of the system 900 are also stored. The CPU 901, ROM 902, and RAM 903 are connected to each other via a bus 904. The input / output (I / O) interface 905 is also connected to the bus 904.

[0108] The following components are connected to the I / O interface 905: an input section 906 including a keyboard, a mouse, etc.; an output section 907 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc. and a speaker, etc.; a storage section 908 including a hard disk, etc.; and a communication section 909 including a network interface card such as a LAN card, a modem, etc. The communication section 909 performs communication processing via a network such as the Internet. The drive 910 is also connected to the I / O interface 905 as needed. A removable medium 911, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 910 as needed, so that the computer program read from it can be installed into the storage section 908 as needed.

[0109] In particular, according to the embodiments disclosed in the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, the embodiments disclosed in the present invention include a computer program product that includes a computer program carried on a computer-readable medium, and the computer program includes program code for performing the methods shown in the flowcharts. In such an embodiment, the computer program can be downloaded and installed from the network through the communication section 909, and / or installed from the removable medium 911. When the computer program is executed by the central processing unit (CPU) 901, the above functions defined in the system of the present invention are performed.

[0110] It should be noted that the computer-readable medium shown in the present invention can be a computer-readable signal medium or a computer-readable storage medium or any combination of the two. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples of the computer-readable storage medium can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, the computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. And in the present invention, the computer-readable signal medium can include a data signal propagated in a baseband or as part of a carrier wave, which carries the computer-readable program code. Such a propagated data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal medium can also be any computer-readable medium other than the computer-readable storage medium, which can send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted by any suitable medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0111] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagram may represent a module, a segment of a program, or a part of code, and the above-mentioned module, segment of a program, or part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than that marked in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram or flowchart, as well as combinations of blocks in the block diagram or flowchart, can be implemented by a dedicated hardware-based system that performs the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.

[0112] The modules involved in the embodiments of the present invention can be implemented in software or in hardware. The described modules can also be set in a processor. For example, it can be described as: a processor includes a data collection module and a use case generation module. Among them, the names of these modules do not constitute a limitation to the module itself in some cases. For example, the use case generation module can also be described as "a module that generates test cases corresponding to click operations according to storage path information and execution information".

[0113] As another aspect, the present invention also provides a computer-readable medium, which can be included in the device described in the above embodiments; or can exist separately without being assembled into the device. The above computer-readable medium carries one or more programs. When the one or more programs are executed by the device, the device includes: obtaining storage path information and execution information of each component corresponding to a click operation, where the execution information includes input parameters, return values, pre-execution context information, and post-execution context information of the execution method within the component; generating test cases corresponding to the click operation according to the storage path information and the execution information.

[0114] According to the technical solution of the embodiment of the present invention, the test case generation method provided by the embodiment of the present invention can visually and automatically generate relatively complete and high-quality test case codes for developers. By clicking an operation, the click position information corresponding to the click operation, the storage paths of each component, and the execution information can be obtained, that is, the timing and context information of the execution method running are dynamically obtained, and a test case can be obtained for each click operation. This method can obtain real and reliable unit test data, and the generated unit test cases can be directly run and pass the test. The test case generation method of the embodiment of the present invention can directly use the real data online, saving the cumbersome process of constructing simulated data. Moreover, by combining static code analysis to automatically introduce environmental code, it can more efficiently ensure the quality of project code, thereby improving the user experience. At the same time, this method can also help developers quickly locate problems from the obtained context information to troubleshoot and solve problems when encountering development vulnerabilities, improving the application development efficiency.

[0115] The above specific implementation manners do not constitute a limitation on the protection scope of the present invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.

Claims

1. A method for generating test cases, characterized in that, Including: Obtain the storage path information and execution information of each component corresponding to the click operation, where the execution information includes the input parameters, return value, pre-execution context information, and post-execution context information of the execution method within the component; Generate a test case corresponding to the click operation according to the storage path information and the execution information, including: generating environment code according to the storage path information, generating test code according to the execution information, and assembling the environment code and the test code to generate the test case.

2. The method according to claim 1, characterized in that, Obtain the storage path information and the execution information of each component corresponding to the click operation in a real-time or timed manner.

3. The method according to claim 1, characterized in that, Obtain the execution information of each component corresponding to the click operation, including: For any execution method of any component, obtain the pre-execution context information and input parameters of the any execution method; According to the pre-execution context information and the input parameters, call the execution method to obtain the return value; According to the return value, obtain the post-execution context information of the execution method.

4. The method according to claim 3, characterized in that, Before obtaining the pre-execution context information and input parameters of any of the execution methods, determine that the number of the execution methods being executed is not greater than a preset threshold.

5. The method according to claim 1, characterized in that, Also including: Obtain the click position information corresponding to the click operation, and store the click position information, the storage path information, and the execution information correspondingly according to the identifier of the click operation.

6. The method according to any one of claims 1 to 5, characterized in that, Before generating the test case corresponding to the click operation according to the storage path information and the execution information, it also includes: Deduplicate the execution information according to the method name of the execution method.

7. A test case generation device, characterized in that, Including: A data collection module that obtains the storage path information and execution information of each component corresponding to the click operation, where the execution information includes the input parameters, return value, pre-execution context information, and post-execution context information of the execution method within the component; A use case generation module that generates a test case corresponding to the click operation according to the storage path information and the execution information, including: generating environment code according to the storage path information, generating test code according to the execution information, and assembling the environment code and the test code to generate the test case.

8. An electronic device, characterized in that, Including: One or more processors; A storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1-6.

9. A computer-readable medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method according to any one of claims 1-6.

Citation Information

Patent Citations

  • Method for constructing test use case of software-as-a-service (SaaS) software based on durable X-machine (DXM) model

    CN102253887A

  • Method and device for generating test case, medium and electronic equipment

    CN111367791A