[go: up one dir, main page]

CN114265772B - Test case generation method and test method - Google Patents

Test case generation method and test method Download PDF

Info

Publication number
CN114265772B
CN114265772B CN202111548993.2A CN202111548993A CN114265772B CN 114265772 B CN114265772 B CN 114265772B CN 202111548993 A CN202111548993 A CN 202111548993A CN 114265772 B CN114265772 B CN 114265772B
Authority
CN
China
Prior art keywords
semantic
test
case
alternative
test object
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202111548993.2A
Other languages
Chinese (zh)
Other versions
CN114265772A (en
Inventor
张云海
周振
杜平心
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Nsfocus Technologies Inc
Nsfocus Technologies Group Co Ltd
Original Assignee
Nsfocus Technologies Inc
Nsfocus Technologies Group Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Nsfocus Technologies Inc, Nsfocus Technologies Group Co Ltd filed Critical Nsfocus Technologies Inc
Priority to CN202111548993.2A priority Critical patent/CN114265772B/en
Publication of CN114265772A publication Critical patent/CN114265772A/en
Application granted granted Critical
Publication of CN114265772B publication Critical patent/CN114265772B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The application discloses a test case generation method and a test method, which belong to the technical field of tests, wherein the test case generation method comprises the following steps: performing deformation processing on the test cases in the obtained test case set to obtain alternative cases, performing semantic coding on the just-in-time compiling class codes in the alternative cases to obtain semantic coding results of the alternative cases, determining whether the alternative cases can increase the semantic coverage of the test object based on the semantic coding results of the alternative cases, wherein the semantic coverage is used for representing the sufficiency of the semantic test of the test object, and adding the alternative cases into the test case set to update the test case set if the alternative cases can increase the semantic coverage of the test object. Therefore, the test condition of the just-in-time compiling class code can be well measured, the generation quality of the test case is improved, and the test sufficiency and the test efficiency are improved.

Description

Test case generation method and test method
Technical Field
The present application relates to the field of testing technologies, and in particular, to a method for generating a test case and a test method.
Background
In the software development process, testing is a very important link, and an important evaluation index of testing is testing efficiency.
In order to improve the test efficiency, a feedback test case generation method based on code coverage appears in the related art, in the method, the test case is evaluated by the code coverage (or code coverage proportion), and the generation of the subsequent test case is guided based on the evaluation result. However, the inventor finds that the just-in-time compiling class code is compiled in the program executing process (i.e. the running period), rather than before executing, and executing the just-in-time compiling class code does not increase the code coverage rate, so the method can reduce or even avoid generating test cases for testing the just-in-time compiling class code. Therefore, the generation mode of the test case is not reasonable, and is not beneficial to fully testing the test object and improving the test efficiency.
Disclosure of Invention
The embodiment of the application provides a test case generation method and a test method, which are used for solving the problems of insufficient test and low test efficiency caused by unreasonable test case generation mode in the related technology.
In a first aspect, an embodiment of the present application provides a method for generating a test case, including:
Performing deformation processing on the test cases in the obtained test case set to obtain alternative cases;
Carrying out semantic coding on the just-in-time compiling class code in the alternative use case to obtain a semantic coding result of the alternative use case;
determining whether the alternative use case can increase the semantic coverage of the test object based on the semantic coding result of the alternative use case, wherein the semantic coverage is used for representing the sufficiency of the semantic test of the test object;
and if the alternative case can be determined to increase the semantic coverage of the test object, adding the alternative case into the test case set.
In some embodiments, performing semantic encoding on the just-in-time compiled class code in the alternative use case to obtain a semantic encoding result of the alternative use case, including:
Generating an abstract syntax tree of the alternative case;
determining a target tree corresponding to the just-in-time compiling class code in the abstract syntax tree;
decomposing the target tree according to a rule that the number of nodes contained in each sub tree is not more than N, so as to obtain at least two sub trees, wherein N is an integer greater than 1;
And respectively carrying out semantic coding on the at least two sub-trees to obtain a semantic coding result of the alternative case.
In some embodiments, nodes are shared between different subtrees or are not shared between different subtrees.
In some embodiments, performing semantic coding on the at least two sub-trees to obtain a semantic coding result of the alternative case, where the semantic coding result includes:
carrying out semantic expression on any node in each subtree according to node information of the node, wherein the node information comprises node names, node types and position information of the node in the subtree;
combining semantic expression results of all nodes to obtain semantic coding results of the subtrees;
and taking the semantic coding result of each subtree as the semantic coding result of the alternative case.
In some embodiments, determining whether the alternative case can increase semantic coverage of the test object based on the semantic encoding result of the alternative case includes:
Compressing the semantic coding result of each subtree to obtain a coding factor;
Querying element values corresponding to the subtrees from a semantic array by taking the coding factors as indexes, wherein each element in the semantic array corresponds to a class of codes of the test object, and the element values of the elements are used for indicating whether test cases can test the class of codes;
and determining whether the alternative use cases can increase the semantic coverage of the test object based on the element values corresponding to the subtrees.
In some embodiments, determining whether the candidate case can increase semantic coverage of the test object based on the element values corresponding to the subtrees includes:
If the element value corresponding to any subtree indicates that no test case can test the corresponding class code of the test object, determining that the alternative case can increase the semantic coverage of the test object, and updating the element value to indicate that the existing test case can test the corresponding class code;
If the element value corresponding to each sub tree indicates that the existing test case can test the corresponding class code, determining that the alternative case cannot increase the semantic coverage of the test object.
In some embodiments, further comprising:
And discarding the alternative case if the alternative case is determined to not increase the semantic coverage of the test object.
In a second aspect, an embodiment of the present application provides a testing method, including:
Acquiring a test case set of a test object;
updating the test case set by adopting the generation method of any test case;
And testing the test object by using the updated test case set.
In a third aspect, an embodiment of the present application provides a device for generating a test case, including:
The deformation module is used for carrying out deformation treatment on the test cases in the test case set to obtain alternative cases;
the coding module is used for carrying out semantic coding on the just-in-time compiling class code in the alternative use case to obtain a semantic coding result of the alternative use case;
the determining module is used for determining whether the alternative case can increase the semantic coverage of the test object based on the semantic coding result of the alternative case, wherein the semantic coverage is used for representing the sufficiency of the semantic test of the test object;
and the processing module is used for adding the alternative case into the test case set if the alternative case is determined to increase the semantic coverage of the test object.
In some embodiments, the encoding module is specifically configured to:
Generating an abstract syntax tree of the alternative case;
determining a target tree corresponding to the just-in-time compiling class code in the abstract syntax tree;
decomposing the target tree according to a rule that the number of nodes contained in each sub tree is not more than N, so as to obtain at least two sub trees, wherein N is an integer greater than 1;
And respectively carrying out semantic coding on the at least two sub-trees to obtain a semantic coding result of the alternative case.
In some embodiments, nodes are shared between different subtrees or are not shared between different subtrees.
In some embodiments, the encoding module is specifically configured to:
carrying out semantic expression on any node in each subtree according to node information of the node, wherein the node information comprises node names, node types and position information of the node in the subtree;
combining semantic expression results of all nodes to obtain semantic coding results of the subtrees;
and taking the semantic coding result of each subtree as the semantic coding result of the alternative case.
In some embodiments, the determining module is specifically configured to:
Compressing the semantic coding result of each subtree to obtain a coding factor;
Querying element values corresponding to the subtrees from a semantic array by taking the coding factors as indexes, wherein each element in the semantic array corresponds to a class of codes of the test object, and the element values of the elements are used for indicating whether test cases can test the class of codes;
and determining whether the alternative use cases can increase the semantic coverage of the test object based on the element values corresponding to the subtrees.
In some embodiments, the determining module is specifically configured to:
If the element value corresponding to any subtree indicates that no test case can test the corresponding class code of the test object, determining that the alternative case can increase the semantic coverage of the test object, and updating the element value to indicate that the existing test case can test the corresponding class code;
If the element value corresponding to each sub tree indicates that the existing test case can test the corresponding class code, determining that the alternative case cannot increase the semantic coverage of the test object.
In some embodiments, the processing module is further to:
And discarding the alternative case if the alternative case is determined to not increase the semantic coverage of the test object.
In a fourth aspect, an embodiment of the present application provides a test apparatus, including:
The acquisition module is used for acquiring a test case set of the test object;
the updating module is used for updating the test case set by adopting the test case generation method;
And the test module is used for testing the test object by using the updated test case set.
In a fifth aspect, an embodiment of the present application provides an electronic device, including: at least one processor, and a memory communicatively coupled to the at least one processor, wherein:
The memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of generating any one of the test cases or the method of testing.
In a sixth aspect, an embodiment of the present application provides a storage medium, where when instructions in the storage medium are executed by a processor of an electronic device, the electronic device is capable of executing any one of the above-described test case generation method or the above-described test method.
In the embodiment of the application, the acquired test cases in the test case set are subjected to deformation processing to obtain alternative cases, the instant compiling class codes in the alternative cases are subjected to semantic coding to obtain the semantic coding results of the alternative cases, whether the alternative cases can increase the semantic coverage of the test object or not is determined based on the semantic coding results of the alternative cases, the semantic coverage is used for representing the sufficiency degree of the semantic test of the test object, and if the alternative cases can increase the semantic coverage of the test object, the alternative cases are added into the test case set to update the test case set. In this way, the semantic coding result of the just-in-time compiling class code in the alternative use case obtained by the deformation of the test use case is used for determining whether the alternative use case can increase the semantic coverage of the test object, and updating of the test use case set is guided based on the information of whether the alternative use case can increase the semantic coverage of the test object, so that the test condition of the just-in-time compiling class code can be measured well, the generation quality of the test use case is improved, and the test sufficiency and the test efficiency are improved.
Drawings
The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this specification, illustrate embodiments of the application and together with the description serve to explain the application and do not constitute a limitation on the application. In the drawings:
FIG. 1 is a flowchart of a method for generating test cases according to an embodiment of the present application;
FIG. 2 is a flowchart of semantic encoding of just-in-time compiled class code in an alternative embodiment according to an embodiment of the present application;
FIG. 3 is a flowchart for determining whether an alternative use case can increase the semantic coverage of a test object according to an embodiment of the present application;
FIG. 4 is a schematic diagram of a subtree according to an embodiment of the present application;
FIG. 5 is a schematic diagram of encoding a subtree according to an embodiment of the present application;
FIG. 6 is a schematic diagram of encoding a further sub-tree according to an embodiment of the present application;
FIG. 7 is a schematic diagram of encoding a further sub-tree according to an embodiment of the present application;
FIG. 8 is a flow chart of a testing method according to an embodiment of the present application;
FIG. 9 is a schematic structural diagram of a device for generating test cases according to an embodiment of the present application;
FIG. 10 is a schematic structural diagram of a testing device according to an embodiment of the present application;
Fig. 11 is a schematic diagram of a hardware structure of an electronic device for implementing a method for generating test cases or for implementing a method for testing according to an embodiment of the present application.
Detailed Description
In order to solve the problems of insufficient test and low test efficiency caused by unreasonable generation mode of test cases in the related art, the embodiment of the application provides a test case generation method and a test method.
The preferred embodiments of the present application will be described below with reference to the accompanying drawings of the specification, it being understood that the preferred embodiments described herein are for illustration and explanation only, and not for limitation of the present application, and embodiments of the present application and features of the embodiments may be combined with each other without conflict.
In order to facilitate understanding of the present application, the present application relates to the technical terms:
test cases, a script file for testing.
Class code is compiled just-in-time, code that is compiled during program execution (i.e., run-time).
An abstract syntax tree (Abstract Syntax Tree, AST) is an abstract representation of the source code syntax structure. It represents the syntax structure of a programming language in the form of a tree, each node on the tree representing a structure in the source code.
The test method provided by the embodiment of the application is described below with reference to specific embodiments.
Fig. 1 is a flowchart of a testing method according to an embodiment of the present application, including the following steps.
In step 101, the test cases in the obtained test case set are deformed, so as to obtain alternative cases.
In order to find the test cases capable of increasing the semantic coverage as soon as possible, the generation quality of the test cases is improved, and one test case with the highest semantic coverage can be selected from the test case set for deformation processing.
In the specific implementation, the purpose of the deformation processing is to generate alternative cases different from the test cases, so that the deformation mode capable of achieving the purpose can be considered. The deformation processing is to change a certain variable value in the test case and rewrite a certain code in the test case.
In step 102, the just-in-time compiled class code in the alternative use case is subjected to semantic coding, so that a semantic coding result of the alternative use case is obtained.
In particular, the just-in-time compilation class code in the alternative embodiment may be semantically encoded according to the flow shown in fig. 2, which includes the following steps.
In step 201a, an abstract syntax tree of the alternative is generated.
In step 202a, a target tree corresponding to the just-in-time compiled class code in the abstract syntax tree is determined.
In step 203a, the target tree is decomposed according to a rule that the number of nodes included in each sub tree does not exceed N, so as to obtain at least two sub trees.
Wherein N is an integer greater than 1.
In this way, the target tree is decomposed according to the rule that the number of nodes contained in each sub tree is not more than N, so that the complexity of the target tree can be reduced, and the subsequent coding complexity is reduced.
In addition, the nodes can be shared or not shared among different subtrees, so that the dividing freedom degree of the target tree is conveniently improved, and the complexity of each subtree is further reduced.
In step 204a, the at least two sub-trees are respectively subjected to semantic coding, so as to obtain a semantic coding result of the alternative case.
For example, the semantic coding is performed on the at least two sub-trees according to the following steps to obtain the semantic coding result of the alternative case.
The first step, carrying out semantic expression on any node in each subtree according to node information of the node, wherein the node information comprises node names, node types and position information of the node in the subtree.
And secondly, combining semantic expression results of all nodes in each subtree to obtain a semantic coding result of the subtree.
For example, the semantic expression results of the nodes in each subtree are spliced together according to a certain sequence to be used as the semantic coding results of the subtrees.
And thirdly, taking the semantic coding result of each subtree as the semantic coding result of the alternative case.
In step 103, based on the semantic coding result of the alternative case, it is determined whether the alternative case can increase the semantic coverage of the test object, where the semantic coverage is used to characterize the sufficiency of the semantic test on the test object.
Wherein the test object is a JavaScript engine.
In particular, it may be determined whether the candidate case can increase the semantic coverage of the test object according to the flow shown in fig. 3, where the flow includes the following steps.
In step 301a, the semantic coding result of each subtree is compressed to obtain a coding factor.
Wherein the length of the coding factor is generally fixed.
In step 302a, the element values corresponding to the subtrees are queried from the semantic array by using the coding factors as indexes, each element in the semantic array corresponds to a class code of the test object, and the element values of the elements are used for indicating whether the class code can be tested by the test cases.
In step 303a, it is determined whether the candidate use case can increase the semantic coverage of the test object based on the element values corresponding to the subtrees.
If the element value corresponding to any subtree indicates that no test case can test the corresponding class code of the test object, determining that the alternative case can increase the semantic coverage of the test object; if the element value corresponding to each sub tree indicates that the existing test case can test the corresponding class code, it is determined that the alternative case cannot increase the semantic coverage of the test object.
In step 104, if it is determined that the candidate case can increase the semantic coverage of the test object, the candidate case is added to the test case set.
In this way, the alternative cases are added to the test case set as new test cases to update the test case set.
In step 105, if it is determined that the alternative case cannot increase the semantic coverage of the test object, the alternative case is discarded.
The test case generation method of the embodiment of the application is described below by taking a test object as a JavaScript engine as an example.
In specific implementation, a new test case can be generated as follows.
Step 1, selecting a test case input. Js from the current test case set of the JavaScript engine.
And 2, performing deformation processing on the input. Js to generate a new test case new.
Generally, when the JavaScript engine is subjected to the fuzzing test, the generation of test cases is relatively random, so that the morphing process performed on input.
And 3, performing lexical analysis and grammar analysis on the new.js to generate an abstract grammar tree of the new.js.
Step 4, identifying the part of the abstract syntax tree that is to be dynamically compiled Just In Time (JIT).
And 5, decomposing the JIT dynamic compiling part into a plurality of subtrees with the node number not exceeding N, wherein the subtrees can be overlapped nodes.
And 6, carrying out semantic coding on each sub tree.
Fig. 4 is a schematic structural diagram of a subtree according to an embodiment of the present application.
For example, the subtrees are semantically encoded according to the following steps:
Step 6-1, normalize the name of the identification node (Identifier) in the abstract syntax tree, and the rule is as follows:
And the variable names are numbered according to the sequence of appearance by taking var as a prefix. For example, idx is renamed var_000, float_array is renamed var_001, and so on.
And customizing the function name, taking fun as a prefix, and numbering according to the sequence of appearance. For example, cb is renamed here to fun_001, and so on.
Built-in function names rename according to the pattern of "object type_function name". For example, the built-in function map is renamed array_map.
After step 6-1, the subtree shown in FIG. 4 is as shown in FIG. 5.
Step 6-2, normalizing the Literal quantity node (Liter) name in the abstract syntax tree according to the following rules:
the values are divided into the following categories: 0.1, -1, maximum, negative maximum, sign value, small positive number, small negative number, medium positive number, medium negative number, large positive number, large negative number, named by category.
Character strings are divided into the following categories: the blank string, the keyword string, the short string, the medium string, and the long string are named by category.
After step 6-2, the subtree shown in FIG. 5 is as shown in FIG. 6.
And 6-3, carrying out semantic coding on each node in the abstract syntax tree, wherein the coding consists of a type number and a sequence number.
The types include: a Statement (Statement), an Expression (Expression), an Operator (Operator), a variable (var), a function (fun), a numerical value (num), a character string, and the like are encoded in order, wherein a Statement such as if … else judgment, a for loop, and the like, an Expression such as variable assignment, an Operator such as = =, = and the like are declared.
The named node obtains a sequence number from its name.
The unnamed node obtains a sequence number according to the similar node enumeration order.
After step 6-3, the subtree shown in FIG. 6 is as shown in FIG. 7.
It should be noted that the subtree shown in fig. 4 is only an example, and includes a relatively small number of nodes, and the node types do not cover all the node types, but does not affect the description of step 6.
And 6-4, traversing each node in the abstract syntax tree, and connecting semantic codes of each node to obtain the semantic codes of the whole subtree.
For example, fun_001, block_000, if_000, op_005, var_000, num_0, block_001, op_004, var_001, array_float are used as the semantic encoding result of the subtree.
And 7, compressing the codes of each subtree to obtain the coding factors with the specified length.
And 8, inquiring element values corresponding to the subtrees from the semantic array by taking the coding factors corresponding to each subtree as indexes.
Each element in the semantic array corresponds to a class of code of the JavaScript engine, and the element value of the element is used for indicating whether a test case can test the class of code. For example, when the element value of the element is 1, it indicates that the existing test case can test the code; when the element value of the element is 0, no test case is indicated to test the code.
And 9, determining whether new.js can increase the semantic coverage of the JavaScript engine based on the element values corresponding to the subtrees.
If the element value corresponding to any subtree is 0, it is indicated that new.js can increase the semantic coverage of the JavaScript engine, and the corresponding element value can be modified to 1 and added to the test case set. If the element values corresponding to all subtrees are 1, it is indicated that new.js cannot increase the semantic coverage of the JavaScript engine, and the new.js can be discarded.
In the embodiment of the application, the subtree is disassembled, the subtree is encoded, the encoding factor is used as an index to inquire the semantic array, the semantic space coverage of the new test case obtained by deformation is measured, then the subsequent test case generation is guided by feedback by the measurement result, the possibility that the new test case generated by deformation improves the semantic space coverage can be obviously increased, more valuable test cases can be generated by higher high semantic space coverage, the generation mode of the test case is more reasonable, and the fuzzy test efficiency is also improved.
Fig. 8 is a flowchart of a testing method according to an embodiment of the present application, including the following steps.
In step 801, a test case set of a test object is acquired.
Wherein the test object is a JavaScript engine.
In step 802, the test case set is updated by using the test case generation method in the embodiment of the present application.
In step 803, the test object is tested using the updated test case set.
In the embodiment of the application, a test case evaluation system based on semantic coverage is established, codes in the deformed test cases are converted into semantic sequences, the coverage rate of the code in the semantic space is calculated, the code is used as feedback input to guide the generation of subsequent test cases, the high-quality test cases can be rapidly generated, and the fuzzy test efficiency of test objects is improved.
When the method provided in the embodiment of the present application is implemented in software or hardware or a combination of software and hardware, a plurality of functional modules may be included in the electronic device, and each functional module may include software, hardware, or a combination thereof.
Based on the same technical conception, the embodiment of the application also provides a device for generating the test case, and the principle of solving the problem of the device for generating the test case is similar to that of the method for generating the test case, so that the implementation of the device for generating the test case can be referred to the implementation of the method for generating the test case, and the repetition is omitted.
Fig. 9 is a schematic structural diagram of a generating device for a test case according to an embodiment of the present application, which includes a deforming module 901, an encoding module 902, a determining module 903, and a processing module 904.
The deformation module 901 is configured to perform deformation processing on test cases in the test case set to obtain alternative cases;
The encoding module 902 is configured to perform semantic encoding on the just-in-time compiled class code in the alternative use case, so as to obtain a semantic encoding result of the alternative use case;
A determining module 903, configured to determine, based on a semantic encoding result of the alternative use case, whether the alternative use case can increase a semantic coverage of a test object, where the semantic coverage is used to characterize a sufficiency of a semantic test on the test object;
And the processing module 904 is configured to add the alternative case to the test case set if it is determined that the alternative case can increase the semantic coverage of the test object.
In some embodiments, the encoding module 902 is specifically configured to:
Generating an abstract syntax tree of the alternative case;
determining a target tree corresponding to the just-in-time compiling class code in the abstract syntax tree;
decomposing the target tree according to a rule that the number of nodes contained in each sub tree is not more than N, so as to obtain at least two sub trees, wherein N is an integer greater than 1;
And respectively carrying out semantic coding on the at least two sub-trees to obtain a semantic coding result of the alternative case.
In some embodiments, nodes are shared between different subtrees or are not shared between different subtrees.
In some embodiments, the encoding module 902 is specifically configured to:
carrying out semantic expression on any node in each subtree according to node information of the node, wherein the node information comprises node names, node types and position information of the node in the subtree;
combining semantic expression results of all nodes to obtain semantic coding results of the subtrees;
and taking the semantic coding result of each subtree as the semantic coding result of the alternative case.
In some embodiments, the determining module 903 is specifically configured to:
Compressing the semantic coding result of each subtree to obtain a coding factor;
Querying element values corresponding to the subtrees from a semantic array by taking the coding factors as indexes, wherein each element in the semantic array corresponds to a class of codes of the test object, and the element values of the elements are used for indicating whether test cases can test the class of codes;
and determining whether the alternative use cases can increase the semantic coverage of the test object based on the element values corresponding to the subtrees.
In some embodiments, the determining module 903 is specifically configured to:
If the element value corresponding to any subtree indicates that no test case can test the corresponding class code of the test object, determining that the alternative case can increase the semantic coverage of the test object, and updating the element value to indicate that the existing test case can test the corresponding class code;
If the element value corresponding to each sub tree indicates that the existing test case can test the corresponding class code, determining that the alternative case cannot increase the semantic coverage of the test object.
In some embodiments, the processing module 904 is further configured to:
And discarding the alternative case if the alternative case is determined to not increase the semantic coverage of the test object.
Based on the same technical conception, the embodiment of the application also provides a testing device, and the principle of the testing device for solving the problems is similar to that of the testing method, so that the implementation of the testing device can be referred to the implementation of the testing method, and the repetition is omitted.
Fig. 10 is a schematic structural diagram of a test device according to an embodiment of the present application, which includes an obtaining module 1001, an updating module 1002, and a testing module 1003.
An obtaining module 1001, configured to obtain a test case set of a test object;
the updating module 1002 is configured to update the test case set by using the test case generation method provided by the present application;
And the testing module 1003 is configured to test the test object by using the updated test case set.
The division of the modules in the embodiments of the present application is schematically only one logic function division, and there may be another division manner in actual implementation, and in addition, each functional module in each embodiment of the present application may be integrated in one processor, or may exist separately and physically, or two or more modules may be integrated in one module. The coupling of the individual modules to each other may be achieved by means of interfaces which are typically electrical communication interfaces, but it is not excluded that they may be mechanical interfaces or other forms of interfaces. Thus, the modules illustrated as separate components may or may not be physically separate, may be located in one place, or may be distributed in different locations on the same or different devices. The integrated modules may be implemented in hardware or in software functional modules.
Having described the contrast learning method and apparatus of an exemplary embodiment of the present application, next, an electronic device according to another exemplary embodiment of the present application is described.
In some possible embodiments, an electronic device according to the application may comprise at least one processor and at least one memory. Wherein the memory stores program code which, when executed by the processor, causes the processor to perform the methods according to the various exemplary embodiments of the application described hereinabove.
An electronic device 130 implemented according to such an embodiment of the present application is described below with reference to fig. 11. The electronic device 130 shown in fig. 11 is merely an example, and should not be construed as limiting the functionality and scope of use of embodiments of the present application.
As shown in fig. 11, the electronic device 130 is embodied in the form of a general-purpose electronic device. Components of electronic device 130 may include, but are not limited to: the at least one processor 131, the at least one memory 132, and a bus 133 connecting the various system components, including the memory 132 and the processor 131.
Bus 133 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, a processor, and a local bus using any of a variety of bus architectures.
Memory 132 may include readable media in the form of volatile memory such as Random Access Memory (RAM) 1321 and/or cache memory 1322, and may further include Read Only Memory (ROM) 1323.
Memory 132 may also include a program/utility 1325 having a set (at least one) of program modules 1324, such program modules 1324 include, but are not limited to: an operating system, one or more application programs, other program modules, and program data, each or some combination of which may include an implementation of a network environment.
The electronic device 130 may also communicate with one or more external devices 134 (e.g., keyboard, pointing device, etc.), one or more devices that enable a user to interact with the electronic device 130, and/or any device (e.g., router, modem, etc.) that enables the electronic device 130 to communicate with one or more other electronic devices. Such communication may occur through an input/output (I/O) interface 135. Also, electronic device 130 may communicate with one or more networks such as a Local Area Network (LAN), a Wide Area Network (WAN), and/or a public network, such as the Internet, through network adapter 136. As shown, network adapter 136 communicates with other modules for electronic device 130 over bus 133. It should be appreciated that although not shown, other hardware and/or software modules may be used in connection with electronic device 130, including, but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID systems, tape drives, data backup storage systems, and the like.
In an exemplary embodiment, a computer readable storage medium is also provided, such as a memory 132, including instructions executable by the processor 131 to perform the contrast learning method described above. Alternatively, the storage medium may be a non-transitory computer readable storage medium, which may be, for example, ROM, random Access Memory (RAM), CD-ROM, magnetic tape, floppy disk, optical data storage device, and the like.
In an exemplary embodiment, a computer program product is also provided, which, when executed by an electronic device, is capable of carrying out any one of the exemplary methods provided by the application.
Also, a computer program product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium can be, for example, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples (a non-exhaustive list) of the readable storage medium would include the following: an electrical connection having one or more wires, a portable disk, a hard disk, a RAM, a ROM, an erasable programmable read-Only Memory (EPROM), flash Memory, optical fiber, compact disc read-Only Memory (Compact Disk Read Only Memory, CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
The method for generating test cases or the program product for implementing the test method in the embodiment of the application can adopt a CD-ROM and comprise program codes, and can run on computing equipment. However, the program product of the present application is not limited thereto, and in this document, a readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
The readable signal medium may include a data signal propagated in baseband or as part of a carrier wave with readable program code embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A readable signal medium may also be any readable medium that is not a readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, radio Frequency (RF), etc., or any suitable combination of the foregoing.
Program code for carrying out operations of the present application may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, C++ or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computing device, partly on the user's device, as a stand-alone software package, partly on the user's computing device, partly on a remote computing device, or entirely on the remote computing device or server. In the case of remote computing devices, the remote computing device may be connected to the user computing device through any kind of network, such as a local area network (Local Area Network, LAN) or wide area network (Wide Area Network, WAN), or may be connected to an external computing device (e.g., connected over the internet using an internet service provider).
It should be noted that although several units or sub-units of the apparatus are mentioned in the above detailed description, such a division is merely exemplary and not mandatory. Indeed, the features and functions of two or more of the elements described above may be embodied in one element in accordance with embodiments of the present application. Conversely, the features and functions of one unit described above may be further divided into a plurality of units to be embodied.
Furthermore, although the operations of the methods of the present application are depicted in the drawings in a particular order, this is not required or suggested that these operations must be performed in this particular order or that all of the illustrated operations must be performed in order to achieve desirable results. Additionally or alternatively, certain steps may be omitted, multiple steps combined into one step to perform, and/or one step decomposed into multiple steps to perform.
It will be appreciated by those skilled in the art that embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present application have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. It is therefore intended that the following claims be interpreted as including the preferred embodiments and all such alterations and modifications as fall within the scope of the application.
It will be apparent to those skilled in the art that various modifications and variations can be made to the present application without departing from the spirit or scope of the application. Thus, it is intended that the present application also include such modifications and alterations insofar as they come within the scope of the appended claims or the equivalents thereof.

Claims (9)

1. The method for generating the test case is characterized by comprising the following steps:
Performing deformation processing on the test cases in the obtained test case set to obtain alternative cases;
Carrying out semantic coding on the just-in-time compiling class code in the alternative use case to obtain a semantic coding result of the alternative use case;
determining whether the alternative use case can increase the semantic coverage of the test object based on the semantic coding result of the alternative use case, wherein the semantic coverage is used for representing the sufficiency of the semantic test of the test object;
if the alternative case is determined to be capable of increasing the semantic coverage of the test object, adding the alternative case into the test case set;
Performing semantic coding on the just-in-time compiling class code in the alternative case to obtain a semantic coding result of the alternative case, wherein the semantic coding result comprises the following steps:
Generating an abstract syntax tree of the alternative case; determining a target tree corresponding to the just-in-time compiling class code in the abstract syntax tree; decomposing the target tree according to a rule that the number of nodes contained in each sub tree is not more than N, so as to obtain at least two sub trees, wherein N is an integer greater than 1; respectively carrying out semantic coding on the at least two sub-trees to obtain a semantic coding result of the alternative case, wherein carrying out semantic coding on each sub-tree comprises carrying out semantic expression on node information of each node in the sub-tree;
Based on the semantic coding result of the alternative case, determining whether the alternative case can increase the semantic coverage of the test object includes:
Compressing the semantic coding result of each subtree to obtain a coding factor; querying element values corresponding to the subtrees from a semantic array by taking the coding factors as indexes, wherein each element in the semantic array corresponds to a class of codes of the test object, and the element values of the elements are used for indicating whether test cases can test the class of codes; and determining whether the alternative use cases can increase the semantic coverage of the test object based on the element values corresponding to the subtrees.
2. The method of claim 1, wherein nodes are shared between different subtrees or nodes are not shared between different subtrees.
3. The method of claim 1, wherein semantically encoding the at least two sub-trees to obtain the semantic encoding result of the alternative case comprises:
carrying out semantic expression on any node in each subtree according to node information of the node, wherein the node information comprises node names, node types and position information of the node in the subtree;
combining semantic expression results of all nodes to obtain semantic coding results of the subtrees;
and taking the semantic coding result of each subtree as the semantic coding result of the alternative case.
4. The method of claim 1, wherein determining whether the alternative case can increase semantic coverage of the test object based on the element values corresponding to each subtree comprises:
If the element value corresponding to any subtree indicates that no test case can test the corresponding class code of the test object, determining that the alternative case can increase the semantic coverage of the test object, and updating the element value to indicate that the existing test case can test the corresponding class code;
If the element value corresponding to each sub tree indicates that the existing test case can test the corresponding class code, determining that the alternative case cannot increase the semantic coverage of the test object.
5. The method as recited in claim 1, further comprising:
And discarding the alternative case if the alternative case is determined to not increase the semantic coverage of the test object.
6. A method of testing, comprising:
Acquiring a test case set of a test object;
Updating the test case set by the method of any one of claims 1 to 5;
And testing the test object by using the updated test case set.
7. A test case generating apparatus, comprising:
The deformation module is used for carrying out deformation treatment on the test cases in the test case set to obtain alternative cases;
the coding module is used for carrying out semantic coding on the just-in-time compiling class code in the alternative use case to obtain a semantic coding result of the alternative use case;
the determining module is used for determining whether the alternative case can increase the semantic coverage of the test object based on the semantic coding result of the alternative case, wherein the semantic coverage is used for representing the sufficiency of the semantic test of the test object;
The processing module is used for adding the alternative case into the test case set if the alternative case is determined to be capable of increasing the semantic coverage of the test object;
The coding module is specifically used for generating an abstract syntax tree of the alternative case; determining a target tree corresponding to the just-in-time compiling class code in the abstract syntax tree; decomposing the target tree according to a rule that the number of nodes contained in each sub tree is not more than N, so as to obtain at least two sub trees, wherein N is an integer greater than 1; respectively carrying out semantic coding on the at least two sub-trees to obtain a semantic coding result of the alternative case, wherein carrying out semantic coding on each sub-tree comprises carrying out semantic expression on node information of each node in the sub-tree;
The determining module is specifically configured to compress a semantic encoding result of each subtree to obtain an encoding factor; querying element values corresponding to the subtrees from a semantic array by taking the coding factors as indexes, wherein each element in the semantic array corresponds to a class of codes of the test object, and the element values of the elements are used for indicating whether test cases can test the class of codes; and determining whether the alternative use cases can increase the semantic coverage of the test object based on the element values corresponding to the subtrees.
8. An electronic device, comprising: at least one processor, and a memory communicatively coupled to the at least one processor, wherein:
The memory stores instructions executable by the at least one processor to cause the at least one processor to perform the method of any of claims 1-5.
9. A storage medium, characterized in that the electronic device performs the method according to any of claims 1-5 when instructions in the storage medium are executed by a processor of the electronic device.
CN202111548993.2A 2021-12-17 2021-12-17 Test case generation method and test method Active CN114265772B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111548993.2A CN114265772B (en) 2021-12-17 2021-12-17 Test case generation method and test method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111548993.2A CN114265772B (en) 2021-12-17 2021-12-17 Test case generation method and test method

Publications (2)

Publication Number Publication Date
CN114265772A CN114265772A (en) 2022-04-01
CN114265772B true CN114265772B (en) 2024-07-26

Family

ID=80827725

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111548993.2A Active CN114265772B (en) 2021-12-17 2021-12-17 Test case generation method and test method

Country Status (1)

Country Link
CN (1) CN114265772B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113448844B (en) * 2021-06-21 2022-10-25 青岛海尔科技有限公司 Method and device for regression testing and electronic equipment
CN115221061B (en) * 2022-07-22 2024-03-22 中国电信股份有限公司 Test code generation method and device, storage medium and electronic equipment

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103425584A (en) * 2013-08-27 2013-12-04 上海复深蓝信息技术有限公司 Large-scale application regression testing information processing method based on Java bytecode
CN108717374A (en) * 2018-04-24 2018-10-30 阿里巴巴集团控股有限公司 The method, apparatus and computer equipment that Java Virtual Machine preheats when starting

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8627287B2 (en) * 2007-11-29 2014-01-07 Microsoft Corporation Prioritizing quality improvements to source code
CA2686993A1 (en) * 2009-12-03 2011-06-03 Ibm Canada Limited - Ibm Canada Limitee Semantic verification of multidimensional data sources
US20170161065A1 (en) * 2012-10-20 2017-06-08 Google Inc. Generating Code Coverage Data for use with a Computing Device and System
US9619375B2 (en) * 2014-05-23 2017-04-11 Carnegie Mellon University Methods and systems for automatically testing software
US9990272B2 (en) * 2016-08-03 2018-06-05 International Business Machines Corporation Test case generation for uncovered code paths
CN113590495B (en) * 2021-08-31 2025-03-21 北京沃东天骏信息技术有限公司 A method, device, equipment and storage medium for determining test coverage

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103425584A (en) * 2013-08-27 2013-12-04 上海复深蓝信息技术有限公司 Large-scale application regression testing information processing method based on Java bytecode
CN108717374A (en) * 2018-04-24 2018-10-30 阿里巴巴集团控股有限公司 The method, apparatus and computer equipment that Java Virtual Machine preheats when starting

Also Published As

Publication number Publication date
CN114265772A (en) 2022-04-01

Similar Documents

Publication Publication Date Title
US8601453B2 (en) COBOL to bytecode translation
CN109408528B (en) Database script generation method and device, calculation device and storage medium
CN109863473B (en) Method, electronic device and electronic system for sample-driven profile-guided optimization
CN112394942B (en) Distributed software development compiling method and software development platform based on cloud computing
CN106293677B (en) A kind of code conversion method and device
US9122540B2 (en) Transformation of computer programs and eliminating errors
CN114265772B (en) Test case generation method and test method
US11327722B1 (en) Programming language corpus generation
CN110866029B (en) sql statement construction method, device, server and readable storage medium
CN106371887A (en) System and method for MSVL compiling
CN112269566B (en) Script generation processing method, device, equipment and system
CN114625844B (en) Code searching method, device and equipment
US9886251B2 (en) Optimized compiling of a template function
CN115905031B (en) Test case recommendation method based on accurate quality assurance system
CN114064601A (en) Storage process conversion method, device, equipment and storage medium
CN110928535B (en) Derived variable deployment method, device, equipment and readable storage medium
CN110489124B (en) Source code execution method, source code execution device, storage medium and computer equipment
CN115826991B (en) Software script generation method, system, computer and readable storage medium
CN113312880B (en) Text form conversion method and device and electronic equipment
CN114090017A (en) Method and device for analyzing programming language and nonvolatile storage medium
Nguyen et al. Using topic model to suggest fine-grained source code changes
CN111597202A (en) Battlefield situation information on-demand extraction method and device based on fractal theory
CN119128905B (en) Intelligent vulnerability mining system and method for real-time operating system
CN110825608B (en) Critical semantic testing method and device, storage medium and electronic equipment
CN119473376A (en) Method, device, equipment and medium for analyzing change of call link

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant