A test case generation method and device, electronic device and storage medium
By matching and generating test cases, the problem of high generation cost of test cases in the prior art is solved, and the efficiency of automated testing is improved.
Patent Information
- Application Number
- CN202110970088.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-23
- Publication Date
- 2025-03-25
- Estimated Expiration
- 2041-08-23
AI Technical Summary
In the prior art, the test case generation method has high writing cost, which leads to inefficiency of automated testing.
By determining the characteristic information of the target test object, matching the candidate use case model, and generating test cases based on the target use case model, reducing the workload of manual writing.
It effectively reduces the workload of test case writing, lowers the threshold for automated testing, and improves the efficiency of automated testing.
Smart Images

Figure CN113778864B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of testing technology, and in particular to a method and device for generating a test case, an electronic device, and a storage medium. Background Art
[0002] With the rapid development of the Internet, interface-based automated testing has received more and more attention from Internet technology development teams, and has also played an important role in daily work. Automated testing requires continuous maintenance and writing of automated use cases. Summary of the invention
[0003] In order to solve the technical problem of high test case writing cost in the test case generation method, the present application provides a test case generation method and device, an electronic device and a storage medium.
[0004] In a first aspect, an embodiment of the present application provides a method for generating a test case, comprising:
[0005] Determine the target test objects to be tested;
[0006] Acquire target object feature information of the target test object, wherein the target object feature information includes at least one target object feature;
[0007] By using the target object feature information, a target use case model corresponding to the target test object is matched among all candidate use case models, wherein the matching degree between the target model feature information of the target use case model and the target object feature information meets a preset requirement, and the target model feature information includes at least one target model feature;
[0008] A target test case for testing the target test object is generated according to the target use case model.
[0009] Optionally, as in the aforementioned method, obtaining target object feature information of the target test object includes:
[0010] Determine at least one interface to be tested included in the target test object;
[0011] The target object feature information of the target test object is obtained by acquiring all target interface features of each of the interfaces to be tested.
[0012] Optionally, as in the aforementioned method, before matching a target use case model corresponding to the target test object among all candidate use case models through the target object feature information, the method includes:
[0013] Obtain a historical test case code script corresponding to a historical scenario, wherein the historical test case code script includes at least one historical test case, and the historical test case corresponds one-to-one to a candidate interface in the historical scenario;
[0014] Extract target keyword information from the historical test case code script;
[0015] Inputting the target keyword information into the target neural network, predicting the prediction test cases and prediction usage information required to be used in the historical scenario, wherein the prediction usage information is used to indicate the combination relationship of each of the prediction test cases;
[0016] Matching each of the predicted test cases in the historical test case code script according to the target keyword information;
[0017] Combining the predicted test cases according to the predicted usage information to obtain a pending use case model;
[0018] Generate a corresponding pending test case code script according to the pending test case model;
[0019] When the test result after the historical scenario is tested by the pending test case code script meets the preset result, the pending test case model is determined as the candidate use case model corresponding to the historical scenario.
[0020] Optionally, as in the aforementioned method, extracting target keyword information from the historical test case code script includes:
[0021] Extract keywords from the historical test case code script to obtain candidate keywords;
[0022] Among all the candidate keywords, the target keyword information that meets the preset requirements is selected.
[0023] Optionally, as in the aforementioned method, after extracting keywords from the historical test case code script and obtaining candidate keyword information, the method further includes:
[0024] According to the function of each of the candidate interfaces, the candidate keyword information is clustered to obtain a candidate keyword set corresponding to each of the functions, wherein each of the candidate keyword sets includes at least one candidate keyword.
[0025] Optionally, as in the above method, the selecting the target keyword information satisfying the preset requirements from among all the candidate keywords includes:
[0026] According to a preset weighting scheme, based on the weight of each candidate keyword and the number of repetitions of each candidate keyword in all the candidate keywords, a weighted value of each candidate keyword is determined;
[0027] After removing duplicates from all the candidate keywords, the keywords after removing duplicates are obtained;
[0028] According to the weighted value of each of the deduplicated keywords, the target keyword information is determined from all the deduplicated keywords, wherein the weighted value of the target keyword information is higher than the weighted values of other deduplicated keywords.
[0029] Optionally, the method as described above further includes:
[0030] Determine a target test framework corresponding to the target scenario according to the business feature information of the business corresponding to the target scenario;
[0031] Generate a test case template and a data template that are adapted to the target test framework and correspond to the target interface according to the target interface required by the target scenario;
[0032] According to the test case template and the data template corresponding to the target interface, a candidate test case of the target interface corresponding to the target scenario is generated.
[0033] Optionally, as in the aforementioned method, matching a target use case model corresponding to the target test object from among all candidate use case models through the target object feature information includes:
[0034] Acquire candidate model feature information of the candidate use case model, wherein there is a one-to-one correspondence between the candidate use case model and the candidate model feature information, and the candidate model feature information includes at least one candidate model feature;
[0035] Obtaining the degree of match between the candidate model feature information and the target object feature information by determining the number of the candidate model features, among all the candidate model features, that are identical to any one of the target object features among all the target object features;
[0036] When the matching degree meets the preset requirement, the candidate use case model corresponding to the matching degree is used as the target use case model.
[0037] Optionally, as in the aforementioned method, generating a target test case for testing the target test object according to the target use case model includes:
[0038] Generating a test case combination corresponding to the target test object according to the target use case model, wherein the test case combination includes a test case corresponding to each interface in the target test object;
[0039] The test case combination is integrated into the test framework corresponding to the target use case model to obtain the target test case for testing the target test object.
[0040] In a second aspect, an embodiment of the present application provides a test case generation device, comprising:
[0041] A determination module, used to determine a target test object to be tested;
[0042] An acquisition module, configured to acquire target object feature information of the target test object, wherein the target object feature information includes at least one target object feature;
[0043] A matching module, configured to match a target use case model corresponding to the target test object from among all candidate use case models through the target object feature information, wherein the matching degree between the target model feature information of the target use case model and the target object feature information meets a preset requirement, and the target model feature information includes at least one target model feature;
[0044] A generating module is used to generate a target test case for testing the target test object according to the target test case model.
[0045] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other via the communication bus;
[0046] The memory is used to store computer programs;
[0047] The processor is used to implement any of the methods described above when executing the computer program.
[0048] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the storage medium includes a stored program, wherein the program executes a method as described in any of the preceding items when executed.
[0049] The above technical solution provided by the embodiment of the present application has the following advantages compared with the prior art:
[0050] Compared with the test case generation method in the related art, the method provided in the embodiment of the present application can effectively reduce the workload of manually writing test cases, lower the threshold for automated testing of interfaces or business scenarios, and improve the efficiency of automated testing. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0052] 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 embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0053] Figure 1 A flowchart of a method for generating a test case provided in an embodiment of the present application;
[0054] Figure 2 A flowchart of a method for generating a test case provided in another embodiment of the present application;
[0055] Figure 3 A flowchart of a method for generating a test case provided in another embodiment of the present application;
[0056] Figure 4 A block diagram of a test case generation device provided in an embodiment of the present application;
[0057] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0058] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0059] In related technologies, in order to quickly and efficiently write and maintain automated test cases and scripts, the following solutions are used:
[0060] Solution 1: Manually design test cases, manually write test cases, run test cases, and finally output test reports.
[0061] Solution 2: Based on historical use cases, reuse historical test cases, automatically generate common and necessary use cases, and reduce the writing of some use cases.
[0062] Solution 3: Based on the existing open source frameworks such as RF, Pytest, TestNg, etc., make certain encapsulation modifications to write and generate automated use cases.
[0063] The above solution has the following problems:
[0064] Problems with Solution 1: The efficiency of writing and executing automated use cases is low, different APIs must be designed, written, and run separately, and the degree of reuse of historical use cases is low.
[0065] Problems with Solution 2: Historical test cases are utilized, which improves writing efficiency to a certain extent, but the automated scripts will be particularly redundant, which is not conducive to subsequent maintenance.
[0066] Problems with Solution 3: After the open source framework is encapsulated, it can not only improve the reuse of historical use cases and improve writing efficiency, but also reduce the redundancy of automated test scripts. However, it has certain requirements on the tester's ability to write scripts, which increases the learning cost. At the same time, the transformation within the framework has poor applicability to different businesses and different frameworks and is not universal.
[0067] There is no effective solution to the technical problem of high test case writing cost in the test case generation method of the related technology.
[0068] According to one aspect of an embodiment of the present application, a method for generating a test case is provided. Optionally, in this embodiment, the method for generating a test case can be applied to a hardware environment consisting of a terminal and a server. The server is connected to the terminal via a network, and can be used to provide services for the terminal or a client installed on the terminal. A database can be set on the server or independently of the server to provide data storage services for the server.
[0069] The above network may include but is not limited to at least one of the following: wired network, wireless network. The above wired network may include but is not limited to at least one of the following: wide area network, metropolitan area network, local area network, and the above wireless network may include but is not limited to at least one of the following: WIFI (Wireless Fidelity), Bluetooth. The terminal may not be limited to a PC, a mobile phone, a tablet computer, etc.
[0070] The test case generation method of the embodiment of the present application can be executed by a server, a terminal, or a server and a terminal together. The terminal can also execute the test case generation method of the embodiment of the present application by a client installed thereon.
[0071] Taking the method for generating the test case in this embodiment executed by the server as an example, Figure 1A method for generating a test case provided in an embodiment of the present application comprises the following steps:
[0072] Step S101, determining a target test object to be tested.
[0073] The test case generation method in this embodiment can be applied to scenarios where new business scenarios (e.g., online shopping scenarios, query scenarios, etc.) need to be tested. In the embodiment of this application, the scenario of testing a new interface is taken as an example. If there is no contradiction, the above test case generation method is also applicable to other scenarios.
[0074] When the target test object is a business scenario, since a business scenario may include multiple interfaces or only one interface, the number of interfaces in the target test object will also change according to the actual situation. For example, taking the shopping scenario as an example, it is necessary to have interfaces such as query, order, and payment; when it is a query scenario, only the query interface may exist.
[0075] Step S102: acquiring target object feature information of a target test object, wherein the target object feature information includes at least one target object feature.
[0076] After the target test object to be tested is determined, the target object feature information of the target test object can be obtained.
[0077] The target object feature information may be information consisting of one or more keywords obtained after keyword extraction of the test case code script corresponding to the target test object, including but not limited to: scenarios (e.g., shopping, query, etc.), interface information (e.g., interface path), interface parameters (e.g., input parameter fields).
[0078] Step S103, matching a target use case model corresponding to the target test object from among all candidate use case models through the target object feature information, wherein the matching degree between the target model feature information of the target use case model and the target object feature information meets the preset requirements, and the target model feature information includes at least one target model feature.
[0079] After the target object characteristic information is determined, a target use case model corresponding to the target test object can be matched among all candidate use case models.
[0080] The candidate use case model may be a data model that can characterize the combination relationship between various test cases in the corresponding business scenario.
[0081] The candidate use case model can adopt an RNN neural network. Since the candidate use case model corresponds to a specific business scenario and includes multiple test cases, the candidate use case model also corresponds to candidate model feature information; and each candidate model feature information includes at least one candidate model feature.
[0082] After determining the target object feature information and the candidate object feature information of each candidate use case model, the matching degree between the target object feature and each candidate object feature information can be determined, and when the matching degree meets the preset result, the candidate use case model corresponding to the matching degree is determined as the target use case model.
[0083] Step S104: generating a target test case for testing the target test object according to the target use case model.
[0084] After the target use case model is determined, a target test case for testing the target test object can be generated according to the target use case model, so that the target test object can be tested through the target test case and the corresponding test result can be obtained.
[0085] The target test case can be a single test case or a collection of multiple test cases. The specific number of test cases is adjusted based on the actual situation of the target test object. For example, when the target test object is an independent query interface, the target test case can be a test case for testing the query interface. When the target test object is a shopping scenario, the target test case needs to include test cases corresponding to each interface under the shopping scenario.
[0086] Compared with the test case generation method in the related art, the method in this embodiment can effectively reduce the workload of manually writing test cases, lower the threshold for automated testing of interfaces or business scenarios, and improve the efficiency of automated testing.
[0087] As an optional implementation, as in the above method, the step S102 of acquiring the target object feature information of the target test object includes the following steps:
[0088] Step S201: determine at least one interface to be tested included in the target test object.
[0089] Step S202: obtaining target object feature information of the target test object by acquiring all target interface features of each interface to be tested.
[0090] After the target test object is determined, all interfaces to be tested included in the target test object can be determined.
[0091] Since each interface to be tested has corresponding features, keywords can be extracted for each interface to be tested to obtain all target interface features of each interface to be tested, and then target object feature information of the target test object can be obtained based on all target interface features.
[0092] For example, text preprocessing can be performed on each interface document of the target test object, and the target interface features in each interface document can be extracted through word segmentation methods such as forward matching based on string matching, mutual information based on statistical methods, etc., and then the target interface features corresponding to each interface to be tested can be obtained, and the target object feature information of the target test object can be obtained based on all target interface features.
[0093] Through the method in this embodiment, the target object feature information of the target test object can be quickly extracted, so as to match the target use case model corresponding to the target test object according to the target object feature information.
[0094] like Figure 2 As shown, as an optional implementation, as in the above method, before matching the target use case model corresponding to the target test object in all candidate use case models through the target object feature information in step S103, the method includes the following steps:
[0095] For example, in the test of the resource management business module, keyword information such as device type and node type is sampled from the historical test case code script according to the preset keyword weight, the sampled data set is sorted and encoded, and then this information is input into the RNN neural network for learning, and a data model with keyword labels is output.
[0096] Step S301, obtaining a historical test case code script corresponding to a historical scenario, wherein the historical test case code script includes at least one historical test case, and the historical test case corresponds one-to-one to the candidate interface in the historical scenario.
[0097] When the historical scenarios have been tested in advance, the historical test case code scripts corresponding to the historical scenarios can be obtained.
[0098] The historical test case code script may be a file including a data file and specific codes for running; and the historical test case code script includes all historical test cases used to test historical scenarios, so there are historical test cases corresponding one-to-one to the candidate interfaces in each historical scenario.
[0099] Step S302: extract target keyword information from historical test case code scripts.
[0100] The historical test case code script includes all historical test cases used to test historical scenarios. Therefore, by performing keyword extraction on the historical test case code script, target keyword information can be extracted.
[0101] The target keyword information may include one or more keywords of a preset type.
[0102] Step S303, inputting the target keyword information into the target neural network, predicting the prediction test cases and prediction usage information required in the historical scenarios, wherein the prediction usage information is used to indicate the combination relationship between the prediction test cases.
[0103] After obtaining the target keyword information, the target keyword information can be input into the target neural network so that the target neural network can analyze the target keyword information to obtain the predicted test cases and predicted usage information required for use in historical scenarios.
[0104] The prediction test case may be a test case required for use by the target neural network based on the historical scenario analyzed according to the target keyword information. Optionally, the target neural network may be an RNN (recursive neural network).
[0105] The predicted usage can be the combination relationship of various predicted test cases in the historical scenarios obtained by the target neural network based on the target keyword information analysis, and the combination relationship can be the sequence relationship of various predicted test cases in the testing process; for example, when the historical scenario is a shopping scenario, then in terms of logical relationship, the test case corresponding to the interface for generating an order must be after the test case corresponding to the checkout interface.
[0106] Step S304, matching each predicted test case in the historical test case code script according to the target keyword information.
[0107] The target keyword information is extracted from the historical test case code script, so each keyword in the target keyword information exists in the historical test case code script.
[0108] Generally, each test case has multiple keywords. Therefore, the corresponding predicted test case can be matched in the historical test case code script through each keyword in the target keyword information.
[0109] Step S305, combining the predicted test cases according to the predicted usage information to obtain a pending use case model.
[0110] After obtaining the predicted usage information and the predicted test cases, the predicted test cases can be combined according to the predicted usage information to obtain a preliminarily determined pending use case model.
[0111] Step S306, generating a corresponding pending test case code script according to the pending test case model.
[0112] After obtaining the pending use case model, the pending use case model can be integrated into the corresponding test framework to obtain the pending test case code script that can be used for testing.
[0113] Step S307, when the test result after testing the historical scenario through the pending test case code script meets the preset result, the pending test case model is determined as a candidate use case model corresponding to the historical scenario.
[0114] After obtaining the pending test case code script, the historical scenario can be tested through the pending test case code script and the corresponding test results can be obtained. When the test results meet the preset results, the pending use case model is determined as the candidate use case model corresponding to the historical scenario.
[0115] The preset result may be a result indicating that the historical scenario can be tested by the pending test case code script. When the pending test case code script cannot test the historical scenario, it means that the obtained pending use case model still has errors and needs to be further improved before the historical scenario can be tested. On the contrary, when the test result meets the preset result, the pending use case model is determined as a candidate use case model corresponding to the historical scenario, that is, the candidate use case model can be used to test the historical scenario.
[0116] Through the method in this embodiment, the use case model corresponding to each scenario can be quickly determined, thereby improving the efficiency of determining the use case model.
[0117] As an optional implementation, as in the above method, the step S302 of extracting target keyword information from the historical test case code script includes the following steps:
[0118] Step S401, extract keywords from historical test case code scripts to obtain candidate keywords.
[0119] After determining the historical test case code script, you can use a preset string to match it in the historical test case code script. After locating the corresponding field according to the string, you can extract the information of the field as a keyword to obtain the keyword extracted from each string. Multiple identical keywords or multiple different keywords can be extracted from one string. When there are multiple identical test cases in the historical scenario or the keywords of the same field in different test cases are the same, multiple identical keywords can be extracted from one string; after keyword extraction through each string, all candidate keywords can be obtained.
[0120] Step S402: Select target keyword information that meets preset requirements from among all candidate keywords.
[0121] After all candidate keywords are determined, in order to avoid duplicate or less important candidate keyword information, all candidate keyword information may be further screened to obtain target keyword information.
[0122] As an optional implementation, as in the aforementioned method, after extracting keywords from the historical test case code script in step S401 to obtain candidate keyword information, the method further includes the following steps:
[0123] Step S501 : clustering candidate keyword information according to the function of each candidate interface to obtain a candidate keyword set corresponding to each function, wherein each candidate keyword set includes at least one candidate keyword.
[0124] After determining the candidate interface corresponding to each historical test case, the function of each candidate interface can be determined, such as query, configuration, analysis, big data, etc. After determining the candidate keywords, all candidate keywords corresponding to each function can be determined, and then a candidate keyword set corresponding to each function can be obtained.
[0125] After obtaining the candidate keyword set corresponding to each function, the candidate keywords in the candidate keyword set for each function may be screened again to obtain target keyword information corresponding to each function.
[0126] Through the method in this embodiment, when it is necessary to establish a candidate use case model for a scenario that only includes an interface of a certain function, it is only necessary to search in the candidate keyword set corresponding to the function, thereby improving the accuracy and efficiency of establishing the candidate use case model.
[0127] As an optional implementation, as in the above method, the step S402 of selecting target keyword information that meets the preset requirements from all candidate keywords includes the following steps:
[0128] Step S601: According to a preset weighting scheme, a weight value of each candidate keyword is determined according to the weight of each candidate keyword and the number of repetitions of each candidate keyword among all candidate keywords.
[0129] The weight of the candidate keyword may be information indicating the importance of the candidate keyword. For example, when the type of the candidate keyword is scene, interface information, or interface parameter, the corresponding weight may be higher than the weight of other types of candidate keywords.
[0130] In addition, after all candidate keywords are obtained, if the same candidate keyword appears many times, it means that the candidate keyword is highly important.
[0131] Therefore, the preset weighting scheme may be a scheme for determining the weighted value of each candidate keyword according to the weight and the number of repetitions of each candidate keyword.
[0132] Step S602: After removing duplicates from all candidate keywords, the keywords after removing duplicates are obtained.
[0133] Since there may be repeated keywords in the candidate keywords, it is not conducive to the later matching of test cases according to the candidate keywords. Therefore, all candidate keywords are deduplicated and the remaining candidate keywords are used as the keyword information after deworming.
[0134] Step S603, determining target keyword information from all the deduplicated keywords according to the weighted value of each deduplicated keyword, wherein the weighted value of the target keyword information is higher than the weighted values of other deduplicated keywords.
[0135] The keywords after deduplication are not repeated, and since a corresponding weighted value is calculated for each candidate keyword, each keyword after deduplication also has a corresponding weighted value.
[0136] You can filter each deduplicated keyword based on the weighted value to get the target keyword information.
[0137] For example, the number N of keywords in the target keyword information may be determined, and then the deduplicated keywords are sorted in descending order according to the weighted values, and the target keyword information may be obtained by taking the first N deduplicated keywords.
[0138] Through the method in this embodiment, it is possible to avoid the situation where too many keywords are screened out, and candidate keywords with higher importance can be retained, which can effectively improve the efficiency of determining candidate use case models in the later stage.
[0139] like Figure 3As shown, as an optional implementation, the method as described above further includes the following steps:
[0140] Step S701: determine a target test framework corresponding to the target scenario according to business feature information of the business corresponding to the target scenario.
[0141] Step S702: Generate a test case template and a data template that are adapted to the target test framework and correspond to the target interface according to the target interface required by the target scenario.
[0142] Step S703: Generate candidate test cases corresponding to the target scenario of the target interface according to the test case template and the data template corresponding to the target interface.
[0143] If the target scenario has not been tested, there is no use case model and test case corresponding to the target scenario. Therefore, it is necessary to generate candidate test cases corresponding to each target interface in the target scenario.
[0144] Different businesses have different business feature information (ie, business characteristics), and are therefore suitable for different test frameworks (eg, RF, Pytest, TestNg, etc.).
[0145] After determining the target test framework corresponding to the target scenario according to the business feature information of the business corresponding to the target scenario, all target interfaces required for the target scenario can be determined, and then test case templates and data templates that are adapted to the target test framework and correspond to the target interfaces can be generated.
[0146] The test case template may be a template conforming to the format of a target test framework.
[0147] The data template may be a template for defining the parameters required by the target interface. For example, when the target interface is a login interface, the data template may define that a user name and password need to be written.
[0148] After determining the test case template and data template corresponding to the target interface, candidate test cases corresponding to the target scenario of the target interface can be generated.
[0149] Furthermore, based on all interfaces in the target scenario, a test case code script corresponding to the target scenario can be generated according to each candidate test case.
[0150] Through the method in this embodiment, when there is no test case corresponding to the target scenario, candidate test cases corresponding to the target interface can be generated first, so that candidate use case models can be obtained later based on the generated candidate test cases.
[0151] As an optional implementation, as in the above method, the step S103 of matching the target use case model corresponding to the target test object from all candidate use case models through the target object feature information includes the following steps:
[0152] Step S801, obtaining candidate model feature information of a candidate use case model, wherein there is a one-to-one correspondence between the candidate use case model and the candidate model feature information, and the candidate model feature information includes at least one candidate model feature.
[0153] Since the candidate use case model corresponds to a specific business scenario and includes multiple test cases, the candidate use case model also corresponds to unique candidate model feature information; and each candidate model feature information includes at least one candidate model feature.
[0154] Step S802, obtaining the degree of match between the candidate model feature information and the target object feature information by determining the number of candidate model features among all the candidate model features that are the same as any target object feature among all the target object features.
[0155] After determining the target object feature information and the candidate object feature information of each candidate use case model, the matching degree between the target object feature and each candidate object feature information can be determined.
[0156] The matching degree may be determined by determining the number of candidate model features among all candidate model features that are identical to any target object feature among all target object features.
[0157] For example, if there is candidate model feature information A (including five candidate model features, a1, a2, a3, a4, and a5) of candidate use case model I and target object feature information B (including five target model features, a1, a2, a3, a6, and a7), the matching degree between candidate model feature information A and target object feature information B can be the quotient of the same number of features and the total number of features, that is, (3+3) / (5+5)=0.6.
[0158] Step S803: When the matching degree is greater than or equal to a preset matching degree threshold, the candidate use case model corresponding to the matching degree is used as the target use case model.
[0159] After the matching degree is obtained, it can be determined whether the candidate use case model can be used as the target use case model based on the matching degree.
[0160] For example, when the preset matching threshold is 0.8, and the matching degree 1 between the above-mentioned candidate model feature information A and the target object feature information B of a test task is 0.6, the candidate use case model corresponding to the matching degree 1, that is, candidate use case model I cannot be used as the target use case model of the target test object. When there is a candidate use case model II whose candidate model feature information C and the target object feature information B have a matching degree 2 of 0.9, the candidate use case model corresponding to the matching degree 2, that is, candidate use case model II can be used as the target use case model of the target test object.
[0161] Through the method in this embodiment, the target use case model corresponding to the target test object can be quickly matched, thereby improving the matching efficiency.
[0162] As an optional implementation, as in the above method, the step S104 of generating a target test case for testing the target test object according to the target use case model includes the following steps:
[0163] Step S901: Generate a test case combination corresponding to a target test object according to a target use case model, wherein the test case combination includes a test case corresponding to each interface in the target test object.
[0164] After obtaining the target use case model corresponding to the target test object, a test case combination corresponding to the target test object can be generated according to the target use case model. The test case combination can include a test case corresponding to each interface and indicate the logical relationship between each test case.
[0165] For example, the use case model in the resource management module contains keywords such as node type, device type, and node status. When the same keywords appear in the test scenario, it can fall on this use case model, combine the interface test cases in the model with the new interface, and construct a new business test scenario.
[0166] Step S902: Integrate the test case combination into the test framework corresponding to the target test case model to obtain a target test case for testing the target test object.
[0167] After obtaining the test case combination, the test case combination can be integrated into the corresponding test framework to obtain the target test case, and finally the target test case is run to generate a test report. At the same time, the test case is fed back to the historical test case library and then trained and learned by the deep learning machine, so as to achieve the purpose of enriching the model and refining the business scenario.
[0168] like Figure 4 As shown, according to an embodiment of another aspect of the present application, a test case generation device is also provided, including:
[0169] Determine module 1, used to determine the target test object to be tested;
[0170] An acquisition module 2 is used to acquire target object feature information of a target test object, wherein the target object feature information includes at least one target object feature;
[0171] A matching module 3 is used to match a target use case model corresponding to a target test object from among all candidate use case models through target object feature information, wherein the matching degree between the target model feature information of the target use case model and the target object feature information meets a preset requirement, and the target model feature information includes at least one target model feature;
[0172] The generating module 4 is used to generate a target test case for testing the target test object according to the target test case model.
[0173] Specifically, the specific process of each module in the device of the embodiment of the present invention realizing its function can be referred to the relevant description in the method embodiment, which will not be repeated here.
[0174] According to another embodiment of the present application, there is also provided an electronic device, including: Figure 5 As shown, the electronic device may include: a processor 1501 , a communication interface 1502 , a memory 1503 and a communication bus 1504 , wherein the processor 1501 , the communication interface 1502 , and the memory 1503 communicate with each other via the communication bus 1504 .
[0175] Memory 1503, used for storing computer programs;
[0176] The processor 1501 is used to implement the steps of the above method embodiment when executing the program stored in the memory 1503.
[0177] The bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0178] The communication interface is used for communication between the above electronic device and other devices.
[0179] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0180] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0181] An embodiment of the present application further provides a computer-readable storage medium, the storage medium including a stored program, wherein the method steps of the above method embodiment are executed when the program is run.
[0182] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0183] The foregoing is merely a specific embodiment of the present invention, which enables those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A method for generating a test case, characterized in that: include: Determine the target test objects to be tested; Acquire target object feature information of the target test object, wherein the target object feature information includes at least one target object feature; Obtain a historical test case code script corresponding to a historical scenario, wherein the historical test case code script includes at least one historical test case, and the historical test case corresponds one-to-one to a candidate interface in the historical scenario; extract target keyword information from the historical test case code script; input the target keyword information into a target neural network, predict the predicted test cases and predicted usage information required for the historical scenario, wherein the predicted usage information is used to indicate the combination relationship of each of the predicted test cases; match each of the predicted test cases in the historical test case code script according to the target keyword information; combine the predicted test cases according to the predicted usage information to obtain a pending use case model; generate a corresponding pending test case code script according to the pending use case model; and when the test result after testing the historical scenario through the pending test case code script meets the preset result, determine the pending use case model as a candidate use case model corresponding to the historical scenario; By using the target object feature information, a target use case model corresponding to the target test object is matched among all candidate use case models, wherein the matching degree between the target model feature information of the target use case model and the target object feature information meets a preset requirement, and the target model feature information includes at least one target model feature; A target test case for testing the target test object is generated according to the target use case model.
2. The method according to claim 1, characterized in that: The step of obtaining target object feature information of the target test object comprises: Determine at least one interface to be tested included in the target test object; The target object feature information of the target test object is obtained by acquiring all target interface features of each of the interfaces to be tested.
3. The method according to claim 2, characterized in that The target keyword information extracted from the historical test case code script includes: Extract keywords from the historical test case code script to obtain candidate keywords; Among all the candidate keywords, the target keyword information that meets the preset requirements is selected.
4. The method according to claim 3, characterized in that After extracting keywords from the historical test case code script to obtain candidate keyword information, the method further includes: According to the function of each of the candidate interfaces, the candidate keyword information is clustered to obtain a candidate keyword set corresponding to each of the functions, wherein each of the candidate keyword sets includes at least one candidate keyword.
5. The method according to claim 3, characterized in that: The target keyword information that meets the preset requirements is selected from all the candidate keywords and includes: According to a preset weighting scheme, based on the weight of each candidate keyword and the number of repetitions of each candidate keyword in all the candidate keywords, a weighted value of each candidate keyword is determined; After removing duplicates from all the candidate keywords, the keywords after removing duplicates are obtained; According to the weighted value of each of the deduplicated keywords, the target keyword information is determined among all the deduplicated keywords, wherein the weighted value of the target keyword information is higher than the weighted values of other deduplicated keywords.
6. The method according to claim 1, characterized in that Also includes: Determine a target test framework corresponding to the target scenario according to the business feature information of the business corresponding to the target scenario; Generate a test case template and a data template that are adapted to the target test framework and correspond to the target interface according to the target interface required by the target scenario; According to the test case template and the data template corresponding to the target interface, a candidate test case of the target interface corresponding to the target scenario is generated.
7. The method according to claim 1, characterized in that The step of matching a target use case model corresponding to the target test object from among all candidate use case models by using the target object feature information includes: Acquire candidate model feature information of the candidate use case model, wherein there is a one-to-one correspondence between the candidate use case model and the candidate model feature information, and the candidate model feature information includes at least one candidate model feature; Obtaining the degree of match between the candidate model feature information and the target object feature information by determining the number of the candidate model features, among all the candidate model features, that are the same as any one of the target object features among all the target object features; When the matching degree meets the preset requirement, the candidate use case model corresponding to the matching degree is used as the target use case model.
8. The method according to claim 1, characterized in that: Generating a target test case for testing the target test object according to the target use case model comprises: Generating a test case combination corresponding to the target test object according to the target use case model, wherein the test case combination includes a test case corresponding to each interface in the target test object; The test case combination is integrated into the test framework corresponding to the target use case model to obtain the target test case for testing the target test object.
9. A test case generation device, characterized in that: include: A determination module, used to determine a target test object to be tested; An acquisition module, configured to acquire target object feature information of the target test object, wherein the target object feature information includes at least one target object feature; It also includes a module for obtaining a historical test case code script corresponding to a historical scenario, wherein the historical test case code script includes at least one historical test case, and the historical test case corresponds one-to-one to a candidate interface in the historical scenario; extracting target keyword information from the historical test case code script; inputting the target keyword information into a target neural network to predict the predicted test cases and predicted usage information required for use in the historical scenario, wherein the predicted usage information is used to indicate the combination relationship of each of the predicted test cases; matching each of the predicted test cases in the historical test case code script according to the target keyword information; combining the predicted test cases according to the predicted usage information to obtain a pending use case model; generating a corresponding pending test case code script according to the pending use case model; and determining the pending use case model as a candidate use case model corresponding to the historical scenario when the test result after testing the historical scenario through the pending test case code script meets the preset result; A matching module, configured to match a target use case model corresponding to the target test object from among all candidate use case models through the target object feature information, wherein the matching degree between the target model feature information of the target use case model and the target object feature information meets a preset requirement, and the target model feature information includes at least one target model feature; A generating module is used to generate a target test case for testing the target test object according to the target test case model.
10. An electronic device, characterized in that: include: A processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; The memory is used to store computer programs; The processor is used to implement the method according to any one of claims 1 to 8 when executing the computer program.
11. A computer-readable storage medium, characterized in that: The storage medium includes a stored program, wherein the program executes the method according to any one of claims 1 to 8 when executed.
Citation Information
Patent Citations
Method and device for generating test cases
CN107908548A