A test method and device based on decision tree
Through the decision tree-based testing method, the test table is generated and the interval of path value is determined, the problem of missing test scenarios or combination points in the existing technology is solved, and the full coverage automation testing of complex business processes is realized, which improves the testing efficiency and accuracy.
Patent Information
- Application Number
- CN201810954871.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2018-08-21
- Publication Date
- 2025-01-14
- Estimated Expiration
- 2038-08-21
AI Technical Summary
The prior art may miss some test scenarios or combination points in functional testing, especially in complex business processes, where the desired results of maintaining test cases are complex, resulting in unrelated variables being under-tested.
采用基于决策树的测试方法,通过构建决策树,生成测试表,确定路径值的区间,并以目标路径值作为入参值,完成自动化测试,匹配全组合数据表以获取期望结果,确保测试结果的准确性。
Improve testing efficiency, ensure full coverage of business processes, avoid the omission of test scenarios or combination points, and enhance the comprehensiveness and accuracy of testing.
Smart Images

Figure CN110851343B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a testing method and device based on a decision tree. Background Art
[0002] With the rapid development of business, new challenges have been posed to traditional functional testing methods and means. Especially for process-based applications, the theoretical ideas of test case design are adopted, and effective test cases are designed using the cause-effect diagram method, on which the automated testing of the test cases is performed.
[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:
[0004] The cause-and-effect diagram method takes into account the logic provided by the business. If it is used simply in functional testing, some test scenarios or combination points may be missed, resulting in a variable not actually affecting the result, and this irrelevance (that is, the variable has no effect on the result) is not tested. In addition, for complex business processes, it is also relatively complicated to maintain the expected results corresponding to the test cases. Summary of the invention
[0005] In view of this, an embodiment of the present invention provides a test method and device based on a decision tree to solve the technical problem that some test scenarios or combination points may be missed.
[0006] To achieve the above object, according to one aspect of an embodiment of the present invention, a decision tree-based testing method is provided, comprising:
[0007] Construct a decision tree based on the decision tree algorithm and write test cases based on the decision tree;
[0008] Read each path in the decision tree and generate a test table to determine the interval of the path value;
[0009] Select a target path value from the interval of the path value, use the target path value as an input parameter value, and splice it into the test case;
[0010] Execute the spliced test cases and get the test results.
[0011] Optionally, reading each path in the decision tree and generating a test table to determine the interval of the path value includes:
[0012] Read each path in the decision tree to generate a test table, wherein each row of data in the test table records each node of a path in the decision tree;
[0013] Filling the elements in each row of data in the test table to obtain a full combination data table;
[0014] According to the order of each node in the path, the elements in each row of data in the full combination data table are sequentially spliced to determine the interval of the path value.
[0015] Optionally, the elements in each row of data in the full combination data table are sequentially concatenated according to the order of each node in the path, so as to determine the interval of the path value, including:
[0016] Converting the elements in each row of data in the full combination data table into a binary string;
[0017] According to the order of each node in the path, the elements in each row of data in the full combination data table are sequentially concatenated to obtain a binary string corresponding to each row of data;
[0018] Convert the binary string corresponding to each row of data into an int value to determine the interval of the path value.
[0019] Optionally, selecting a target path value from the interval of the path value, taking the target path value as an input parameter value, and splicing it into the test case includes:
[0020] Select a target path value from the interval of the path value, and convert the target path value into a binary string;
[0021] Take the binary string as the input parameter and splice it into the test case.
[0022] Optionally, the binary string is used as an input parameter value and is concatenated into a test case, including:
[0023] Taking the binary string as an input parameter value, splitting the binary string into binary strings corresponding to each node;
[0024] According to the order of each node in the path, concatenate the binary strings corresponding to each node into the test case.
[0025] Optionally, the method further comprises:
[0026] Using the target path value to match the full combination data table to obtain the expected result;
[0027] Whether the test passes is determined by judging whether the expected result and the test structure are the same.
[0028] In addition, according to another aspect of an embodiment of the present invention, a decision tree-based testing device is provided, comprising:
[0029] A building module, used for building a decision tree based on a decision tree algorithm, and writing test cases according to the decision tree;
[0030] A reading module, used to read each path in the decision tree and generate a test table to determine the interval of the path value;
[0031] A splicing module, used for selecting a target path value from the interval of the path value, taking the target path value as an input parameter value, and splicing it into the test case;
[0032] The test module is used to execute the spliced test cases and obtain the test results.
[0033] Optionally, the reading module is used to:
[0034] Read each path in the decision tree to generate a test table, wherein each row of data in the test table records each node of a path in the decision tree;
[0035] Filling the elements in each row of data in the test table to obtain a full combination data table;
[0036] According to the order of each node in the path, the elements in each row of data in the full combination data table are sequentially spliced to determine the interval of the path value.
[0037] Optionally, the elements in each row of data in the full combination data table are sequentially concatenated according to the order of each node in the path, so as to determine the interval of the path value, including:
[0038] Converting the elements in each row of data in the full combination data table into a binary string;
[0039] According to the order of each node in the path, the elements in each row of data in the full combination data table are sequentially concatenated to obtain a binary string corresponding to each row of data;
[0040] Convert the binary string corresponding to each row of data into an int value to determine the interval of the path value.
[0041] Optionally, the splicing module is used for:
[0042] Select a target path value from the interval of the path value, and convert the target path value into a binary string;
[0043] Take the binary string as the input parameter and splice it into the test case.
[0044] Optionally, the binary string is used as an input parameter value and is concatenated into a test case, including:
[0045] Taking the binary string as an input parameter value, splitting the binary string into binary strings corresponding to each node;
[0046] According to the order of each node in the path, concatenate the binary strings corresponding to each node into the test case.
[0047] Optionally, the test module is further used to:
[0048] Using the target path value to match the full combination data table to obtain the expected result;
[0049] Whether the test passes is determined by judging whether the expected result and the test structure are the same.
[0050] According to another aspect of an embodiment of the present invention, there is further provided an electronic device, including:
[0051] one or more processors;
[0052] a storage device for storing one or more programs,
[0053] When the one or more programs are executed by the one or more processors, the one or more processors implement the method described in any of the above embodiments.
[0054] According to another aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored. When the program is executed by a processor, the method described in any one of the above embodiments is implemented.
[0055] One embodiment of the above invention has the following advantages or beneficial effects: because of the technical means of reading each path in the decision tree, generating a test table, determining the interval of the path value, and using the target path value in the interval as the input parameter value, the technical problem that some test scenarios or combination points may be missed is overcome. The present invention utilizes the idea of a decision tree, generates a test table based on the decision tree, obtains the interval of the path value through full coverage permutations and combinations of each element in the test table, and then uses the path value as the input parameter value to complete the automated test and obtain the test result. Finally, the path value is used to match the full combination data table to obtain the expected result, and the test result is compared to see if it is the same as the expected result, thereby performing a fully covered automated test on the business process, improving the test efficiency, and avoiding problems with some test scenarios or combination points.
[0056] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0058] Figure 1is a schematic diagram of the main process of a decision tree-based testing method according to an embodiment of the present invention;
[0059] Figure 2 is a schematic diagram of a decision tree structure according to an embodiment of the present invention;
[0060] Figure 3 is a schematic diagram of the main process of a decision tree-based testing method according to a reference embodiment of the present invention;
[0061] Figure 4 is a schematic diagram of main modules of a decision tree-based testing device according to an embodiment of the present invention;
[0062] Figure 5 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0063] Figure 6 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0064] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0065] Figure 1 Schematic diagram of the main process of the decision tree-based testing method according to an embodiment of the present invention. Figure 1 As shown, the decision tree-based testing method may include:
[0066] Step 101, construct a decision tree based on a decision tree algorithm, and write test cases according to the decision tree.
[0067] First, build a decision tree based on the decision tree algorithm and historical data; then, write test cases based on each path in the decision tree and each node in the path.
[0068] A decision tree is a tree structure in which each internal node represents a judgment on an attribute, each branch represents the output of a judgment result, and each leaf node represents a classification result.
[0069] like Figure 2As shown in the figure, taking the six features of "whether it is a gift", "whether it is a new product", "whether the warehouse quotation is 0", "whether it is an import type", "whether there is a return policy (RMA)", and "whether there are other (such as residual value)" as examples, the corresponding decision tree is constructed. The nodes other than the leaf nodes in the decision tree represent each feature, and the leaf nodes represent the output results, such as "new product", "return policy", "import type", "other", and "no matching items". Therefore, the corresponding results can be obtained by traversing the paths in the decision tree.
[0070] Then, based on the above six features, a feature class is established with corresponding feature method judgments to obtain the input parameter values corresponding to each feature, as shown below, which is used to input the input parameter values corresponding to each feature.
[0071] class FEATUREFORCANZHI()
[0072] def_init_(self, data):
[0073] def zpValue(self):
[0074] def xpValue(self):
[0075] def cbjValue(self):
[0076] def rkValue(self):
[0077] def rmaValue(self):
[0078] def elseValue(self):
[0079] The test results are obtained by calling six methods, namely "New Product", "With Return and Exchange Policy", "Import Category", "With Others" and "No Match". Figure 2 The decision tree shown has five result categories, namely new products, imports, return and exchange policy, other, and no matching items. There is a method in each category to obtain the specific result information corresponding to the category.
[0080] Step 102, read each path in the decision tree, generate a test table, and thus determine the interval of the path value.
[0081] In this step, each path in the decision tree created in step 101 is first read to generate a test table, in which each row of data in the test table records each node of a path in the decision tree; then the elements in each row of data in the test table are filled to obtain a full combination data table; finally, the elements in each row of data in the full combination data table are sequentially spliced according to the order of each node in the path, so as to determine the interval of the path value.
[0082] Optionally, the elements in each row of data in the full combination data table are concatenated in sequence according to the order of each node in the path to determine the interval of the path value, including: converting the elements in each row of data in the full combination data table into a binary string; concatenating the elements in each row of data in the full combination data table in sequence according to the order of each node in the path to obtain the binary string corresponding to each row of data; converting the binary string corresponding to each row of data into an int value respectively to determine the interval of the path value.
[0083] Still Figure 2 Take the decision tree shown as an example to illustrate:
[0084] 1) Read Figure 2 Each path in the decision tree shown (from the root node to the leaf node) automatically fills in the CSV (Comma-Separated Values) file. If the corresponding feature is "yes", fill in "1" under the corresponding feature. If the corresponding feature is "no", fill in "0" under the corresponding feature, thereby generating the following test table:
[0085]
[0086] In this test table, each row of data corresponds to the nodes of a path in the decision tree. For example, the first row records line1 = ['1'",'1'",",",], which corresponds to the path of "it is a gift - the warehouse quotation is 0 - the result is a new product". The second row records line2 = ['1'",'0','1','1'",], which corresponds to the path of "it is a gift - the warehouse quotation is not 0 - it is an entry type - there is RMA - the result is RMA".
[0087] 2) Fill the elements in each row of data in the test table to obtain a full combination data table.
[0088] Take the first line record line1 = ['1'",'1'",",",] as an example, first convert each element in the first line into a binary string and fill it. If the element is 1, fill it with [1,1]; if the element is 0, fill it with [0,0]; if the element is empty, fill it with [0,1]. Then, according to the order of each node in the path (that is, the order of each feature in the test table from left to right), all combinations of each element in line1 are arranged.
[0089] Take "1" from [1,1], take "0" from [0,0], take "0" or "1" from [0,1], perform full combination permutations on each element in line1 in turn, and then remove the repeated permutations to obtain the following full combination permutation data set:
[0090] 1 0 1 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 1 0 1 0 0 0 1 1 1 0 0 0 1 0 1 1 1 0 1 0 1 1 0 0 1 0 1 1 1 1 1 1 1 0 1 1 1 0 1 0 1 0 1 0 1 1 0 1 1 1 1 0 1 1 1 0 1 0 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0 1 0
[0091] Then, each element in each row of data after the full combination is concatenated in turn, that is, the elements in the combination are ordered to form a binary string. Finally, the binary string is converted into an int value to obtain the path value corresponding to line1, that is, [41,63,60,40,56,46,44,47,57,42,45,59,43,62,61,58] and the corresponding result is "new product".
[0092] Similarly, the second row of records line2 = ['1',",'0','1','1',"], the third row of records, the fourth row of records, etc. are processed in the same way to obtain a full combination data table, and then the elements in each row of data in the full combination data table are concatenated and converted, and finally the path value interval is determined to be [0,63].
[0093] Because the position of an empty string is uncertain, it is inconvenient to perform permutation and combination if it is not filled. Therefore, the embodiment of the present invention improves the convenience of combination by first filling and then performing full combination and permutation on each element.
[0094] Step 103, selecting a target path value from the interval of the path value, taking the target path value as an input parameter value, and splicing it into the test case.
[0095] Select any path value from the interval of path values determined in step 102 as the target path value, convert it into a binary string, and then use the binary string as the input parameter value to splice it into the test case in step 101. Convert the path value into a binary string, combine the judgment logic of the feature, select the specific value corresponding to each feature, and complete the splicing of the input parameter value.
[0096] As another embodiment of the present invention, the binary string is used as an input parameter value and is spliced into a test case, including: using the binary string as an input parameter value, splitting the binary string into binary strings corresponding to each node; and splicing the binary strings corresponding to each node into the test case according to the order of each node in the path. That is, the features are spliced to complete the assembly of the test input parameter.
[0097] For example, in the above example, there are six features, that is, at most 2 6 = 64 combinations, and accordingly, the input parameter value is a path value in the interval [0,63]. When the logic test of the service is required, only an input parameter value enumeration needs to be input to automatically complete the test.
[0098] Step 104, execute the spliced test cases to obtain test results.
[0099] On the basis of step 103, the spliced test cases are executed to obtain test results.
[0100] For example, if the path value interval is [0,63], when the input is 0, we get an input parameter object that is not a gift, not a new product, warehouse quotation, not 0, not an entry type, not RMA, and has no other logic. We use this input parameter object to call the test case and get the test result of the actual call.
[0101] In yet another embodiment of the present invention, the method further includes: using the target path value to match the full combination data table to obtain an expected result; and determining whether the test passes by judging whether the expected result is the same as the test structure.
[0102] Still taking the input parameter value 0 as an example, use the input parameter value 0 to match the full combination data table, obtain the expected result of "none", verify the actual test result and the expected result, and obtain the test result of the path. If the test result is the same as the expected result, the test passes; if the test result is different from the expected result, the test fails.
[0103] According to the various embodiments described above, it can be seen that the present invention adopts a technical means of reading each path in the decision tree, generating a test table, determining the interval of the path value, and using the target path value in the interval as the input parameter value, thereby solving the problem that some test scenarios or combination points may be missed. In other words, the prior art may miss some test scenarios or combination points. The present invention uses the idea of a decision tree to generate a test table based on the decision tree, obtains the interval of the path value through the full coverage arrangement and combination of each element in the test table, and then uses the path value as the input parameter value to complete the automated test and obtain the test result. Finally, the path value is used to match the full combination data table to obtain the expected result, and the test result is compared to see if it is the same as the expected result, thereby performing a fully covered automated test on the business process, improving the test efficiency, and avoiding the problem of some test scenarios or combination points.
[0104] Figure 3 : is a schematic diagram of the main process of a decision tree-based testing method according to a reference embodiment of the present invention. The decision tree-based testing method may include:
[0105] Step 301, constructing a decision tree based on a decision tree algorithm, and writing test cases according to the decision tree;
[0106] Step 302, reading each path in the decision tree and generating a test table, wherein each row of data in the test table records each node of a path in the decision tree;
[0107] Step 303, filling the elements in each row of data in the test table to obtain a full combination data table;
[0108] Step 304, converting the elements in each row of data in the full combination data table into a binary string;
[0109] Step 305, sequentially concatenating the elements in each row of data in the full combination data table according to the order of each node in the path, thereby obtaining a binary string corresponding to each row of data;
[0110] Step 306, convert the binary string corresponding to each row of data into an int value, so as to determine the interval of the path value;
[0111] Step 307, selecting a target path value from the interval of the path value, and converting the target path value into a binary string;
[0112] Step 308, using the binary string as an input parameter value, splitting the binary string into binary strings corresponding to each node;
[0113] Step 309, according to the order of each node in the path, concatenate the binary string corresponding to each node into the test case;
[0114] Step 310, executing the spliced test cases to obtain test results;
[0115] Step 311, using the target path value to match the full combination data table to obtain the expected result;
[0116] Step 312, determining whether the test passes by judging whether the expected result and the test structure are the same.
[0117] In addition, the specific implementation content of the decision tree-based testing method in a reference embodiment of the present invention has been described in detail in the decision tree-based testing method described above, so the repeated content will not be described here.
[0118] Figure 4 is a schematic diagram of the main modules of the decision tree-based testing device according to an embodiment of the present invention, such as Figure 4 As shown, the test device 400 based on the decision tree includes a construction module 401, a reading module 402, a splicing module 403 and a testing module 404. The construction module 401 constructs a decision tree based on a decision tree algorithm, and writes a test case according to the decision tree; the reading module 402 reads each path in the decision tree, generates a test table, and thus determines the interval of the path value; the splicing module 403 selects a target path value from the interval of the path value, takes the target path value as an input parameter value, and splices it into the test case; the testing module 404 executes the spliced test case to obtain the test result.
[0119] Optionally, the reading module 402 also reads each path in the decision tree and generates a test table, in which each row of data in the test table records each node of a path in the decision tree; fills the elements in each row of data in the test table to obtain a full combination data table; and sequentially splices the elements in each row of data in the full combination data table according to the order of each node in the path, thereby determining the interval of the path value.
[0120] Optionally, the elements in each row of data in the full combination data table are concatenated in sequence according to the order of each node in the path to determine the interval of the path value, including: converting the elements in each row of data in the full combination data table into a binary string; concatenating the elements in each row of data in the full combination data table in sequence according to the order of each node in the path to obtain the binary string corresponding to each row of data; converting the binary string corresponding to each row of data into an int value respectively to determine the interval of the path value.
[0121] Optionally, the splicing module 403 further selects a target path value from the interval of the path value, converts the target path value into a binary string, and uses the binary string as an input parameter value to splice it into the test case.
[0122] Optionally, the binary string is used as an input parameter value and spliced into a test case, including: using the binary string as an input parameter value, splitting the binary string into binary strings corresponding to each node; and splicing the binary strings corresponding to each node into the test case according to the order of each node in the path.
[0123] Optionally, the test module 404 further uses the target path value to match the full combination data table to obtain an expected result; and determines whether the test passes by judging whether the expected result and the test structure are the same.
[0124] According to the various embodiments described above, it can be seen that the present invention adopts a technical means of reading each path in the decision tree, generating a test table, determining the interval of the path value, and using the target path value in the interval as the input parameter value, thereby solving the problem that some test scenarios or combination points may be missed. In other words, the prior art may miss some test scenarios or combination points. The present invention uses the idea of a decision tree to generate a test table based on the decision tree, obtains the interval of the path value through the full coverage arrangement and combination of each element in the test table, and then uses the path value as the input parameter value to complete the automated test and obtain the test result. Finally, the path value is used to match the full combination data table to obtain the expected result, and the test result is compared to see if it is the same as the expected result, thereby performing a fully covered automated test on the business process, improving the test efficiency, and avoiding the problem of some test scenarios or combination points.
[0125] It should be noted that the specific implementation content of the decision tree-based testing device of the present invention has been described in detail in the above-mentioned decision tree-based testing method, so the repeated content will not be described again here.
[0126] Figure 5 An exemplary system architecture 500 is shown to which a decision tree-based testing method or a decision tree-based testing device according to an embodiment of the present invention can be applied.
[0127] like Figure 5 As shown, system architecture 500 may include terminal devices 501, 502, 503, a network 504 and a server 505. Network 504 is used to provide a medium for communication links between terminal devices 501, 502, 503 and server 505. Network 504 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0128] Users can use terminal devices 501, 502, 503 to interact with server 505 through network 504 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 501, 502, 503, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only as examples).
[0129] The terminal devices 501 , 502 , and 503 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.
[0130] The server 505 may be a server that provides various services, such as a backend management server (only an example) that provides support for shopping websites browsed by users using the terminal devices 501, 502, and 503. The backend management server may analyze and process the received data such as product information query requests, and feed back the processing results (such as target push information, product information - only an example) to the terminal device.
[0131] It should be noted that the decision tree-based testing method provided in the embodiment of the present invention can be executed on the server 505, or on the terminal devices 501, 502, 503. Accordingly, the decision tree-based testing device can be set in the server 505, or in the terminal devices 501, 502, 503.
[0132] It should be understood that Figure 5 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0133] Reference below Figure 6 , which shows a schematic diagram of the structure of a computer system 600 of a terminal device suitable for implementing an embodiment of the present invention. Figure 6 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0134] like Figure 6 As shown, the computer system 600 includes a central processing unit (CPU) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage part 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the system 600 are also stored. The CPU 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0135] The following components are connected to the I / O interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, a modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I / O interface 605 as needed. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 610 as needed, so that a computer program read therefrom is installed into the storage section 608 as needed.
[0136] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 609, and / or installed from the removable medium 611. When the computer program is executed by the central processing unit (CPU) 601, the above-mentioned functions defined in the system of the present invention are executed.
[0137] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may 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, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may 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 may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0138] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0139] The modules involved in the embodiments of the present invention may be implemented by software or hardware. The modules described may also be set in a processor, for example, it may be described as: a processor includes a construction module, a reading module, a splicing module and a testing module, wherein the names of these modules do not constitute a limitation on the modules themselves in some cases.
[0140] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes: building a decision tree based on a decision tree algorithm, and writing test cases according to the decision tree; reading each path in the decision tree, generating a test table, and thus determining the interval of the path value; selecting a target path value from the interval of the path value, using the target path value as an input parameter value, and splicing it into the test case; executing the spliced test case to obtain the test result.
[0141] According to the technical solution of the embodiment of the present invention, because the technical means of reading each path in the decision tree, generating a test table, determining the interval of the path value, and using the target path value in the interval as the input parameter value is adopted, the technical problem that some test scenarios or combination points may be missed is overcome. The present invention utilizes the idea of a decision tree, generates a test table based on the decision tree, obtains the interval of the path value through full coverage permutations and combinations of each element in the test table, and then uses the path value as the input parameter value to complete the automated test and obtain the test result. Finally, the path value is used to match the full combination data table to obtain the expected result, and the test result is compared to see if it is the same as the expected result, thereby performing a fully covered automated test on the business process, improving the test efficiency, and avoiding problems with some test scenarios or combination points.
[0142] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A testing method based on a decision tree, characterized in that: include: Construct a decision tree based on the decision tree algorithm and write test cases based on the decision tree; Read each path in the decision tree and generate a test table to determine the interval of the path value; Select a target path value from the interval of the path value, use the target path value as an input parameter value, and splice it into the test case; Execute the spliced test cases and get the test results; Read each path in the decision tree and generate a test table to determine the interval of the path value, including: Read each path in the decision tree to generate a test table, wherein each row of data in the test table records each node of a path in the decision tree; Filling the elements in each row of data in the test table to obtain a full combination data table; According to the order of each node in the path, the elements in each row of data in the full combination data table are sequentially spliced to determine the interval of the path value.
2. The method according to claim 1, characterized in that According to the order of each node in the path, the elements in each row of data in the full combination data table are sequentially spliced to determine the interval of the path value, including: Converting the elements in each row of data in the full combination data table into a binary string; According to the order of each node in the path, the elements in each row of data in the full combination data table are sequentially concatenated to obtain a binary string corresponding to each row of data; Convert the binary string corresponding to each row of data into an int value to determine the interval of the path value.
3. The method according to claim 1, characterized in that Selecting a target path value from the interval of the path value, taking the target path value as an input parameter value, and splicing it into the test case includes: Select a target path value from the interval of the path value, and convert the target path value into a binary string; Take the binary string as the input parameter and splice it into the test case.
4. The method according to claim 3, characterized in that Take the binary string as the input parameter and splice it into the test case, including: Taking the binary string as an input parameter value, splitting the binary string into binary strings corresponding to each node; According to the order of each node in the path, concatenate the binary strings corresponding to each node into the test case.
5. The method according to claim 1, characterized in that Also includes: Using the target path value to match the full combination data table to obtain the expected result; Whether the test passes is determined by judging whether the expected result and the test structure are the same.
6. A test device based on a decision tree, characterized in that: include: A building module, used for building a decision tree based on a decision tree algorithm, and writing test cases according to the decision tree; A reading module, used to read each path in the decision tree and generate a test table to determine the interval of the path value; A splicing module, used for selecting a target path value from the interval of the path value, taking the target path value as an input parameter value, and splicing it into the test case; The test module is used to execute the spliced test cases and obtain the test results; The reading module is used for: Read each path in the decision tree to generate a test table, wherein each row of data in the test table records each node of a path in the decision tree; Filling the elements in each row of data in the test table to obtain a full combination data table; According to the order of each node in the path, the elements in each row of data in the full combination data table are sequentially spliced to determine the interval of the path value.
7. The device according to claim 6, characterized in that According to the order of each node in the path, the elements in each row of data in the full combination data table are sequentially spliced to determine the interval of the path value, including: Converting the elements in each row of data in the full combination data table into a binary string; According to the order of each node in the path, the elements in each row of data in the full combination data table are sequentially concatenated to obtain a binary string corresponding to each row of data; Convert the binary string corresponding to each row of data into an int value to determine the interval of the path value.
8. The device according to claim 6, characterized in that The splicing module is used for: Select a target path value from the interval of the path value, and convert the target path value into a binary string; Take the binary string as the input parameter and splice it into the test case.
9. The device according to claim 8, characterized in that Take the binary string as the input parameter and splice it into the test case, including: Taking the binary string as an input parameter value, splitting the binary string into binary strings corresponding to each node; According to the order of each node in the path, concatenate the binary strings corresponding to each node into the test case.
10. The device according to claim 6, characterized in that The test module is also used to: Using the target path value to match the full combination data table to obtain the expected result; Whether the test passes is determined by judging whether the expected result and the test structure are the same.
11. An electronic device, characterized in that: include: 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 to 5.
12. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Decision-making tree based prediction method and device
CN104111920A
Method and apparatus for generating test case of webpage
CN106294107A