CN113778890B - Code testing method and device, electronic equipment and storage medium - Google Patents

Code testing method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN113778890B
CN113778890B CN202111087190.1A CN202111087190A CN113778890B CN 113778890 B CN113778890 B CN 113778890B CN 202111087190 A CN202111087190 A CN 202111087190A CN 113778890 B CN113778890 B CN 113778890B
Authority
CN
China
Prior art keywords
code
test case
link
program source
test
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
CN202111087190.1A
Other languages
Chinese (zh)
Other versions
CN113778890A (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.)
Ping An Bank Co Ltd
Original Assignee
Ping An Bank 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 Ping An Bank Co Ltd filed Critical Ping An Bank Co Ltd
Priority to CN202111087190.1A priority Critical patent/CN113778890B/en
Publication of CN113778890A publication Critical patent/CN113778890A/en
Application granted granted Critical
Publication of CN113778890B publication Critical patent/CN113778890B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3676Test management for coverage analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3692Test management for test results analysis
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention relates to the technical field of testing, in particular to a code testing method, a device, an electronic device and a storage medium, which are used for carrying out structural analysis on a program source code and forming a logic link according to a plurality of function functions in the code and the calling relation of the function functions; dividing the program source code into a plurality of code blocks according to each function in the logic link, and adjusting the logic link into a theoretical execution link according to code block identifiers; obtaining test cases matched with an actual execution link and a theoretical execution link from a test case library to form a test case combination; testing the program source code by using the test case combination; the test cases can be automatically obtained through matching of the theoretical execution link and the actual execution link, so that the code branch coverage rate of the test can be improved, and the obtaining difficulty of the test cases can be reduced.

Description

Code testing method and device, electronic equipment and storage medium
[ field of technology ]
The present invention relates to the field of testing technologies, and in particular, to a code testing method, a code testing device, an electronic device, and a storage medium.
[ background Art ]
Code coverage (codecoverage) is an important index reflecting the coverage degree of a test case to a tested program, and is also a reference value for measuring the test integrity. In the process of software development, code coverage data is obtained by the client and is generated based on all codes of the monitored item. In the prior art, when testing a program source code, an existing test case is generally selected or a new test case is generally written based on code coverage rate, and an actual execution link of the test case is not considered when the test case is selected, so that the technical problem of low code branch coverage rate of the test cannot be solved.
[ invention ]
The invention aims to provide a code testing method, a device, electronic equipment and a storage medium, which are used for solving the technical problem of low code branch coverage rate in the prior art.
The technical scheme of the invention is as follows: provided is a code testing method, comprising:
obtaining a logic link of a program source code to be tested, wherein the logic link comprises a plurality of function functions and calling relations of the function functions;
dividing the program source code into a plurality of code blocks according to each function in the logic link, acquiring the connection relation of each code block according to the calling relation of the function in the logic link, and generating a theoretical execution link of the program source code according to the code identification of the code block and the connection relation;
inserting a record identifier for recording the running information of each code block in each code block of the program source code;
obtaining a test case combination of which an actual execution link is matched with the theoretical execution link from a pre-constructed test case library, wherein the test case library comprises a plurality of test cases and the actual execution link corresponding to the test cases, and the actual execution link is obtained by recording the test cases in the process of executing test tasks of historical program source codes;
And calling the program source code inserted with the record label to test each test case in the test case combination, acquiring the running information of the corresponding code block recorded by each record identification, and generating a test result of the program source code according to the running information of each test case.
Optionally, the dividing the program source code into a plurality of code blocks according to each function in the logic link, obtaining a connection relationship of each code block according to a calling relationship of the function in the logic link, and generating a theoretical execution link of the program source code according to a code identifier of the code block and the connection relationship, including:
dividing the program source code into a plurality of code blocks according to each function in the logic link;
comparing the code blocks with each unit code in a preset code warehouse, and determining the unit code matched with the code blocks according to the comparison result;
acquiring a code identifier of the unit code in a code warehouse, and taking the code identifier as a code identifier of a code block;
acquiring the connection relation of each code block according to the calling relation of the function in the logic link;
And generating a theoretical execution link of the program source code according to the code identification of the code block and the connection relation.
Optionally, the test case library is constructed according to the following steps:
acquiring a logic link of a first program source code, wherein the logic link comprises a plurality of function functions and calling relations of the function functions;
dividing the first program source code into a plurality of code blocks according to each function in the logic link, acquiring the connection relation of each code block according to the calling relation of the function in the logic link, and generating a theoretical execution link of the first program source code according to the code blocks and the connection relation;
inserting a record identifier for recording the running information of each code block in the first program source code;
acquiring a pre-edited test case, calling the first program source code inserted with the record label to test the test case, acquiring running information of the corresponding code blocks recorded by the record identifiers, and generating an actual execution link and an actual execution duration of the test case according to the running information;
And storing the test cases and the corresponding actual execution links into a test case library.
Optionally, the obtaining the test case combination that the actual execution link matches the theoretical execution link from the pre-built test case library includes:
comparing the theoretical execution links of the program source codes with actual execution links stored in a pre-built test case library respectively to obtain actual execution links matched with the theoretical execution links;
if the number of the matched actual execution links is a plurality of, acquiring the actual execution duration of each actual execution link, and selecting the actual execution link with the minimum actual execution duration;
and obtaining the test cases matched with the program source codes according to the actual execution link, and generating the test case combination.
Optionally, after the obtaining the test case combination that the actual execution link matches the theoretical execution link from the pre-built test case library, the method further includes:
if the theoretical execution link cannot successfully acquire the matched actual execution link, generating a test case generation request of the theoretical execution link;
receiving an input test case corresponding to the theoretical execution link, adding a new label to the test case, and adding the test case carrying the new label to the test case combination.
Optionally, the calling the program source code with the record label inserted tests each test case in the test case combination, obtains the running information of the corresponding code block recorded by each record identifier, and after generating the test result of the program source code according to the running information of each test case, further includes:
generating an actual execution link and an actual execution duration of the test case according to the running information of the test case carrying the newly-added label;
and deleting the newly added label of the test case, and storing the test case and the corresponding actual execution link into a test case library.
Optionally, the obtaining the logic link of the program source code to be tested includes:
analyzing the program source code to be tested to generate an abstract syntax tree of the program source code;
accessing the abstract syntax tree to obtain a function corresponding to each symbol on the abstract syntax tree;
accessing the abstract syntax tree to obtain calling nodes of the function functions, and recording calling relations among the function functions;
and generating a logic link of the program source code according to the function and the calling relation of the function.
The other technical scheme of the invention is as follows: there is provided a code testing apparatus including:
the analysis module is used for acquiring a logic link of a program source code to be tested, wherein the logic link comprises a plurality of function functions and calling relations of the function functions;
the link generation module is used for dividing the program source code into a plurality of code blocks according to each function in the logic link, acquiring the connection relation of each code block according to the calling relation of the function in the logic link, and generating a theoretical execution link of the program source code according to the code identification of the code block and the connection relation;
the instrumentation module is used for inserting a record identifier for recording the running information of each code block in each code block of the program source code;
the matching module is used for acquiring a test case combination of which the actual execution link is matched with the theoretical execution link from a pre-constructed test case library, wherein the test case library comprises a plurality of test cases and the actual execution link corresponding to the test cases, and the actual execution link is obtained by recording the test cases in the process of being used for executing the test tasks of the historical program source codes;
The test module is used for calling the program source code inserted with the record label to test each test case in the test case combination, obtaining the running information of the corresponding code block recorded by each record identification, and generating a test result of the program source code according to the running information of each test case.
The other technical scheme of the invention is as follows: there is provided an electronic device comprising a processor, a memory coupled to the processor, the memory storing program instructions executable by the processor; the processor implements the code testing method described above when executing the program instructions stored in the memory.
The other technical scheme of the invention is as follows: a storage medium is provided, in which program instructions are stored, which program instructions, when executed by a processor, implement the code testing method described above.
According to the code testing method, the device, the electronic equipment and the storage medium, the structure analysis is carried out on the program source code, and a logic link is formed according to a plurality of function functions in the code and the calling relation of the function functions; dividing the program source code into a plurality of code blocks according to each function in the logic link, and adjusting the logic link into a theoretical execution link according to code block identifiers; obtaining test cases matched with an actual execution link and a theoretical execution link from a test case library to form a test case combination; testing the program source code by using the test case combination; the test cases can be automatically obtained through matching of the theoretical execution link and the actual execution link, so that the code branch coverage rate of the test can be improved, and the obtaining difficulty of the test cases can be reduced.
[ description of the drawings ]
FIG. 1 is a flow chart of a code testing method according to a first embodiment of the present invention;
FIG. 2 is a flow chart of a code testing method according to a second embodiment of the present invention;
FIG. 3 is a schematic diagram of a code testing device according to a third embodiment of the present invention;
fig. 4 is a schematic structural diagram of an electronic device according to a fourth embodiment of the present invention;
fig. 5 is a schematic structural view of a storage medium according to a fifth embodiment of the present invention.
[ detailed description ] of the invention
The following description of the embodiments of the present invention will be made clearly and fully with reference to the accompanying drawings, in which it is evident that the embodiments described are only some, but not all embodiments of the invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
The terms "first," "second," "third," and the like in this disclosure are used for descriptive purposes only and are not to be construed as indicating or implying a relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defining "a first", "a second", and "a third" may explicitly or implicitly include at least one such feature. In the description of the present invention, the meaning of "plurality" means at least two, for example, two, three, etc., unless specifically defined otherwise. All directional indications (such as up, down, left, right, front, back … …) in embodiments of the present invention are merely used to explain the relative positional relationship, movement, etc. between the components in a particular gesture (as shown in the drawings), and if the particular gesture changes, the directional indication changes accordingly. Furthermore, the terms "comprise" and "have," as well as any variations thereof, are intended to cover a non-exclusive inclusion. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not limited to only those listed steps or elements but may include other steps or elements not listed or inherent to such process, method, article, or apparatus.
Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment may be included in at least one embodiment of the invention. The appearances of such phrases in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. Those of skill in the art will explicitly and implicitly appreciate that the embodiments described herein may be combined with other embodiments.
Fig. 1 is a flow chart of a code testing method according to a first embodiment of the present invention. It should be noted that, if there are substantially the same results, the method of the present invention is not limited to the flow sequence shown in fig. 1.
As shown in fig. 1, the code testing method includes the steps of:
s101, acquiring a logic link of a program source code to be tested, wherein the logic link comprises a plurality of function functions and calling relations of the function functions;
analyzing the structure of the program source code to be tested, wherein the structure of the program source code relates to the realization of a plurality of functions, the realization of each function relates to one or a plurality of function functions and the calling among the function functions, the operation of calling another function and the step of judging are necessarily involved in the execution process of the function, and the calling result and the judging result can possibly cause different logic branches to appear; and the step of calling or judging may also continue to call another one or more function implementations, where the existence of a logic branch causes the occurrence of different logic links, each logic link is used to characterize the calling relationship of multiple function functions on the link, so that one program source code may relate to one or more logic links, specifically, for one program source code, analysis of the program source code shows that it relates to 7 function functions, where the 7 function functions are 4 logic links in total, the logic link 1 calls the function B and the function B, the logic link 2 calls the function B and the function B, the logic link 3 calls the function C, the function C and the function E, and the logic link 4 calls the function E and the function E.
Specifically, step S101 includes the steps of:
s1011, analyzing the program source code to be tested, and generating an abstract syntax tree of the program source code;
firstly compiling a program source code to obtain a class file of the program source code; and then, carrying out grammar analysis on the program source code by using the JavaParser to generate an abstract grammar tree corresponding to the program source code, wherein the JavaParser is generated by JavaCC.
S1012, accessing the abstract syntax tree to obtain a function corresponding to each symbol on the abstract syntax tree;
the visitor mode is used for accessing the abstract syntax tree, and the function of each symbol on the abstract syntax tree is obtained by combining a Java reflection mechanism according to the class file obtained in the step S1011 in the accessing process.
S1013, accessing the abstract syntax tree to obtain a calling node of the function, and recording a calling relation between the function functions;
s1014, generating a logic link of the program source code according to the function and the calling relation of the function.
In addition, the function nodes can be accessed on an abstract syntax tree, corresponding control flow graphs (Control Flow Graph, CFG) are generated for each function, and the control flow graphs are abstract data structures of the program source codes.
S102, dividing the program source code into a plurality of code blocks according to each function in the logic link, acquiring the connection relation of each code block according to the calling relation of the function in the logic link, and generating a theoretical execution link of the program source code according to the code identification of the code block and the connection relation;
in addition, in practical use, more than one code capable of realizing the function a may be used, for example, the codes a1, a2 and a3 may all realize the function a, in this embodiment, a code warehouse may be pre-constructed to store codes for realizing different function functions, and a code identifier is provided for each code to distinguish different codes corresponding to the same function, for example, the code a1 for realizing the function a in the program source code, so that the code identifier of the code a1 is used to characterize the code block a in the theoretical execution link.
The theoretical execution link is used for representing all paths which can be traversed theoretically in the program source code execution process, the theoretical execution link corresponds to the logic link, the calling relationship in the logic link corresponds to the connection relationship in the theoretical execution link, for example, the logic link 1 is a function A calling function B and a function B calling function C, the code block of the function A corresponds to a code identifier a1, the code block of the function B corresponds to a code identifier B2, the code block of the function C corresponds to a code identifier C1, and the theoretical execution link 1 is a 1- & gtb 2- & gtc 1; accordingly, the theoretical execution link 2 is a1→b2→d1, the theoretical execution link 3 is a1→c1→e2→f2, and the theoretical execution link 4 is a1→e2→g1.
The step S102 specifically includes the following steps:
s201, dividing the program source code into a plurality of code blocks according to each function in the logic link;
s202, comparing the code blocks with each unit code in a preset code warehouse, and determining the unit codes matched with the code blocks according to comparison results;
if the matching of the code block and the unit code fails, the code block is described as a new written code, a new test case is generally written for the new written code, and a proper test case cannot be acquired from the test case library.
S203, acquiring a code identifier of the unit code in a code warehouse, and taking the code identifier as a code identifier of a code block;
s204, obtaining the connection relation of each code block according to the calling relation of the function in the logic link;
s205, generating a theoretical execution link of the program source code according to the code identification of the code block and the connection relation;
each unit code in the code warehouse is a code for realizing different functional functions, each unit code corresponds to one functional function, the same functional function possibly corresponds to a plurality of unit codes, and the code identification can be the number of the unit code in the code warehouse.
S103, inserting a record identifier for recording the running information of each code block in each code block of the program source code;
the instrumentation record mark is used for realizing information acquisition, in each code block of the program source code, in the execution process of the program source code, the record mark in the code block can automatically record the running information when the code block is executed when the corresponding code block is executed, the running information is the characteristic data generated when the code block is executed, and can comprise the connection nodes of the code block and other code blocks, the execution time of the code block and the like, the instrumentation record mark in the code block is generally the entry position of the corresponding function of the code block, and if the code block comprises the judging position (for example if statement) or the jumping position (for example goto statement), the instrumentation record mark can also be arranged at the judging position or the jumping position.
The different test cases may trigger different execution links to be executed, for example, a code block includes a determination step of "if Y > 0, jump to W", where Y is an internal variable in the code block, and the variable Y is calculated according to the parameter X in the test case, so that the determination condition Y > 0 has different branches due to different test cases, and when testing the program source code with different test cases, different execution links are executed.
S104, obtaining a test case combination of which an actual execution link is matched with the theoretical execution link from a pre-constructed test case library, wherein the test case library comprises a plurality of test cases and the actual execution link corresponding to the test cases, and the actual execution link is obtained by recording the test cases in the process of being used for executing test tasks of historical program source codes;
for easy understanding, the steps of acquiring the actual execution link and the method of constructing the test case library are described first, and the specific steps are as follows:
s301, acquiring a logic link of a first program source code, wherein the logic link comprises a plurality of function functions and calling relations of the function functions;
s302, dividing the first program source code into a plurality of code blocks according to each function in the logic link, acquiring the connection relation of each code block according to the calling relation of the function in the logic link, and generating a theoretical execution link of the first program source code according to the code blocks and the connection relation;
s303, inserting a record identifier for recording the running information of each code block in each code block of the first program source code;
Steps S301 to S303 may be specifically referred to the description of steps S101 to S103.
S304, acquiring a pre-edited test case, calling the first program source code inserted with the record label to test the test case, acquiring running information of the corresponding code blocks recorded by the record identifiers, and generating an actual execution link and an actual execution duration of the test case according to the running information;
the test case in the step is written aiming at the program source code, in the process of testing the first program source code by using the test case, the running information related to the code blocks is recorded when the code blocks are executed, the sequence of the code blocks which are actually covered and the sequence of the covered code blocks when the test case is used for testing can be obtained according to the running information recorded by the code blocks, the actual execution link of the test case when the first program source code is tested can be obtained, the actual execution link possibly cannot completely cover the theoretical execution link of the first program source code, the actual execution duration of the actual execution link can be obtained according to the execution time of each code block in the running information, and the test speed of the test case is reflected.
S305, storing the test cases and the corresponding actual execution links into a test case library;
the actual execution link characterizes the code blocks that can be covered by the test case and the logical relationship between the code blocks, and the actual execution link obtained in step S304 is stored in association with the test case.
Along with the advancement of test work, the number of test cases in the test case library is increased continuously, the number of actually executed links is increased continuously, and when the program source code to be tested needs to be tested, matched test cases are screened from the test case library.
The step S104 specifically includes the following steps:
s401, respectively comparing the theoretical execution links of the program source codes with actual execution links stored in a pre-built test case library to obtain actual execution links matched with the theoretical execution links;
the program source code is provided with a plurality of theoretical execution links, and the theoretical execution links and the actual execution links are respectively matched, specifically, when each theoretical execution link is used for acquiring a matched actual execution link, the theoretical execution link and the actual execution link comprise a plurality of code identifiers which are sequentially connected according to an execution sequence, and when the program source code is compared, whether a first code identifier in the theoretical execution link is matched with a first code identifier in the actual execution link or not is firstly judged according to the execution sequence; if the first code identification is matched, judging whether a second code identification in the theoretical execution link is matched with a second code identification in the actual execution link, and if not, ending; repeating the steps, if the last code identifier is matched, judging whether the next code identifier in the theoretical execution link is matched with the next code identifier in the actual execution link, and if not, ending; repeating the steps until the last code identifier in the theoretical execution link, and if the last code identifier is matched, determining that the actual execution link is matched with the theoretical execution link.
S402, if the number of the matched actual execution links is a plurality of, acquiring the actual execution duration of each actual execution link, and selecting the actual execution link with the minimum actual execution duration;
s403, acquiring test cases matched with the program source codes according to the actual execution links, and generating test case combinations;
specifically, for example, theoretical execution link 1 is a1→b2→c1, theoretical execution link 2 is a1→b2→d1, theoretical execution link 3 is a1→c1→e2→f2, theoretical execution link 4 is a1→e2→g1, and test cases matched with theoretical execution links 1,2, and 3 are selected, respectively. After the actual execution links of all the test cases in the test case combination are overlapped, the theoretical execution links of the program source codes to be tested can be covered to the greatest extent.
S105, calling the program source code inserted with the record label to test each test case in the test case combination, obtaining the running information of the corresponding code block recorded by each record identifier, and generating a test result of the program source code according to the running information of each test case;
in the process of testing the program source code by using the test case, the running information related to the code blocks is recorded when the code blocks are executed, the code blocks which are actually covered and the sequence among the covered code blocks can be obtained according to the running information recorded by the code blocks when the test case is used for testing, the test execution link of the program source code is obtained, and the coverage rate of the execution link is calculated according to the test execution link and the theoretical execution link.
Along with the accumulation of a large amount of test case samples in the test case library, the code test method of the embodiment can realize intelligent test case combination recommendation, acquire and process related data based on an artificial intelligence technology, and realize unattended artificial intelligence test. Among these, artificial intelligence (Artificial Intelligence, AI) is the theory, method, technique and application system that uses a digital computer or a digital computer-controlled machine to simulate, extend and extend human intelligence, sense the environment, acquire knowledge and use knowledge to obtain optimal results.
Artificial intelligence infrastructure technologies generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technologies, operation/interaction systems, mechatronics, and the like. The artificial intelligence software technology mainly comprises a computer vision technology, a robot technology, a biological recognition technology, a voice processing technology, a natural language processing technology, machine learning/deep learning and other directions.
The code testing method of the embodiment can also be applied to vulnerability detection of a digital medical platform.
Fig. 2 is a flow chart of a code testing method according to a second embodiment of the invention. It should be noted that, if there are substantially the same results, the method of the present invention is not limited to the flow sequence shown in fig. 2.
As shown in fig. 2, the code testing method includes the steps of:
s501, acquiring a logic link of a program source code to be tested, wherein the logic link comprises a plurality of function functions and calling relations of the function functions;
s502, dividing the program source code into a plurality of code blocks according to each function in the logic link, acquiring the connection relation of each code block according to the calling relation of the function in the logic link, and generating a theoretical execution link of the program source code according to the code identification of the code block and the connection relation;
s503, inserting a record mark for recording the running information of each code block in each code block of the program source code;
s504, obtaining a test case combination of which an actual execution link is matched with the theoretical execution link from a pre-constructed test case library, wherein the test case library comprises a plurality of test cases and the actual execution link corresponding to the test cases, and the actual execution link is obtained by recording the test cases in the process of being used for executing test tasks of historical program source codes;
the steps S501 to S504 are specifically referred to steps S101 to S104 of the first embodiment, and are not described in detail herein.
S505, if the theoretical execution link cannot successfully acquire the matched actual execution link, generating a test case generation request of the theoretical execution link; receiving an input test case corresponding to the theoretical execution link, adding a new label to the test case, and adding the test case carrying the new label to the test case combination.
The method includes that a matched actual execution link cannot be successfully obtained, and the fact that a test case suitable for the theoretical execution link does not exist in a test case library is indicated, and at the moment, a test case generation request is sent to remind a tester of writing the test case of the theoretical execution link.
S506, calling the program source code inserted with the record label to test each test case in the test case combination, obtaining the running information of the corresponding code block recorded by each record identifier, and generating a test result of the program source code according to the running information of each test case;
the step S506 is specifically referred to step S105 of the first embodiment, and will not be described herein in detail.
S507, generating an actual execution link and an actual execution duration of the test case according to the running information of the test case carrying the newly-added label; and deleting the newly added label of the test case, and storing the test case and the corresponding actual execution link into a test case library.
In this embodiment, when the test case cannot be matched in the test case library, a new test case needs to be rewritten for the theoretical execution link, and after the test is finished, the new test case and the corresponding actual execution link are stored in the test case library, so that the test case library is continuously enriched.
Fig. 3 is a schematic structural diagram of a code testing device according to a third embodiment of the present invention. As shown in fig. 3, the code testing device 30 includes an analysis module 31, a link generation module 32, a instrumentation module 33, a matching module 34, and a testing module 35, where the analysis module 31 is configured to obtain a logic link of a program source code to be tested, where the logic link includes a plurality of function functions and a calling relationship of the function functions; the link generation module 32 is configured to divide the program source code into a plurality of code blocks according to each function in the logical link, obtain a connection relationship of each code block according to a calling relationship of the function in the logical link, and generate a theoretical execution link of the program source code according to a code identifier of the code block and the connection relationship; a instrumentation module 33, configured to insert, in each code block of the program source code, a record identifier for recording running information of the code block; the matching module 34 is configured to obtain a test case combination in which an actual execution link matches the theoretical execution link from a pre-built test case library, where the test case library includes a plurality of test cases and actual execution links corresponding to the test cases, where the actual execution links are obtained by recording during a test task in which the test cases are used to execute historical program source codes; and the test module 35 is configured to call the program source code inserted with the record label to test each test case in the test case combination, obtain the running information of the corresponding code block recorded by each record identifier, and generate a test result of the program source code according to the running information of each test case.
Further, the link generation module 32 is further configured to: dividing the program source code into a plurality of code blocks according to each function in the logic link; comparing the code blocks with each unit code in a preset code warehouse, and determining the unit code matched with the code blocks according to the comparison result; acquiring a code identifier of the unit code in a code warehouse, and taking the code identifier as a code identifier of a code block; acquiring the connection relation of each code block according to the calling relation of the function in the logic link; and generating a theoretical execution link of the program source code according to the code identification of the code block and the connection relation.
Further, the matching module 34 is further configured to obtain a logic link of the first program source code, where the logic link includes a plurality of function functions and a calling relationship of the function functions; dividing the first program source code into a plurality of code blocks according to each function in the logic link, acquiring the connection relation of each code block according to the calling relation of the function in the logic link, and generating a theoretical execution link of the first program source code according to the code blocks and the connection relation; inserting a record identifier for recording the running information of each code block in the first program source code; acquiring a pre-edited test case, calling the first program source code inserted with the record label to test the test case, acquiring running information of the corresponding code blocks recorded by the record identifiers, and generating an actual execution link and an actual execution duration of the test case according to the running information; and storing the test cases and the corresponding actual execution links into a test case library.
Further, the matching module 34 is further configured to compare the theoretical execution links of the program source code with actual execution links stored in a pre-built test case library, respectively, to obtain actual execution links matched with the theoretical execution links; if the number of the matched actual execution links is a plurality of, acquiring the actual execution duration of each actual execution link, and selecting the actual execution link with the minimum actual execution duration; and obtaining the test cases matched with the program source codes according to the actual execution link, and generating the test case combination.
Further, the matching module 34 is further configured to generate a test case generation request of the theoretical execution link if the theoretical execution link cannot successfully obtain the matched actual execution link; receiving an input test case corresponding to the theoretical execution link, adding a new label to the test case, and adding the test case carrying the new label to the test case combination.
Further, the matching module 34 is further configured to generate an actual execution link and an actual execution duration of the test case according to the running information of the test case carrying the new tag; and deleting the newly added label of the test case, and storing the test case and the corresponding actual execution link into a test case library.
Further, the analysis module 31 is further configured to analyze the program source code to be tested, and generate an abstract syntax tree of the program source code; accessing the abstract syntax tree to obtain a function corresponding to each symbol on the abstract syntax tree; accessing the abstract syntax tree to obtain calling nodes of the function functions, and recording calling relations among the function functions; and generating a logic link of the program source code according to the function and the calling relation of the function.
Fig. 4 is a schematic structural view of an electronic device according to a fourth embodiment of the present invention. As shown in fig. 4, the electronic device 40 includes a processor 41 and a memory 42 coupled to the processor 41.
The memory 42 stores program instructions for implementing the code testing method of any of the embodiments described above.
The processor 41 is used to execute program instructions stored in the memory 42 for code testing.
The processor 41 may also be referred to as a CPU (Central Processing Unit ). The processor 41 may be an integrated circuit chip with signal processing capabilities. Processor 41 may also be a general purpose processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
Referring to fig. 5, fig. 5 is a schematic structural diagram of a storage medium according to a fifth embodiment of the present invention. The storage medium according to the embodiment of the present invention stores the program instructions 51 capable of implementing all the methods described above, and the storage medium may be nonvolatile or volatile. The program instructions 51 may be stored in the storage medium as a software product, and include instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) or a processor (processor) to perform all or part of the steps of the methods according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), a magnetic disk, an optical disk, or other various media capable of storing program codes, or a terminal device such as a computer, a server, a mobile phone, a tablet, or the like.
In the several embodiments provided in the present invention, it should be understood that the disclosed systems, devices, and methods may be implemented in other manners. For example, the apparatus embodiments described above are merely illustrative, e.g., the division of elements is merely a logical functional division, and there may be additional divisions of actual implementation, e.g., multiple elements or components may be combined or integrated into another system, or some features may be omitted, or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be an indirect coupling or communication connection via some interfaces, devices or units, which may be in electrical, mechanical or other form.
In addition, each functional unit in the embodiments of the present invention may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units may be implemented in hardware or in software functional units. The foregoing is only the embodiments of the present invention, and the patent scope of the invention is not limited thereto, but is also covered by the patent protection scope of the invention, as long as the equivalent structures or equivalent processes of the present invention and the contents of the accompanying drawings are changed, or the present invention is directly or indirectly applied to other related technical fields.
While the invention has been described with respect to the above embodiments, it should be noted that modifications can be made by those skilled in the art without departing from the inventive concept, and these are all within the scope of the invention.

Claims (8)

1. A code testing method, comprising:
obtaining a logic link of a program source code to be tested, wherein the logic link comprises a plurality of function functions and calling relations of the function functions;
Dividing the program source code into a plurality of code blocks according to each function in the logic link, acquiring the connection relation of each code block according to the calling relation of the function in the logic link, and generating a theoretical execution link of the program source code according to the code identification of the code block and the connection relation;
inserting a record identifier for recording the running information of each code block in each code block of the program source code;
obtaining a test case combination of which an actual execution link is matched with the theoretical execution link from a pre-constructed test case library, wherein the test case library comprises a plurality of test cases and the actual execution link corresponding to the test cases, and the actual execution link is obtained by recording the test cases in the process of executing test tasks of historical program source codes;
calling the program source code inserted with the record identifier to test each test case in the test case combination, acquiring the running information of the corresponding code block recorded by each record identifier, and generating a test result of the program source code according to the running information of each test case;
The method further comprises the steps of after the test case combination that the actual execution link is matched with the theoretical execution link is obtained from a pre-constructed test case library:
if the theoretical execution link cannot successfully acquire the matched actual execution link, generating a test case generation request of the theoretical execution link;
receiving an input test case corresponding to the theoretical execution link, adding a new label to the test case, and adding the test case carrying the new label to the test case combination;
the method comprises the steps of calling the program source code inserted with the record identifier to test each test case in the test case combination, obtaining the running information of the corresponding code block recorded by each record identifier, and generating a test result of the program source code according to the running information of each test case, and then further comprises the following steps:
generating an actual execution link and an actual execution duration of the test case according to the running information of the test case carrying the newly-added label;
and deleting the newly added label of the test case, and storing the test case and the corresponding actual execution link into a test case library.
2. The code testing method according to claim 1, wherein the dividing the program source code into a plurality of code blocks according to each function in the logical link, obtaining a connection relationship of each code block according to a calling relationship of the function in the logical link, and generating a theoretical execution link of the program source code according to a code identifier of the code block and the connection relationship includes:
dividing the program source code into a plurality of code blocks according to each function in the logic link;
comparing the code blocks with each unit code in a preset code warehouse, and determining the unit code matched with the code blocks according to the comparison result;
acquiring a code identifier of the unit code in a code warehouse, and taking the code identifier as a code identifier of a code block;
acquiring the connection relation of each code block according to the calling relation of the function in the logic link;
and generating a theoretical execution link of the program source code according to the code identification of the code block and the connection relation.
3. The code testing method of claim 1, wherein the library of test cases is constructed as follows:
Acquiring a logic link of a first program source code, wherein the logic link comprises a plurality of function functions and calling relations of the function functions;
dividing the first program source code into a plurality of code blocks according to each function in the logic link, acquiring the connection relation of each code block according to the calling relation of the function in the logic link, and generating a theoretical execution link of the first program source code according to the code blocks and the connection relation;
inserting a record identifier for recording the running information of each code block in the first program source code;
acquiring a pre-edited test case, calling the first program source code inserted with the record identifier to test the test case, acquiring running information of the corresponding code blocks recorded by each record identifier, and generating an actual execution link and an actual execution duration of the test case according to the running information;
and storing the test cases and the corresponding actual execution links into a test case library.
4. The code testing method according to claim 3, wherein the obtaining, from a pre-built test case library, a test case combination in which an actual execution link matches the theoretical execution link, includes:
Comparing the theoretical execution links of the program source codes with actual execution links stored in a pre-built test case library respectively to obtain actual execution links matched with the theoretical execution links;
if the number of the matched actual execution links is a plurality of, acquiring the actual execution duration of each actual execution link, and selecting the actual execution link with the minimum actual execution duration;
and obtaining the test cases matched with the program source codes according to the actual execution link, and generating the test case combination.
5. The code testing method according to claim 1, wherein the obtaining the logical link of the program source code to be tested includes:
analyzing the program source code to be tested to generate an abstract syntax tree of the program source code;
accessing the abstract syntax tree to obtain a function corresponding to each symbol on the abstract syntax tree;
accessing the abstract syntax tree to obtain calling nodes of the function functions, and recording calling relations among the function functions;
and generating a logic link of the program source code according to the function and the calling relation of the function.
6. A code testing apparatus, comprising:
the analysis module is used for acquiring a logic link of a program source code to be tested, wherein the logic link comprises a plurality of function functions and calling relations of the function functions;
the link generation module is used for dividing the program source code into a plurality of code blocks according to each function in the logic link, acquiring the connection relation of each code block according to the calling relation of the function in the logic link, and generating a theoretical execution link of the program source code according to the code identification of the code block and the connection relation;
the instrumentation module is used for inserting a record identifier for recording the running information of each code block in each code block of the program source code;
the matching module is used for acquiring a test case combination of which the actual execution link is matched with the theoretical execution link from a pre-constructed test case library, wherein the test case library comprises a plurality of test cases and the actual execution link corresponding to the test cases, and the actual execution link is obtained by recording the test cases in the process of being used for executing the test tasks of the historical program source codes;
The test module is used for calling the program source code inserted with the record identifier to test each test case in the test case combination, acquiring the running information of the code block corresponding to each record identifier record, and generating a test result of the program source code according to the running information of each test case;
wherein, the matching module is further used for: if the theoretical execution link cannot successfully acquire the matched actual execution link, generating a test case generation request of the theoretical execution link; receiving an input test case corresponding to the theoretical execution link, adding a new label to the test case, and adding the test case carrying the new label to the test case combination;
the matching module is also used for: generating an actual execution link and an actual execution duration of the test case according to the running information of the test case carrying the newly-added label; and deleting the newly added label of the test case, and storing the test case and the corresponding actual execution link into a test case library.
7. An electronic device comprising a processor, and a memory coupled to the processor, the memory storing program instructions executable by the processor; the processor, when executing the program instructions stored in the memory, implements the code testing method of any one of claims 1-5.
8. A computer readable storage medium, characterized in that the computer readable storage medium has stored therein program instructions, which when executed by a processor implement the code testing method according to any of claims 1-5.
CN202111087190.1A 2021-09-16 2021-09-16 Code testing method and device, electronic equipment and storage medium Active CN113778890B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111087190.1A CN113778890B (en) 2021-09-16 2021-09-16 Code testing method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111087190.1A CN113778890B (en) 2021-09-16 2021-09-16 Code testing method and device, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN113778890A CN113778890A (en) 2021-12-10
CN113778890B true CN113778890B (en) 2023-06-30

Family

ID=78851403

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111087190.1A Active CN113778890B (en) 2021-09-16 2021-09-16 Code testing method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN113778890B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116126736B (en) * 2023-04-17 2023-07-07 青岛青软晶尊微电子科技有限公司 Chip code optimization method based on user requirements
CN116909627B (en) * 2023-09-13 2023-12-12 杭州笨马网络技术有限公司 Executable program analysis method and device, electronic equipment and storage medium

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101241466A (en) * 2007-02-08 2008-08-13 深圳迈瑞生物医疗电子股份有限公司 Embedded software test method and system
CN109062809A (en) * 2018-09-20 2018-12-21 北京奇艺世纪科技有限公司 Method for generating test case, device and electronic equipment on a kind of line
US10162966B1 (en) * 2016-10-19 2018-12-25 Trend Micro Incorporated Anti-malware system with evasion code detection and rectification
CN110413506A (en) * 2019-06-19 2019-11-05 平安普惠企业管理有限公司 Test case recommended method, device, equipment and storage medium
EP3654215A1 (en) * 2018-11-15 2020-05-20 Sternum Ltd. Applying control flow integrity verification in intermediate code files
CN112559363A (en) * 2020-12-23 2021-03-26 平安银行股份有限公司 Test case generation method, system, equipment and medium based on full link marking
CN112905443A (en) * 2019-12-04 2021-06-04 阿里巴巴集团控股有限公司 Test case generation method, device and storage medium

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050223361A1 (en) * 2004-04-01 2005-10-06 Belbute John L Software testing based on changes in execution paths
US20210191845A1 (en) * 2019-12-23 2021-06-24 Ab Initio Technology Llc Unit testing of components of dataflow graphs

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101241466A (en) * 2007-02-08 2008-08-13 深圳迈瑞生物医疗电子股份有限公司 Embedded software test method and system
US10162966B1 (en) * 2016-10-19 2018-12-25 Trend Micro Incorporated Anti-malware system with evasion code detection and rectification
CN109062809A (en) * 2018-09-20 2018-12-21 北京奇艺世纪科技有限公司 Method for generating test case, device and electronic equipment on a kind of line
EP3654215A1 (en) * 2018-11-15 2020-05-20 Sternum Ltd. Applying control flow integrity verification in intermediate code files
CN110413506A (en) * 2019-06-19 2019-11-05 平安普惠企业管理有限公司 Test case recommended method, device, equipment and storage medium
CN112905443A (en) * 2019-12-04 2021-06-04 阿里巴巴集团控股有限公司 Test case generation method, device and storage medium
CN112559363A (en) * 2020-12-23 2021-03-26 平安银行股份有限公司 Test case generation method, system, equipment and medium based on full link marking

Also Published As

Publication number Publication date
CN113778890A (en) 2021-12-10

Similar Documents

Publication Publication Date Title
CN113778890B (en) Code testing method and device, electronic equipment and storage medium
CN104657140B (en) Code generating method and device
CN106326107B (en) Non-intrusion type embedded software abnormal based on simulated environment handles verification method
CN111756575B (en) Performance analysis method and device of storage server and electronic equipment
CN107015841B (en) Preprocessing method for program compiling and program compiling device
CN109992498B (en) Test case generation method and system and computer system
CN104794049B (en) Applied program testing method and device
CN106547520B (en) Code path analysis method and device
CN108399124A (en) Application testing method, device, computer equipment and storage medium
CN107080945B (en) Method and device for testing artificial intelligence behaviors in game and electronic equipment
CN110162457A (en) Test method, device, equipment and the storage medium of user interface
CN109783365A (en) Automated testing method, device, computer equipment and storage medium
CN113127314A (en) Method and device for detecting program performance bottleneck and computer equipment
CN108399125A (en) Automated testing method, device, computer equipment and storage medium
CN110889116B (en) Advertisement interception method and device and electronic equipment
CN112199261B (en) Application program performance analysis method and device and electronic equipment
CN112395199B (en) Distributed software instance testing method based on cloud computing and software development platform
CN118131006A (en) ATPG test vector simplifying method and device, storage medium and electronic device
CN109783837A (en) Emulator, analogue system, emulation mode and simulated program
CN117632620A (en) Management method and device for software radio equipment test
CN108874658A (en) A kind of sandbox analysis method, device, electronic equipment and storage medium
CN109582574A (en) A kind of code coverage statistical method, device, storage medium and terminal device
CN113778515B (en) Method and device for determining program package change information
CN115577363A (en) Detection method and device for deserialization utilization chain of malicious code
CN113010409B (en) Intelligent contract testing method and device, electronic equipment and storage medium

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