Program testing method, device and system and electronic equipment
By extracting the feature information of the target code branch and generating accurate test cases, the problem of low program testing accuracy in the prior art is solved, and higher code branch coverage testing accuracy and application stability are achieved.
Patent Information
- Application Number
- CN202510186795.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-20
- Publication Date
- 2025-06-06
AI Technical Summary
The prior art is difficult to ensure that all code branches in the application are tested comprehensively and accurately, resulting in low accuracy in program testing, which may lead to potential bugs in untested code branches that are not detected after the application is released.
By extracting the feature information of the target code branch, a comprehensive and accurate test case is generated, and after the test case is executed, a code branch coverage test report with high accuracy is generated to improve the accuracy of the code branch coverage test.
It effectively improves the accuracy of program testing and avoids potential bugs in untested code branches being discovered after the application is released, thereby improving user experience and improving application stability.
Smart Images

Figure CN120104493A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a program testing method, device, system and electronic equipment. Background Art
[0002] At present, in the process of application (i.e. software, such as iOS (an operating system) software, etc.) development, program testing (i.e. software testing) is a key link to ensure the quality of the application; however, related technologies often fail to ensure comprehensive and accurate testing of all code branches in the application, resulting in low accuracy of program testing, i.e., insufficient accuracy in detecting whether a code branch is covered, which may result in potential bugs (vulnerabilities) in untested code branches being discovered only after the application is released. Based on this, there is currently no good solution for improving the accuracy of program testing. Summary of the invention
[0003] In view of this, the embodiments of the present invention provide a program testing method, device, system and electronic device to solve the problems of low accuracy of program testing in related technologies; that is, the embodiments of the present invention can generate comprehensive and accurate test cases by extracting characteristic information of target code branches, and generate a more accurate code branch coverage test report after executing the test cases, which can effectively improve the accuracy of code branch coverage testing, that is, it can effectively improve the accuracy of detecting whether code branches are covered, thereby effectively improving the accuracy of program testing, and avoiding potential bugs in untested code branches from being discovered after the application is released, thereby improving user experience and enhancing application stability.
[0004] According to an aspect of an embodiment of the present invention, a program testing method is provided, the method comprising:
[0005] Acquire a target application, wherein the target application includes at least one target code branch;
[0006] Using the target application, constructing an abstract syntax tree, and extracting feature information of each target code branch in the at least one target code branch based on the abstract syntax tree;
[0007] Generate at least one test case corresponding to each target code branch based on the feature information of each target code branch;
[0008] At least one test case corresponding to each target code branch is executed to obtain test record data, and a code branch coverage test report is generated based on the test record data.
[0009] According to another aspect of an embodiment of the present invention, a program testing device is provided, the device comprising:
[0010] An acquisition unit, configured to acquire a target application, wherein the target application includes at least one target code branch;
[0011] A processing unit, configured to construct an abstract syntax tree using the target application, and extract feature information of each target code branch in the at least one target code branch based on the abstract syntax tree;
[0012] The processing unit is further configured to generate at least one test case corresponding to each target code branch based on the feature information of each target code branch;
[0013] The processing unit is further used to execute at least one test case corresponding to each target code branch, obtain test record data, and generate a code branch coverage test report based on the test record data.
[0014] According to another aspect of an embodiment of the present invention, an electronic device is provided, comprising a processor and a memory storing a program, wherein the program comprises instructions, which, when executed by the processor, enable the processor to perform the above-mentioned method.
[0015] According to another aspect of an embodiment of the present invention, a program testing system is provided. The program testing system includes at least one electronic device. The at least one electronic device is used to enable the program testing system to execute the above-mentioned method.
[0016] According to another aspect of an embodiment of the present invention, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable a computer to execute the above-mentioned method.
[0017] After acquiring the target application, the embodiment of the present invention can use the target application to construct an abstract syntax tree, and based on the abstract syntax tree, extract the characteristic information of each target code branch in at least one target code branch, and the target application includes at least one target code branch. Then, based on the characteristic information of each target code branch, at least one test case corresponding to each target code branch can be generated. Further, at least one test case corresponding to each target code branch can be executed to obtain test record data, and a code branch coverage test report can be generated based on the test record data. It can be seen that the embodiment of the present invention can generate comprehensive and accurate test cases through the extracted characteristic information of the target code branch, and generate a code branch coverage test report with high accuracy after executing the test case, which can effectively improve the accuracy of the code branch coverage test, that is, effectively improve the accuracy of detecting whether the code branch is covered, thereby effectively improving the accuracy of the program test, and avoiding the potential bugs existing in the untested code branch from being discovered after the application is released, thereby improving the user experience and improving the stability of the application. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Further details, features and advantages of the invention are disclosed in the following description of exemplary embodiments in conjunction with the accompanying drawings, in which:
[0019] Figure 1 A schematic flow chart of a program testing method according to an exemplary embodiment of the present invention is shown;
[0020] Figure 2 A schematic flow chart of another program testing method according to an exemplary embodiment of the present invention is shown;
[0021] Figure 3 A schematic block diagram of a program testing device according to an exemplary embodiment of the present invention is shown;
[0022] Figure 4 A block diagram of an exemplary electronic device that can be used to implement an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0023] Embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present invention. It should be understood that the drawings and embodiments of the present invention are only for exemplary purposes and are not intended to limit the scope of protection of the present invention.
[0024] It should be understood that the various steps described in the method embodiments of the present invention may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present invention is not limited in this respect.
[0025] The term "including" and its variations used in this document are open inclusions, that is, "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one other embodiment"; the term "some embodiments" means "at least some embodiments". Relevant definitions of other terms will be given in the following description. It should be noted that the concepts of "first", "second", etc. mentioned in the present invention are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0026] It should be noted that the modifications of "one" and "plurality" mentioned in the present invention are illustrative rather than restrictive, and those skilled in the art should understand that, unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0027] The names of the messages or information exchanged between multiple devices in the embodiments of the present invention are only used for illustrative purposes, and are not used to limit the scope of these messages or information.
[0028] It should be noted that the execution subject of the program testing method provided in the embodiment of the present invention may be one or more electronic devices, which is not limited in the embodiment of the present invention; wherein, the electronic device may be a terminal (i.e., a client) or a server, then when the execution subject includes multiple electronic devices, and the multiple electronic devices include at least one terminal and at least one server, the program testing method provided in the embodiment of the present invention may be jointly executed by the terminal and the server. Accordingly, the terminals mentioned here may include but are not limited to: smart phones, tablet computers, laptop computers, desktop computers, intelligent voice interaction devices, and the like. The server mentioned here may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud services, cloud databases, cloud computing (cloud computing), cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and basic cloud computing services such as big data and artificial intelligence platforms, and the like.
[0029] Based on this, an embodiment of the present invention may provide a program testing system, which may include at least one electronic device (ie, one or more electronic devices). Then, the program testing system may execute a program testing method through the at least one electronic device included.
[0030] Based on the above description, an embodiment of the present invention proposes a program testing method, which can be executed by the electronic device (terminal or server) mentioned above, that is, it can be executed by the electronic device included in the program testing system; or, the program testing method can be executed by the terminal and the server together, such as the electronic device in the program testing system can include the terminal and the server. For the sake of convenience, the following description will be given by taking the electronic device executing the program testing method as an example; Figure 1 As shown, the program testing method may include the following steps S101-S104:
[0031] S101, obtaining a target application, where the target application includes at least one target code branch.
[0032] The target application may be an application of the target application; optionally, the target application may be any application, which is not limited in the embodiment of the present invention. Alternatively, the target application may be an iOS application, or an Android application, etc., which is not limited in the embodiment of the present invention. Optionally, for the sake of convenience, the following description will be based on the example that the target application is an iOS application.
[0033] Optionally, the target application may be obtained in a manner including but not limited to at least one of the following:
[0034] The first acquisition method: the target application's application program may be stored in the electronic device's own storage space. In this case, the electronic device may obtain the target application's application program from its own storage space and use the target application's application program as the target application program to achieve acquisition of the target application program.
[0035] The second acquisition method: the electronic device may acquire a program download link of the target application. In this case, the electronic device may download the target application based on the program download link of the target application to acquire the target application.
[0036] The third acquisition method: When the electronic device detects that the user has performed an application update and / or modification operation on the target application, it can obtain the current application of the target application, thereby detecting that the application of the target application has been updated; accordingly, when it is detected that the application of the target application has been updated, the current application of the target application can be used as the target application, thereby triggering the execution of the following use of the target application, building an abstract syntax tree, etc. Based on this, the electronic device can analyze the code branch coverage of different versions of applications and implement differential analysis technology; that is, when the code (i.e., the application) is updated, the newly introduced code branches and the original code branches that may be affected can be quickly determined (i.e., at least one current target code branch can be quickly determined), so that the test cases can be adjusted in time for retesting to ensure the integrity of code coverage.
[0037] S102, using the target application to construct an abstract syntax tree, and based on the abstract syntax tree, extracting feature information of each target code branch in at least one target code branch.
[0038] Optionally, the electronic device may include a code parsing module, that is, the program testing system may include a code parsing module; in this case, the target application may be parsed by the code parsing module to obtain a program parsing result. Exemplarily, when the target application is an iOS application, the target application may include Objective-C (an object-oriented programming language that extends C) and / or Swift (a new programming language used to write iOS and other applications) code. In this case, the Objective-C and / or Swift code in the source code of the iOS application may be parsed by the code parsing module; optionally, the electronic device may perform in-depth parsing of the iOS code through the target compiler front-end technology (such as Clang parser) to accurately handle the mixed programming of Objective-C and Swift through customized parsing rules, such as when parsing code that contains both Objective-C classes and Swift extensions, the code structure and logical relationship can be correctly identified, that is, the Objective-C class can be parsed according to the parsing rules corresponding to the Objective-C class, and the Swift code can be parsed according to the parsing rules corresponding to the Swift code.
[0039] Optionally, the code patterns of commonly used frameworks and libraries in iOS development (such as UIKit (a framework for providing infrastructure), Foundation (a front-end framework), etc.) can be optimized and parsed, and the special syntax and idioms in these frameworks can be familiar to improve the accuracy and efficiency of code parsing. For example, for the parsing of complex view hierarchies and event handling codes in UIKit, code branch information can be accurately extracted; and / or, part of the code built by commonly used frameworks and / or libraries (i.e., code written in specified code patterns) can be removed from the target application to improve efficiency. Optionally, the specified code pattern can be set according to experience or according to actual needs, which is not limited in the embodiments of the present invention; illustratively, the specified code pattern can be the code pattern of commonly used frameworks and libraries.
[0040] Based on this, the electronic device can identify various statement structures in the target application; that is, through lexical analysis and syntax analysis technology, it can identify various statement structures in the target application, such as if-else statements, switch-case statements, for loops, while loops, function and method calls, etc. For example, for a method containing a complex if-else nested structure, the code parsing module can accurately identify the start and end positions of each conditional branch and the conditional expression, etc.
[0041] Furthermore, the electronic device may use the program parsing result to construct an Abstract Syntax Tree (AST) to implement the use of a target application to construct an abstract syntax tree, thereby representing the code logic in a hierarchical structure. Optionally, the electronic device may construct an abstract syntax tree through a code parsing module, that is, the target application may be used to construct an abstract syntax tree through the code parsing module. Optionally, the electronic device may also extract feature information of each target code branch in at least one target code branch based on the abstract syntax tree through the code parsing module. Optionally, a target code branch may refer to a code branch whose statement structure is a target statement structure.
[0042] S103, generating at least one test case corresponding to each target code branch based on the feature information of each target code branch.
[0043] Optionally, the characteristic information of a target code branch may also be referred to as the code branch information of the corresponding target code branch. Optionally, the characteristic information of a target code branch may include but is not limited to at least one of the following: the branch condition of the corresponding target code branch (such as if, for, etc., or the entire branch condition statement (such as a statement containing fields such as if or for), etc.), variable information (which can be used to indicate the variables (i.e., function parameters) involved in the corresponding target code branch) and data types (which can be used to indicate the data types of the variables involved in the corresponding target code branch), etc.; the embodiment of the present invention does not limit this. Optionally, a variable information can be the variable name of the corresponding variable, or the variable number of the corresponding variable, etc., which is not limited by the embodiment of the present invention. Exemplarily, for the conditional branch (i.e., the target code branch) if (username.length>0&&password.length>0), the variable information of the target code branch may include username and password.
[0044] S104, executing at least one test case corresponding to each target code branch, obtaining test record data, and generating a code branch coverage test report based on the test record data.
[0045] Among them, the above-mentioned test record data may include the test record of each test case in at least one test case corresponding to each target code branch. Optionally, the test record of a test case may include but is not limited to: the execution path indication information of the corresponding test case (which can be used to indicate the execution path) and / or the case execution result, etc.; the embodiment of the present invention is not limited to this. Optionally, the case execution result of a test case may include but is not limited to at least one of the following: the execution result identifier of the corresponding test case (which can be an execution success identifier (used to indicate successful execution) or an execution failure identifier (used to indicate unsuccessful execution), to indicate whether it is successfully executed), a code branch test identifier (which can be a code branch coverage identifier (used to indicate that the code branch is covered) or a code branch non-coverage identifier (used to indicate that the code branch is not covered), to indicate whether the expected code branch (i.e., the corresponding code branch) is covered (i.e., triggered), etc., and the embodiment of the present invention is not limited to this. Exemplarily, when executing a test case involving a network request, it is possible to record whether the network request is successful, whether the related callback method is correctly called, and whether the code branch involved is covered. At this time, the case execution result of a test case may also include a network request indication mark (which may be a network request success mark (used to indicate that the network request is successful) or a network request failure mark (used to indicate that the network request fails), to indicate whether the network request is successful) and a call indication mark of the corresponding callback method (which may be a correct call mark (used to indicate that it is correctly called) or an incorrect call mark (used to indicate that it is not correctly called), to indicate whether the corresponding callback method is correctly called), etc. Optionally, the execution success mark, the execution failure mark, the code branch coverage mark, the code branch non-coverage mark, the network request success mark, the network request failure mark, the correct call mark, the incorrect call mark, the etc. can all be set according to experience or according to actual needs, and the embodiments of the present invention do not limit this. Optionally, when a test case is successfully executed, it can be determined that the code branch corresponding to the corresponding test case is covered, and so on.
[0046] Optionally, when any test case encounters an abnormal situation during the test case execution process (such as application crash, timeout, etc.), the test case execution result of any test case may also include the exception information of any test case. The exception information of any test case may include but is not limited to at least one of the following: the location where the exception occurs during the test case execution process of any test case (which may include but is not limited to the number of code lines and / or method names, etc.) and the exception type (such as memory leak, null pointer exception, etc.), etc. The embodiment of the present invention is not limited to this.
[0047] Optionally, the electronic device may include a test execution module, which may be a real or simulated iOS device environment; based on this, the electronic device may execute at least one test case corresponding to each target code branch through the test execution module, that is, the embodiment of the present invention may execute the generated test case in a real or simulated iOS device environment, that is, the electronic device may be a real or simulated iOS device to execute at least one test case corresponding to each target code branch. Optionally, the electronic device may be integrated with the test framework of Xcode (a complete developer tool set), and may also include a third-party test execution tool to execute at least one test case corresponding to each target code branch, and so on; the embodiment of the present invention is not limited to this.
[0048] After acquiring the target application, the embodiment of the present invention can use the target application to construct an abstract syntax tree, and based on the abstract syntax tree, extract the characteristic information of each target code branch in at least one target code branch, and the target application includes at least one target code branch. Then, based on the characteristic information of each target code branch, at least one test case corresponding to each target code branch can be generated. Further, at least one test case corresponding to each target code branch can be executed to obtain test record data, and a code branch coverage test report can be generated based on the test record data. It can be seen that the embodiment of the present invention can generate comprehensive and accurate test cases through the extracted characteristic information of the target code branch, and generate a code branch coverage test report with high accuracy after executing the test case, which can effectively improve the accuracy of the code branch coverage test, that is, effectively improve the accuracy of detecting whether the code branch is covered, thereby effectively improving the accuracy of the program test, and avoiding the potential bugs existing in the untested code branch from being discovered after the application is released, thereby improving the user experience and improving the stability of the application.
[0049] Based on the above description, the embodiment of the present invention also proposes another program testing method. Accordingly, the program testing method can be executed by the electronic device (terminal or server) mentioned above, that is, it can be executed by the electronic device included in the program testing system; or, the program testing method can be executed by the terminal and the server together, such as the electronic device in the program testing system can include the terminal and the server. For the convenience of explanation, the following description will be given by taking the electronic device executing the program testing method as an example; please refer to Figure 2 , the program testing method may include the following steps S201-S207:
[0050] S201, obtaining a target application, where the target application includes at least one target code branch.
[0051] S202, using the target application to construct an abstract syntax tree, and based on the abstract syntax tree, extracting feature information of each target code branch in at least one target code branch.
[0052] Optionally, when extracting characteristic information of each target code branch in at least one target code branch based on an abstract syntax tree, the electronic device may determine at least one target statement structure indicator; and based on the abstract syntax tree and at least one target statement structure indicator, determine at least one target code branch, the statement structure of a target code branch is the target statement structure indicated by one of the at least one target statement structure indicator; based on this, characteristic information of each target code branch in at least one target code branch may be extracted from the abstract syntax tree. Among them, a target statement structure indicator may be used to indicate a target statement structure (such as a for loop, etc.); optionally, a target statement structure indicator may be a statement structure type of a target statement structure (such as if or for, etc.), or may be a number of a corresponding statement structure, etc., which is not limited in the embodiment of the present invention. Optionally, at least one target statement structure indicator may be set according to experience or according to actual needs, which is not limited in the embodiment of the present invention; in other words, at least one target statement structure indicated by at least one target statement structure indicator may be set according to experience or according to actual needs, which is not limited in the embodiment of the present invention.
[0053] For example, assuming that the target statement structure indicated by a target statement structure indicator is an if-else statement, then based on the abstract syntax tree, all code branches starting with if can be used as target code branches, etc. For example, in a method for processing user login, the conditional branch if(username.length>0&&password.length>0) and the username and password variable information therein can be parsed.
[0054] S203: Generate at least one test case corresponding to each target code branch based on the feature information of each target code branch.
[0055] Optionally, for any target code branch in at least one target code branch, based on the characteristic information of any target code branch, the variable information and at least one execution condition in any target code branch are determined; and according to the variable information and at least one execution condition in any target code branch, at least one test case corresponding to any target code branch is generated; wherein, a test case corresponding to any target code branch includes the value of the variable indicated by the variable information in any target code branch under an execution condition in any target code branch. Optionally, the characteristic information of a target code branch may also include at least one execution condition in the corresponding target code branch; optionally, the execution condition in a target code branch may be located in the branch condition (such as the execution condition may be included when the branch condition is the entire branch condition statement), or may not be located in the branch condition, which is not limited in the embodiment of the present invention. Optionally, a test case corresponding to any target code branch may also include the variable information in any target code branch, and so on; this is not limited in the embodiment of the present invention.
[0056] Optionally, an execution condition of a target code branch may represent the variable range (i.e., value range) of the variable indicated by the variable information in the corresponding target code branch (i.e., each variable in the corresponding target code branch). For example, the above-mentioned execution condition username.length>0 may represent that the variable range of the variable username is any value (e.g., any string, etc.) whose length is greater than 0; based on this, when the value of a variable in a target code branch meets an execution condition in the corresponding target code branch, the code branch under the corresponding execution condition may be executed through the corresponding value of the variable. Optionally, a variable range may be a continuous variable range, or a discrete variable range, etc., which is not limited in the embodiment of the present invention. Based on this, the value of a variable under an execution condition may be a numerical value, or a string, etc., which is not limited in the embodiment of the present invention. Optionally, a target code branch may include at least one code branch, that is, it may include code branches under each execution condition in the corresponding target code branch, and so on.
[0057] Optionally, at least one test case corresponding to any target code branch may include test cases for each execution condition of at least one execution condition of any target code branch in any code branch (i.e., test cases for each execution condition of the variable indicated by the variable information in any target code branch in any target code branch), and the test case under any execution condition in any target code branch may include at least one value of the variable indicated by the variable information in any target code branch under any of the execution conditions, i.e., the number of test cases under any execution condition in any target code branch may be one or more, which is not limited to this in the embodiments of the present invention.
[0058] Based on this, for any execution condition in any target code branch, the electronic device can generate a test case for any target code branch under any execution condition according to the variable information in any target code branch and any execution condition, so as to realize the generation of at least one test case corresponding to any target code branch. Optionally, the electronic device can generate at least one value of the variable indicated by the variable information in any target code branch (i.e., each indicated variable) under any execution condition according to the variable information in any target code branch and any execution condition, so as to realize the generation of a test case for any target code branch under any execution condition (i.e., at least one test case, a test case for any target code branch under any execution condition may include a value of the variable indicated by the variable information in any target code branch (i.e., each indicated variable) under any execution condition); optionally, a value of a variable under one execution condition may be a value of the corresponding variable within the variable range indicated by the corresponding execution condition. It should be understood that when there are multiple variables in any target code branch, a value of a variable indicated by the variable information in any target code branch under any execution condition may include a value of each variable in any target code branch under any execution condition, and any execution condition in any target code branch may represent the variable range of each variable in any target code branch.
[0059] Based on this, for any target code branch, at least one targeted test case can be generated to ensure that the target code branch can be executed. Optionally, for any target code branch in at least one target code branch and any execution condition in any target code branch, the electronic device can also generate a test case for any target code branch under any execution condition according to the variable range outside the variable range indicated by any execution condition. At this time, a value of the corresponding variable in the generated test case under any execution condition can be a value of the corresponding variable within the variable range outside the variable range indicated by any execution condition, that is, a value of a variable under an execution condition can also be a value of the corresponding variable outside the variable range indicated by the corresponding execution condition, and so on. For example, for a conditional branch in a login method (such as if (username.length>0&&password.length>0)), a test case can be generated in which both username and password have legal values, as well as a test case that makes username or password empty, and so on.
[0060] Optionally, the electronic device can generate a test case for any target code branch under any execution condition according to the variable information and any execution condition in any target code branch through at least one test case generation strategy (such as boundary value analysis, equivalence class partitioning, etc.). Optionally, at least one test case generation strategy can be set according to experience or according to actual needs, which is not limited in the embodiments of the present invention. Exemplarily, for variables of numerical type, the minimum value, maximum value, slightly less than the minimum value, and slightly greater than the maximum value indicated by the corresponding variable range can be considered in the boundary value analysis; for example, for a method branch that accepts age input, test cases for boundary value situations such as age 0, 18 (legal adult age), and 200 (a larger value) can be generated.
[0061] Optionally, the electronic device may also expand at least one test case corresponding to any target code branch according to at least one test factor, thereby updating at least one test case corresponding to any target code branch; optionally, in combination with the characteristics of the platform (such as when the target application is an iOS application, it may be the iOS platform here), at least one test factor may include but is not limited to factors such as different device types (such as mobile phones, tablets, etc.), different system versions, and different language environments, which are not limited in the embodiments of the present invention. Exemplarily, for any target code branch involving localized string display, test cases in different language environments (such as English, Chinese, etc.) may be generated.
[0062] Optionally, the electronic device may include a test case generation module. In this case, the test case generation module may generate at least one test case corresponding to each target code branch based on the feature information of each target code branch. Optionally, a test case corresponding to a target code branch may also include variable information in the corresponding target code branch, etc.; this is not limited in the embodiment of the present invention.
[0063] S204, executing at least one test case corresponding to each target code branch, obtaining test record data, and generating a code branch coverage test report based on the test record data.
[0064] Optionally, at least one monitoring code is embedded in the target application, and a monitoring code can be used to monitor the execution path of the test case. The test record data may include the execution path indication information of each test case, and an execution path indication information can be used to indicate the execution path of a test case; and / or, the test record data includes system performance indication data when each test case is executed. Optionally, a monitoring code can be a lightweight monitoring code (such as using runtime technology to insert monitoring code before and after key method calls), which tracks the execution path of the test case in real time. These monitoring codes have little impact on application performance, but can accurately record the execution of each test case, such as recording execution information at each function entry and exit; Optionally, an execution path indication information may include but is not limited to function parameters, return values, and function names corresponding to a test case, etc., which are not limited in the embodiment of the present invention. Based on this, the embodiment of the present invention can conveniently restore the execution path of the corresponding test case through the execution path indication information of a test case.
[0065] Optionally, the electronic device may also integrate debugging and performance analysis tools (such as Instruments (a debugging and performance analysis tool that can be used for iOS systems)) to obtain more comprehensive test execution data, such as memory usage, CPU (Central Processing Unit) usage, etc. through debugging and performance analysis tools; that is, the system performance indicator data when a test case is executed may include but is not limited to memory usage, CPU usage, etc., which is not limited in the embodiment of the present invention. Based on this, the relationship between the test record data and the code branch coverage can be further analyzed to generate a code branch coverage test report to discover potential performance problems and test coverage loopholes.
[0066] Optionally, in other embodiments, the electronic device may also send at least one test case corresponding to each target code branch to other electronic devices in the program testing system, so that the other electronic devices execute at least one test case corresponding to each target code branch, obtain test record data, and generate a code branch coverage test report based on the test record data, etc.; the present invention is not limited to this.
[0067] Optionally, when generating a code branch coverage test report based on the test record data, the electronic device may use an abstract syntax tree to determine the target graph structure, and traverse the target graph structure (i.e., traverse each node in the target graph structure) through a graph traversal algorithm, so that the currently traversed node is used as the current node, and a node (i.e., a node in the target graph structure) can be used to indicate a code branch. Optionally, the electronic device may use a code branch indicated by the abstract syntax tree as a node of the target graph structure to determine the target graph structure using the abstract syntax tree; optionally, conditional judgments and loop structures may be used as edges in the target graph structure, or the edges between the code branches in the abstract syntax tree may be used as edges in the target graph structure, and so on. Based on this, the embodiment of the present invention may represent the abstract syntax tree and the test case execution path as a graph structure. Optionally, the electronic device may traverse the target graph structure according to a depth-first search, or may traverse the target graph structure according to a breadth-first search, and so on; the embodiment of the present invention is not limited to this.
[0068] Based on this, the electronic device can determine whether the current node is accessed during the execution of the test case based on the test record data; if the current node is accessed, the code branch indicated by the current node is used as the covered code branch. Optionally, for any test case involved in the test record data, if the code branch corresponding to any test case is the code branch indicated by the current node, and the case execution result of any test case indicates that the code branch corresponding to any test case is covered, it can be determined whether the current node is accessed during the execution of the test case, and then the code branch indicated by the current node is used as the covered code branch.
[0069] Further, after traversing the target graph structure, the electronic device may generate a code branch coverage test report based on all covered code branches in at least one target code branch. Optionally, the electronic device may use the ratio of the number of all covered code branches in at least one target code branch to the total number of all code branches in at least one target code branch as the code branch coverage rate, so as to add the code branch coverage rate to the code branch coverage test report. Optionally, the electronic device may also add the test record data to the code branch coverage test report; and / or, the display information of all uncovered code branches may be determined from the test record data (including but not limited to the class, method and conditional expression, etc., such as determining the corresponding display information from the execution path indication information), and the display information of all uncovered code branches is added to the code branch coverage test report; and / or, the code branch coverage may be displayed in a visual manner, that is, the code branch coverage of the target application may be displayed in a graphical manner (such as a code map, a flowchart, etc.), and the coverage of each target code branch may be visualized to obtain a graphical display result, thereby adding the graphical display result to the code branch coverage test report, so as to realize a graphical display of the code branch coverage of at least one target code branch, so that developers can intuitively understand which areas of the code need further testing, etc.; the embodiment of the present invention is not limited to this. For example, the positions of covered and uncovered code branches on the code map may be marked with different colors, or the branch coverage in each method may be displayed in the form of a flowchart, etc.
[0070] Optionally, the electronic device may further include a coverage analysis module. In this case, the coverage analysis module may generate a code branch coverage test report based on the test record data.
[0071] S205, when the code branch coverage is less than a preset code branch coverage threshold, generating an updated test case set based on at least one test case corresponding to each target code branch.
[0072] Optionally, the preset code branch coverage threshold may be set according to experience or according to actual needs, which is not limited in the embodiments of the present invention; illustratively, the preset code branch coverage threshold may be 100%, and so on.
[0073] Optionally, the electronic device can generate an updated test case set based on at least one test case corresponding to each target code branch based on machine learning and data mining technology. Based on this, the embodiment of the present invention can discover the potential patterns and rules between code branches and effective test cases by analyzing a large amount of data; for example, for a specific type of algorithm logic (such as a sorting algorithm), its code branch execution under different data inputs can be learned, thereby generating more optimized test cases for new similar code branches. Optionally, the machine learning and data mining technology can be a neural network algorithm, or a decision tree algorithm, etc., which is not limited by the embodiment of the present invention.
[0074] In one embodiment, when generating an updated test case set based on at least one test case corresponding to each target code branch, the electronic device may generate a program test data set based on at least one test case corresponding to each target code branch, and one program test data may include a value of each variable in each target code branch and / or code branch coverage; based on this, the target neural network model may be called to generate updated program test data corresponding to each program test data in the program test data set (that is, each program test data may be input into the target neural network model respectively to generate updated program test data corresponding to each program test data), so that the updated program test data corresponding to each program test data may be generated based on the updated program test data corresponding to each program test data. The update program test data determines the pending test cases corresponding to each target code branch. The pending test cases corresponding to a target code branch may include a pending value of a variable in the corresponding target code branch (i.e., a value that does not exist in at least one test case corresponding to each target code branch). That is to say, the pending value of the variable in any target code branch can be determined from the update program test data corresponding to each program test data, so that the pending test case corresponding to any target code branch is determined by using the pending value of the variable in any target code branch; further, the pending test cases corresponding to each target code branch can be added to the update test case set to realize the generation of the update test case set. Optionally, an update program test data may include a value of each variable in each target code branch and / or an update coverage. Optionally, the pending value of a variable can be determined from the update program test data whose update coverage is greater than the code branch coverage, or can be determined from any update program test data, and so on; the embodiment of the present invention is not limited to this.
[0075] Optionally, the number of pending test cases corresponding to a target code branch may be H, where H may be a non-negative integer. It should be noted that the embodiment of the present invention does not limit the model architecture of the target neural network model; that is, the model architecture of the target neural network may be set according to experience or according to actual needs, and the embodiment of the present invention does not limit this. Optionally, the target neural network model may be obtained by model training the initial neural network model, that is, the initial neural network model may be trained using a historical test case set (such as a historical test case set of the target application) to obtain the target neural network model; illustratively, a historical program test data set may be generated through a historical test case set to generate updated program test data corresponding to each historical program test data through the current neural network model (such as the initial neural network model), thereby determining the loss value through the difference between the preset code branch coverage threshold and the update coverage rate to optimize the current neural network model until a convergence condition is reached (such as a loss value less than a preset loss threshold or the number of iterations reaches a preset number of iterations threshold, etc.), and so on.
[0076] In another embodiment, the electronic device may determine a target decision tree; optionally, the electronic device may determine the target decision tree through an abstract syntax tree so that the target decision tree can represent the relationship between each target code branch; based on this, the electronic device may determine untested branches from the target decision tree based on at least one test case corresponding to each target code branch (an untested branch may refer to a branch that does not meet the corresponding branch condition in at least one test case corresponding to each target code branch), thereby generating variable values under each untested branch, so as to generate an updated test case set through the variable values under each untested branch, and so on.
[0077] Optionally, in other embodiments, the electronic device may also execute the above again based on the characteristic information of each target code branch to generate an updated test case set, and the updated test case set may include test cases corresponding to each target code branch generated at this time, and so on.
[0078] Optionally, the electronic device can also symbolize the conditional expressions and variables in the target application to determine the set of test cases to be added, and add each test case to be added in the set of test cases to be added to the updated test case set, such as by combining symbolic execution technology to symbolize the conditional expressions and variables in the target application. Based on this, the electronic device can generate test cases to be added that can cover more code branches by solving symbolic expressions (i.e., symbolic execution technology) to determine the set of test cases to be added; illustratively, for a code branch containing a complex mathematical formula, the value range of the variables in the symbolic expression can be solved to generate targeted test cases (i.e., test cases to be added).
[0079] S206, updating the test case set to update at least one test case corresponding to each target code branch, and obtaining an updated test case corresponding to each target code branch.
[0080] In an embodiment of the present invention, the electronic device may adopt an updated test case set to expand the test cases corresponding to each target code branch, that is, determine a new test case corresponding to each target code branch from the updated test case set to update at least one test case corresponding to each target code branch, thereby obtaining an updated test case corresponding to each target code branch; based on this, the updated test case corresponding to any target code branch may include at least one test case corresponding to any target code branch and a new test case. Optionally, the number of new test cases corresponding to a target code branch may be G, where G is a non-negative integer.
[0081] S207, executing the updated test cases corresponding to each target code branch to obtain updated test record data, and generating an updated code branch coverage test report based on the updated test record data.
[0082] It should be noted that the method for determining updated test record data and updated code branch coverage test report is the same as the method for determining the above-mentioned test record data and code branch coverage test report, and the embodiment of the present invention will not be repeated here.
[0083] Optionally, the electronic device may use the updated code branch coverage test report as the code branch coverage test report, and use the updated test cases corresponding to each target code branch as at least one test case corresponding to each target code branch, to iteratively execute the above-mentioned when the code branch coverage is less than the preset code branch coverage threshold, based on at least one test case corresponding to each target code branch, to generate an updated test case set, etc., until the code branch coverage reaches the preset code branch coverage threshold. Based on this, the electronic device can output the current code branch coverage test report to guide developers in software development, that is, to guide developers to optimize the application program of the target application.
[0084] In summary, the embodiments of the present invention can be tightly integrated with the development environment (such as Xcode (an integrated development tool) involved in the iOS development environment) and commonly used development tools, so that testing work can be naturally integrated into the development process. Developers can obtain code branch coverage information in a timely manner, which facilitates timely adjustment and optimization of the code during the development process, thereby effectively optimizing the development process.
[0085] After acquiring the target application, the embodiment of the present invention can use the target application to construct an abstract syntax tree, and based on the abstract syntax tree, extract the characteristic information of each target code branch in at least one target code branch, thereby generating at least one test case corresponding to each target code branch based on the characteristic information of each target code branch. Based on this, at least one test case corresponding to each target code branch can be executed to obtain test record data, and a code branch coverage test report can be generated based on the test record data. Further, when the code branch coverage rate is less than the preset code branch coverage threshold, an updated test case set is generated based on at least one test case corresponding to each target code branch; and the updated test case set is used to update at least one test case corresponding to each target code branch to obtain an updated test case corresponding to each target code branch. Then, accordingly, the updated test case corresponding to each target code branch can be executed to obtain updated test record data, and an updated code branch coverage test report can be generated based on the updated test record data. It can be seen that the embodiment of the present invention can automatically generate test cases for all code branches of the target application, and accurately detect the coverage of each branch, effectively avoiding potential bugs caused by untested parts of the code, thereby achieving comprehensive code branch coverage; and, through intelligent test case generation algorithms and automated test execution and analysis processes, the time and workload of manually writing test cases and analyzing test results can be reduced, making the testing process more efficient and effectively improving testing efficiency; in addition, the embodiment of the present invention can ensure the accuracy of the test results through precise code parsing, test execution monitoring and coverage analysis technology, and can more promptly discover problems in the code, including logical errors, boundary condition problems, and problems related to iOS platform characteristics (the target application can be an iOS application in this case), etc., thereby effectively enhancing the accuracy of program testing.
[0086] Based on the description of the above-mentioned related embodiments of the program testing method, the embodiment of the present invention further proposes a program testing device, which can be a computer program (including program code) running in an electronic device; Figure 3 As shown, the program testing device may include an acquisition unit 301 and a processing unit 302. The program testing device may execute Figure 1 or Figure 2 The program testing method shown, that is, the program testing device can run the above units:
[0087] An acquisition unit 301 is used to acquire a target application, wherein the target application includes at least one target code branch;
[0088] The processing unit 302 is configured to construct an abstract syntax tree using the target application, and extract feature information of each target code branch in the at least one target code branch based on the abstract syntax tree;
[0089] The processing unit 302 is further configured to generate at least one test case corresponding to each target code branch based on the feature information of each target code branch;
[0090] The processing unit 302 is further configured to execute at least one test case corresponding to each target code branch, obtain test record data, and generate a code branch coverage test report based on the test record data.
[0091] In one implementation, when the processing unit 302 extracts feature information of each target code branch in the at least one target code branch based on the abstract syntax tree, it may be specifically configured to:
[0092] Determining at least one target sentence structure indicator;
[0093] Determine, based on the abstract syntax tree and the at least one target sentence structure indicator, the at least one target code branch, wherein the sentence structure of a target code branch is the target sentence structure indicated by one of the at least one target sentence structure indicator;
[0094] Feature information of each target code branch in the at least one target code branch is extracted from the abstract syntax tree.
[0095] In another implementation manner, when the processing unit 302 generates at least one test case corresponding to each target code branch based on the feature information of each target code branch, the processing unit 302 may be specifically configured to:
[0096] For any target code branch of the at least one target code branch, based on the feature information of the any target code branch, determining variable information and at least one execution condition in the any target code branch;
[0097] At least one test case corresponding to any target code branch is generated according to the variable information and at least one execution condition in any target code branch; wherein a test case corresponding to any target code branch includes the value of the variable indicated by the variable information in any target code branch under an execution condition in any target code branch.
[0098] In another implementation, the code branch coverage test report includes code branch coverage; the processing unit 302 may also be used to:
[0099] When the code branch coverage is less than a preset code branch coverage threshold, generating an updated test case set based on at least one test case corresponding to each target code branch;
[0100] Using the updated test case set, updating at least one test case corresponding to each target code branch, and obtaining updated test cases corresponding to each target code branch;
[0101] The updated test cases corresponding to the target code branches are executed to obtain updated test record data, and an updated code branch coverage test report is generated based on the updated test record data.
[0102] In another embodiment, at least one monitoring code is embedded in the target application, one monitoring code is used to monitor the execution path of the test case, the test record data includes execution path indication information of each test case, one execution path indication information is used to indicate the execution path of a test case; and / or, the test record data includes system performance indication data when each test case is executed.
[0103] In another implementation, when the processing unit 302 generates a code branch coverage test report based on the test record data, it can be specifically used to:
[0104] Determine a target graph structure using the abstract syntax tree, and traverse the target graph structure using a graph traversal algorithm, thereby taking a currently traversed node as a current node, where one node is used to indicate one code branch;
[0105] Based on the test record data, determine whether the current node is accessed during the test case execution process; if the current node is accessed, take the code branch indicated by the current node as a covered code branch;
[0106] After traversing the target graph structure, a code branch coverage test report is generated based on all covered code branches in the at least one target code branch.
[0107] In another implementation, the target application is an application of a target application; the processing unit 302 may also be used for:
[0108] When it is detected that the application program of the target application is updated, the current application program of the target application is used as the target application program, and the process of adopting the target application program to construct an abstract syntax tree is triggered and executed.
[0109] According to one embodiment of the present invention, Figure 3Each unit in the program testing device shown can be separately or completely merged into one or several other units to constitute, or some of the units can also be split into multiple smaller units in function to constitute, which can achieve the same operation without affecting the realization of the technical effect of the embodiment of the present invention. The above-mentioned units are divided based on logical functions. In practical applications, the function of one unit can also be realized by multiple units, or the function of multiple units can be realized by one unit. In other embodiments of the present invention, any program testing device can also include other units. In practical applications, these functions can also be assisted by other units to be realized, and can be realized by the collaboration of multiple units.
[0110] According to another embodiment of the present invention, the program can be executed by running a program on a general electronic device such as a computer including a central processing unit (CPU), a random access memory medium (RAM), a read-only memory medium (ROM), and other processing elements and storage elements. Figure 1 or Figure 2 A computer program (including program code) for each step involved in the corresponding method shown in Figure 3 The program testing device shown in and the program testing method of the embodiment of the present invention are implemented. The computer program can be recorded on a computer storage medium, for example, and loaded into the above electronic device through the computer storage medium and run therein.
[0111] After acquiring the target application, the embodiment of the present invention can use the target application to construct an abstract syntax tree, and based on the abstract syntax tree, extract the characteristic information of each target code branch in at least one target code branch, and the target application includes at least one target code branch. Then, based on the characteristic information of each target code branch, at least one test case corresponding to each target code branch can be generated. Further, at least one test case corresponding to each target code branch can be executed to obtain test record data, and a code branch coverage test report can be generated based on the test record data. It can be seen that the embodiment of the present invention can generate comprehensive and accurate test cases through the extracted characteristic information of the target code branch, and generate a code branch coverage test report with high accuracy after executing the test case, which can effectively improve the accuracy of the code branch coverage test, that is, effectively improve the accuracy of detecting whether the code branch is covered, thereby effectively improving the accuracy of the program test, and avoiding the potential bugs existing in the untested code branch from being discovered after the application is released, thereby improving the user experience and improving the stability of the application.
[0112] Based on the description of the above method embodiment and device embodiment, the exemplary embodiment of the present invention further provides an electronic device, including: at least one processor; and a memory connected to the at least one processor in communication. The memory stores a computer program that can be executed by the at least one processor, and the computer program is used to enable the electronic device to perform the method according to the embodiment of the present invention when executed by the at least one processor.
[0113] An exemplary embodiment of the present invention further provides a program testing system, wherein the program testing system includes at least one electronic device, and the at least one electronic device is used to enable the program testing system to execute the method according to the embodiment of the present invention.
[0114] Exemplary embodiments of the present invention also provide a non-transitory computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor of a computer, is used to cause the computer to perform a method according to an embodiment of the present invention.
[0115] An exemplary embodiment of the present invention further provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor of a computer, the computer is used to enable the computer to perform a method according to an embodiment of the present invention.
[0116] refer to Figure 4 , a block diagram of an electronic device 400 that can be used as a server or client of the present invention will now be described, which is an example of a hardware device that can be applied to various aspects of the present invention. The electronic device is intended to represent various forms of digital electronic computer devices, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0117] like Figure 4 As shown, the electronic device 400 includes a computing unit 401, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 402 or a computer program loaded from a storage unit 408 into a random access memory (RAM) 403. In the RAM 403, various programs and data required for the operation of the electronic device 400 can also be stored. The computing unit 401, the ROM 402, and the RAM 403 are connected to each other via a bus 404. An input / output (I / O) interface 405 is also connected to the bus 404.
[0118] A plurality of components in the electronic device 400 are connected to the I / O interface 405, including: an input unit 406, an output unit 407, a storage unit 408, and a communication unit 409. The input unit 406 may be any type of device capable of inputting information to the electronic device 400, and the input unit 406 may receive input digital or character information, and generate key signal inputs related to user settings and / or function control of the electronic device. The output unit 407 may be any type of device capable of presenting information, and may include, but is not limited to, a display, a speaker, a video / audio output terminal, a vibrator, and / or a printer. The storage unit 408 may include, but is not limited to, a disk, an optical disk. The communication unit 409 allows the electronic device 400 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks, and may include, but is not limited to, a modem, a network card, an infrared communication device, a wireless communication transceiver, and / or a chipset, such as a Bluetooth™ device, a WiFi device, a WiMax device, a cellular communication device, and / or the like.
[0119] The computing unit 401 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 401 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 401 performs the various methods and processes described above. For example, in some embodiments, the program testing method may be implemented as a computer software program, which is tangibly included in a machine-readable medium, such as a storage unit 408. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 400 via ROM 402 and / or a communication unit 409. In some embodiments, the computing unit 401 may be configured to execute the program testing method by any other appropriate means (e.g., by means of firmware).
[0120] The program code for implementing the method of the present invention can be written in any combination of one or more programming languages. These program codes can be provided to a processor or controller of a general-purpose computer, a special-purpose computer or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code can be executed entirely on the machine, partially on the machine, partially on the machine as a stand-alone software package and partially on a remote machine, or entirely on a remote machine or server.
[0121] In the context of the present invention, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0122] As used herein, the terms "machine-readable medium" and "computer-readable medium" refer to any computer program product, apparatus, and / or device (e.g., disk, optical disk, memory, programmable logic device (PLD)) for providing machine instructions and / or data to a programmable processor, including a machine-readable medium that receives machine instructions as a machine-readable signal. The term "machine-readable signal" refers to any signal for providing machine instructions and / or data to a programmable processor.
[0123] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0124] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0125] A computer system may include clients and servers. Clients and servers are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship to each other.
[0126] Furthermore, it should be understood that what is disclosed above is only a preferred embodiment of the present invention, and certainly cannot be used to limit the scope of rights of the present invention. Therefore, equivalent changes made according to the claims of the present invention are still within the scope of the present invention.
Claims
1. A program testing method, characterized in that: include: Acquire a target application, wherein the target application includes at least one target code branch; Using the target application, constructing an abstract syntax tree, and extracting feature information of each target code branch in the at least one target code branch based on the abstract syntax tree; Generate at least one test case corresponding to each target code branch based on the feature information of each target code branch; At least one test case corresponding to each target code branch is executed to obtain test record data, and a code branch coverage test report is generated based on the test record data.
2. The method according to claim 1, characterized in that The extracting feature information of each target code branch in the at least one target code branch based on the abstract syntax tree includes: Determining at least one target sentence structure indicator; Determine, based on the abstract syntax tree and the at least one target sentence structure indicator, the at least one target code branch, wherein the sentence structure of a target code branch is the target sentence structure indicated by one of the at least one target sentence structure indicator; Feature information of each target code branch in the at least one target code branch is extracted from the abstract syntax tree.
3. The method according to claim 1 or 2, characterized in that: The generating at least one test case corresponding to each target code branch based on the feature information of each target code branch respectively includes: For any target code branch of the at least one target code branch, based on the feature information of the any target code branch, determining variable information and at least one execution condition in the any target code branch; At least one test case corresponding to any target code branch is generated according to the variable information and at least one execution condition in any target code branch; wherein a test case corresponding to any target code branch includes the value of the variable indicated by the variable information in any target code branch under an execution condition in any target code branch.
4. The method according to claim 1 or 2, characterized in that: The code branch coverage test report includes code branch coverage; the method further includes: When the code branch coverage is less than a preset code branch coverage threshold, generating an updated test case set based on at least one test case corresponding to each target code branch; Using the updated test case set, updating at least one test case corresponding to each target code branch, and obtaining updated test cases corresponding to each target code branch; The updated test cases corresponding to the target code branches are executed to obtain updated test record data, and an updated code branch coverage test report is generated based on the updated test record data.
5. The method according to claim 1 or 2, characterized in that: The target application is embedded with at least one monitoring code, one monitoring code is used to monitor the execution path of the test case, the test record data includes execution path indication information of each test case, one execution path indication information is used to indicate the execution path of a test case; And / or, the test record data includes system performance indication data when each test case is executed.
6. The method according to claim 1 or 2, characterized in that: The generating a code branch coverage test report based on the test record data includes: Determine a target graph structure using the abstract syntax tree, and traverse the target graph structure using a graph traversal algorithm, thereby taking a currently traversed node as a current node, where one node is used to indicate one code branch; Based on the test record data, determine whether the current node is accessed during the test case execution process; if the current node is accessed, take the code branch indicated by the current node as a covered code branch; After traversing the target graph structure, a code branch coverage test report is generated based on all covered code branches in the at least one target code branch.
7. The method according to claim 1 or 2, characterized in that: The target application is an application of the target application; the method further includes: When it is detected that the application program of the target application is updated, the current application program of the target application is used as the target application program, and the process of adopting the target application program to construct an abstract syntax tree is triggered.
8. A program testing device, characterized in that: The device comprises: An acquisition unit, configured to acquire a target application, wherein the target application includes at least one target code branch; A processing unit, configured to construct an abstract syntax tree using the target application, and extract feature information of each target code branch in the at least one target code branch based on the abstract syntax tree; The processing unit is further configured to generate at least one test case corresponding to each target code branch based on the feature information of each target code branch; The processing unit is further used to execute at least one test case corresponding to each target code branch, obtain test record data, and generate a code branch coverage test report based on the test record data.
9. An electronic device, characterized in that: include: processor; as well as Memory for storing programs, The program includes instructions, which, when executed by the processor, cause the processor to perform the method according to any one of claims 1 to 7.
10. A program testing system, characterized in that: The program testing system comprises at least one electronic device; wherein the at least one electronic device is configured to enable the program testing system to execute the method according to any one of claims 1-7.