Precise testing method and device based on code change and test case mapping, equipment and medium
By establishing a mapping library between code changes and test cases, and using code coverage tools to record signature information and coverage, methods affected by code changes can be accurately identified. This solves the problems of low efficiency and insufficient accuracy in existing regression testing strategies, and achieves efficient and accurate regression testing.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SHANGHAI FOREIGN SERVICE ABROAD EMPLOYEE SERVICE CO LTD
- Filing Date
- 2026-04-09
- Publication Date
- 2026-07-10
AI Technical Summary
Existing regression testing strategies suffer from inefficiency and insufficient accuracy. In particular, in large-scale software development, full regression testing consumes a lot of resources, while selective regression testing is prone to missing key test cases.
By establishing a mapping library between code changes and test cases, using code coverage tools to record signature information and coverage, a mapping relationship is constructed to accurately identify methods affected by code changes, and target test cases are queried based on this.
It enables efficient and accurate regression testing, reduces resource waste, improves test quality and efficiency, and can automatically identify the cross-module impact of code changes.
Smart Images

Figure CN122364081A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of software testing technology, and in particular to a precise testing method, apparatus, equipment, and medium based on code change and test case mapping. Background Technology
[0002] As software scales up and iterates at an accelerated pace, regression testing plays an indispensable role in ensuring software quality and verifying that code modifications have not introduced new defects. Whether it's adding new features, fixing defects, or optimizing performance, regression testing is essential to verify the stability of existing functions, and its importance becomes increasingly prominent as software complexity rises.
[0003] Current mainstream regression testing strategies fall into two categories: full regression testing and selective regression testing. Both have significant technical drawbacks. Full regression testing requires executing the complete test case set after each code change. While this achieves maximum coverage, the time, computing, and human resource costs increase exponentially with software scale. In continuous integration / continuous delivery models that prioritize rapid feedback, this inefficiency is particularly pronounced, making it difficult to adapt to actual development needs. Selective regression testing, while reducing execution costs by selecting a test case set, suffers from strategic shortcomings: experience-based selection relies on subjective human judgment, resulting in poor consistency and reusability. It is prone to test omissions due to limitations in human understanding, potentially leading to higher quality risks. Code coverage-based selection relies solely on static, coarse-grained coverage associations, selecting all test cases covering modified files without distinguishing between specific changed lines of code and logical paths. This leads to high redundancy and insufficient accuracy in the test case set, and makes it difficult to identify the indirect cross-module impact of code changes, easily resulting in the omission of critical test cases.
[0004] Therefore, how to establish and maintain a mapping library between code changes and test cases, so as to implement a regression testing solution with high test quality and execution efficiency based on the mapping library, is a technical problem that urgently needs to be solved. Summary of the Invention
[0005] In view of this, the purpose of this invention is to provide a precise testing method, apparatus, device, and medium based on the mapping between code changes and test cases, capable of establishing and maintaining a mapping library between code changes and test cases, so as to implement a regression testing scheme with high test quality and execution efficiency based on the mapping library. The specific scheme is as follows: Firstly, this application provides a precise testing method based on the mapping between code changes and test cases, including: The target code selected by the user is determined. When the user triggers the code coverage collection operation, during the execution of each test case, the signature information of the code method in the target code and the coverage of the code method are determined by a preset code coverage tool. A mapping library is constructed to represent the mapping relationship between the signature information of the code method in the target code, the coverage and the identification information of each test case. When the user terminal triggers a commit operation for the modified code, the corresponding initial code file and the modified code file obtained after modifying the initial code file are determined, and the start line number and end line number of the code method in the initial code file and the modified code file are determined to determine the corresponding line number range; Determine the line number of the code change in the modified code file. If the line number of the code change is within the target line number interval in each of the line number intervals, then the code method corresponding to the target line number interval is determined as the modified method affected by the code change. The change method is determined as the query condition, and a query is performed in the mapping database based on the query condition to obtain the identification information of the target test case corresponding to the change method. The test case description information corresponding to the identification information is then sent to the user terminal to complete the regression test.
[0006] Optionally, during the execution of each test case, determining the signature information of the code methods in the target code and the coverage of the code methods using a preset code coverage tool includes: During the execution of each test case, the code paths covered by each test case are recorded using a preset code coverage tool, and corresponding record reports are generated. The record report is parsed by a preset parser to obtain the signature information of the code methods in the target code and the coverage of the code methods.
[0007] Optionally, when the user terminal triggers a commit operation for the modified code, determining the corresponding initial code file and the modified code file obtained after modifying the initial code file includes: When the user terminal triggers a commit operation for the changed code, the version control system determines the list of code changes received by the preset code repository, and obtains the initial code file in the code change list and the changed code file obtained after modifying the initial code file.
[0008] Optionally, determining the start and end line numbers of the code methods in the initial code file and the modified code file includes: If the modified code file is a file obtained by modifying only the code in the initial code file, the initial code file and the modified code file are parsed by a preset syntax analyzer to generate a method structure list corresponding to the initial code file and a method structure list corresponding to the modified code file, so as to determine the start line number and end line number of the code methods in the initial code file and the modified code file.
[0009] Optionally, the precise testing method based on code change and test case mapping further includes: If a code file is added or deleted, the abstract syntax tree of the added or deleted code file is determined; The abstract syntax tree is parsed to extract the signature information of all code methods in the newly added or deleted code files, and all code methods are identified as modified methods affected by the code changes.
[0010] Optionally, before determining the change method as a query condition, the method further includes: Based on the aforementioned change method, target filtering rules are determined from a preset database; The target filtering rules are used to determine the common libraries and framework methods in the change method, and then the common libraries and framework methods in the change method are filtered.
[0011] Optionally, the precise testing method based on code change and test case mapping further includes: The current code selected by the user is determined. When the user triggers the code coverage collection operation, during the execution of the target test case, the signature information and coverage of the code methods in the current code are determined by the preset code coverage tool, and the mapping library is updated using the signature information and coverage of the code methods in the current code.
[0012] Secondly, this application provides a precise testing device based on the mapping between code changes and test cases, including: The mapping library construction module is used to determine the target code selected by the user. When the user triggers the code coverage collection operation, during the execution of each test case, the signature information of the code method in the target code and the coverage of the code method are determined by a preset code coverage tool, and a mapping library is constructed to represent the mapping relationship between the signature information of the code method in the target code, the coverage and the identification information of each test case. The method determination module is used to, when detecting that the user terminal triggers a commit operation for modified code, determine the corresponding initial code file and the modified code file obtained after modifying the initial code file, and determine the start line number and end line number of the code method in the initial code file and the modified code file to determine the corresponding line number range; determine the code change line number of the modified code file, and if the code change line number is within the target line number range in each of the line number ranges, then determine the code method corresponding to the target line number range as the modified method affected by the code change; The information sending module is used to determine the change method as the query condition, and to perform a query in the mapping library based on the query condition to obtain the identification information of the target test case corresponding to the change method, so as to send the test case description information corresponding to the identification information to the user terminal to complete the regression test.
[0013] Thirdly, this application provides an electronic device, comprising: Memory, used to store computer programs; A processor is used to execute the computer program to implement the aforementioned precise testing method based on code change and test case mapping.
[0014] Fourthly, this application provides a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned precise testing method based on code change and test case mapping.
[0015] In this application, the target code selected by the user terminal is determined. When the user terminal triggers a code coverage collection operation, during the execution of each test case, the signature information of the code methods in the target code and the coverage of the code methods are determined by a preset code coverage tool, and a mapping library is constructed to represent the mapping relationship between the signature information of the code methods in the target code, the coverage, and the identification information of each test case. When the user terminal triggers a commit operation for the changed code, the corresponding initial code file and the changed code file obtained after modifying the initial code file are determined, and the initial code file is determined. The starting and ending line numbers of the code methods in the modified code file are used to determine the corresponding line number ranges; the code change line number of the modified code file is determined; if the code change line number is within the target line number range of each of the line number ranges, the code method corresponding to the target line number range is determined as the modified method affected by the code change; the modified method is determined as the query condition, and a query is performed in the mapping library based on the query condition to obtain the identification information of the target test case corresponding to the modified method, so as to send the test case description information corresponding to the identification information to the user terminal to complete the regression test. As can be seen from the above, in this application, test cases are executed, and their execution trajectories are collected using code coverage tools, recording the signatures of all covered code methods and their coverage data; the mapping relationship between test case identifiers, code method signatures, and coverage is stored; when a code repository commits, a list of changed files is obtained through the version control system; for each changed file, a method-level structural comparison is performed; all changed files are processed in parallel and merged to obtain a final set of changed methods consisting of the signatures of the affected methods; the set of changed methods is compared with the established test case-code method mapping database; all test cases covering any method in the set of changed methods are retrieved, and a recommended test case list is generated. In this way, this application can establish and maintain a mapping library between code changes and test cases, enabling a regression testing scheme with high test quality and execution efficiency based on the mapping library. Attached Figure Description
[0016] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0017] Figure 1 This application discloses a flowchart of a precise testing method based on code change and test case mapping. Figure 2 This application discloses a flowchart for code coverage acquisition. Figure 3 This application discloses a code coverage acquisition timing diagram; Figure 4 This is a sequence diagram for a recommended test case disclosed in this application; Figure 5 This is a schematic diagram of the structure of a precise testing device based on code change and test case mapping disclosed in this application; Figure 6 This is a structural diagram of an electronic device disclosed in this application. Detailed Implementation
[0018] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0019] Currently, mainstream regression testing strategies are divided into two categories: full regression testing and selective regression testing, both of which have significant technical shortcomings. Full regression testing requires executing a complete set of test cases after each code change. Its time cost, computational resources, and human resource consumption increase exponentially with the scale of the software. In continuous integration / continuous delivery models that pursue rapid feedback, the problem of inefficiency is particularly prominent, making it difficult to adapt to actual development needs. Selective regression testing has strategic shortcomings: experience-based selection methods rely on subjective human judgment, resulting in poor consistency and reusability. They are prone to test omissions due to limitations in human cognition, harboring high quality risks. Code coverage-based selection methods rely only on static coarse-grained coverage associations, selecting all test cases covering modified files without distinguishing between specific changed lines of code and logical paths. This leads to high redundancy and insufficient accuracy of the test case set, and it is also difficult to identify the indirect cross-module impact of code changes, easily missing critical test cases. To address these issues, this application provides a precise testing method, apparatus, equipment, and medium based on the mapping between code changes and test cases. It can establish and maintain a mapping library between code changes and test cases, enabling a regression testing scheme with high test quality and execution efficiency based on the mapping library.
[0020] See Figure 1 As shown, this embodiment of the invention discloses a precise testing method based on the mapping between code changes and test cases, including: Step S11: Determine the target code selected by the user terminal. When the user terminal triggers the code coverage collection operation, during the execution of each test case, the signature information of the code method in the target code and the coverage of the code method are determined by a preset code coverage tool, and a mapping library is constructed to represent the mapping relationship between the signature information of the code method in the target code, the coverage and the identification information of each test case.
[0021] In this embodiment, during regression testing, the user client can select target code to be tested from the codebase according to actual testing needs. This target code can be a complete code module or a code snippet corresponding to a specific functional unit. After the user client triggers the code coverage collection operation, the system will automatically run multiple preset test cases, covering different test scenarios and functionalities. During the execution of each test case, a preset code coverage tool records the code paths covered by each test case and generates corresponding record reports. A preset parser parses the record reports to obtain the signature information of the code methods in the target code and the coverage of those methods. The coverage reflects the degree to which each method in the target code is covered by the test cases during test case execution.
[0022] To facilitate accurate identification and analysis in subsequent regression testing, a mapping library will be established. This library records the relationships between the signature information of each method in the target code, the coverage data corresponding to that method, and the identification information of the test cases executing that method. By establishing this mapping relationship, code coverage results can be associated with specific test cases, thus providing a data foundation for quickly locating affected methods and selecting corresponding test cases in subsequent regression testing. Through these steps, code coverage information can be systematically collected and organized, laying the foundation for efficient execution of regression testing.
[0023] Step S12: When the user terminal triggers a commit operation for the changed code, determine the corresponding initial code file and the changed code file obtained after modifying the initial code file, and determine the start line number and end line number of the code method in the initial code file and the changed code file to determine the corresponding line number range.
[0024] In this embodiment, when a user-triggered commit operation for modified code is detected, the version control system determines the list of code changes received by the preset code repository, and obtains the initial code file and the modified code file obtained after modifying the initial code file from the code change list. This process ensures that the system can accurately capture the specific scope and content of the code change, providing a clear input object for subsequent change impact analysis.
[0025] After obtaining the initial code file and the modified code file, the system needs to further analyze the internal structure of the files to locate the specific position of each code method within the file. To do this, the system first determines the type of modification to the file.
[0026] In one specific implementation, if the modified code file is a file obtained by modifying only the code in the initial code file, a preset syntax analyzer parses both the initial code file and the modified code file to generate a method structure list corresponding to the initial code file and a method structure list corresponding to the modified code file. This determines the start and end line numbers of the code methods in the initial and modified code files, thus forming a series of line number intervals. These line number intervals clearly define the line range occupied by each code method in the code file and are the key basis for subsequent comparison with the code change location to determine whether the method has been affected.
[0027] In another specific implementation, if a code file is added or deleted, the abstract syntax tree of the added or deleted code file is determined; the abstract syntax tree is parsed to extract the signature information of all code methods in the added or deleted code file, and all code methods are identified as modified methods affected by the code change. This step can comprehensively identify all methods related to the change.
[0028] Step S13: Determine the line number of the code change in the modified code file. If the line number of the code change is within the target line number interval in each of the line number intervals, then the code method corresponding to the target line number interval is determined as the modified method affected by the code change.
[0029] In this embodiment, after obtaining the initial code file and the modified code file, these two files are compared and analyzed to obtain the code change line numbers. The code change line numbers indicate the line positions in the modified code file where the actual content has changed relative to the initial code file. Next, the system matches the list of code change line numbers with the line number intervals corresponding to each code method determined in step S12, checking whether each code change line number falls within the line number interval of a certain code method. If one or more code change line numbers are located within the line number interval defined by the start and end line numbers of a certain code method, then that line number interval is marked as the target line number interval. Furthermore, the code methods associated with each target line number interval are officially identified by the system as the modified methods affected by this code change. Through this precise matching mechanism based on line number intervals and change line numbers, the system can efficiently and accurately filter out the set of code methods truly affected by the code changes from a large number of code methods.
[0030] Step S14: Determine the change method as the query condition, and perform a query in the mapping library based on the query condition to obtain the identification information of the target test case corresponding to the change method, so as to send the test case description information corresponding to the identification information to the user terminal to complete the regression test.
[0031] In this embodiment, before determining the change method as a query condition, an optimization filtering operation can be performed to further improve the accuracy and efficiency of regression testing. Specifically, target filtering rules are determined from a preset database based on the change method; the target filtering rules are used to determine the general libraries and framework methods in the change method, and the general libraries and framework methods in the change method are filtered.
[0032] Furthermore, the changed method is used as a key query condition for retrieval in the mapping database. The signature information of each changed method is matched against records in the mapping database. When a match is successful, the identification information of one or more test cases that previously covered the changed method can be extracted from the mapping relationship. The test cases corresponding to these identification information are identified as the target test cases to be executed in this regression test. The test case description information corresponding to the target test cases, such as test case name, number, and brief functional description, is sent to the user interface for display, allowing testers to execute the tests or review them, thus completing the regression test. In this way, the system can automatically and accurately filter out a subset of tests directly related to the code change from a large set of test cases, avoiding the resource waste and time consumption caused by executing all test cases in regression testing, greatly improving testing efficiency.
[0033] Furthermore, after completing regression testing for this code change, the system supports dynamic updates to the mapping library to maintain its timeliness and accuracy. When the user selects new current code in subsequent iterations, and the selected current code is determined, the system triggers the code coverage collection operation. During the execution of the target test cases, the system uses a preset code coverage tool to determine the signature information and coverage of the code methods in the current code, and updates the mapping library using this signature information and coverage. Through this continuous update mechanism, the mapping library can be updated synchronously with the code evolution, ensuring that it always reflects the latest coverage relationship between the code and test cases, providing an accurate and reliable data foundation for the next regression test case selection.
[0034] As can be seen from the above, in this application, the target code selected by the user is first determined. When the user triggers a code coverage collection operation, during the execution of each test case, the signature information and corresponding coverage of the code methods in the target code are obtained through a preset code coverage tool, and a mapping library is constructed to represent the mapping relationship between code method signature information, coverage, and the identification information of each test case. When a user triggers a code change submission operation, the corresponding initial code file and the modified code file are determined, and the corresponding line number range is determined based on the start and end line numbers of the code method signature information in the initial code file and the modified code file. Then, the code change line number between the initial code file and the modified code file is determined. If the code change line number falls within a certain target line number range, the code method corresponding to the target line number range is identified as the changed method affected by the change. Using the changed method as the query condition, the identification information of the corresponding target test case is retrieved from the mapping library, and the test case description information corresponding to the identification information is sent to the user to complete the regression test. In this way, this application can establish and maintain a mapping library between code changes and test cases, so as to implement a regression testing scheme with high test quality and execution efficiency based on the mapping library.
[0035] The core execution flow of the technical solution of the embodiments of this application will be described below.
[0036] The core of this application lies in constructing and maintaining a precise mapping between "test cases and code methods" through fine-grained code structure parsing and dynamic line-level difference analysis, thereby achieving intelligent test recommendation. This method may include the following steps: First, establish a mapping relationship between test cases and code coverage: execute test cases and use code coverage tools such as JaCoCo to collect their execution traces, recording the signatures of all covered code methods and their coverage data; persistently store this mapping relationship of "test case identifier - code method signature - coverage". The format of the code method signature is package name / class name / method name (parameter type list).
[0037] Secondly, fine-grained analysis of code changes is performed to identify affected methods: when a code repository commits, a list of changed files is obtained through a version control system such as the GitLab API. All changed files are processed in parallel and merged to obtain a final "set of changed methods" consisting of the signatures of the affected methods.
[0038] For each changed file, a method-level structural comparison is performed: For newly added / deleted files: by parsing the complete abstract syntax tree of the new or old file, the signatures of all methods in the file are extracted and marked as methods affected by the change; For modified files: first, the code files of the two versions before and after the change are parsed to generate their respective method structure lists, with each entry containing the method signature and its start and end lines in the file. Second, the difference information provided by the version control system is parsed to obtain the specific line numbers of the changes in the old and new versions of the code. Finally, a matching algorithm between line numbers and method scopes is executed: traversing the changed line numbers, if a line number falls within the start and end line range of a method, it is determined that the method is affected by this change, and its method signature is added to the changes set.
[0039] Finally, test cases are recommended based on the mapping relationship: the obtained "set of changed methods" is compared with the established "test case-code method" mapping database. All test cases covering any method in the "set of changed methods" are retrieved, generating a "recommended test case list". A "blacklist" can be set to filter out unnecessary general methods, such as utility methods, to improve the business relevance of the recommended results.
[0040] Furthermore, the process of executing tests and updating mappings forms a closed loop: recommended test cases are executed, and new code coverage data is collected. Using this new coverage data, the coverage information in the mapping database is updated, and mappings can be established for newly covered methods. This process automates and continuously evolves the mapping relationships, ensuring they always reflect the latest code and test status.
[0041] In addition, defect association and reverse recommendation can be performed: when a defect is found in testing or production, the code method modified to fix the defect is recorded, and a "defect-code method" association is established. Based on this association, reverse recommendation can be performed: when it is necessary to verify whether a defect has been fixed, or to perform defect root cause analysis, the system can quickly recommend test cases that cover the code methods associated with the defect.
[0042] The following is combined Figure 2 , Figure 3 , Figure 4 The schematic diagram shown illustrates the technical solution of the embodiments of this application in detail.
[0043] It should be noted that, Figure 2 and Figure 3 The system workflow of one embodiment of the present invention is shown from different perspectives. Figure 2 The coverage collection process for building a "test case-code" mapping relationship is described; Figure 3This demonstrates the complete process by which the system intelligently analyzes and recommends test cases after code changes occur. The overall system can be implemented as a standalone, precise testing platform, with its backend services interacting with code repositories, test management platforms, coverage tools, and databases through well-defined interfaces.
[0044] First, refer to Figure 2 As shown, a mapping relationship is established between test cases and code coverage.
[0045] The goal of this step is to build an initial, fine-grained knowledge base of "test case-code method" mappings. For example... Figure 2 As shown, the process begins with user interaction on the system interface. The user first selects the source code repository and specific code branch or commit version to be associated on the platform's front-end interface. The system checks the completeness of the user's input information, prompting the user to supplement any missing information. After confirming the information is correct, the user triggers "Start Coverage Collection." At this time, the system's backend service coordinates the test management platform to execute the specified automated test cases and simultaneously starts the code coverage collection tool to monitor the testing process. The coverage tool records all code paths traversed during test case execution. After collection, the system parses the raw report generated by the coverage tool. The parser can identify the code's structural hierarchy, delving from packages and classes to specific method levels, extracting the unique signature of each covered code method and its corresponding coverage data. For example, the unique signature can be an identifier containing the complete package path, class name, and method name. Finally, the system associates the test case identifier, code method signature, and coverage value, and persistently stores them in a mapping database. This process establishes a "precise profile" of each test case's coverage scope, forming the data foundation for subsequent intelligent recommendations. Figure 2 The end point of the process, "Collection Completed," signifies the completion of a mapping establishment task.
[0046] Secondly, refer to Figure 3 As shown, the code changes were analyzed in a fine-grained manner, and the affected methods were identified.
[0047] This step is the core component of the invention's accurate recommendation mechanism, corresponding to... Figure 3 The interaction between the back-end services and GitLab and the database. For example... Figure 3As shown, the user inputs code comparison information, such as the repository, base branch, and target branch, into the front-end interface. The front-end sends the request to the "use case recommendation interface" of the back-end service. After receiving the request, the back-end service first interacts with the code repository, such as GitLab, to obtain detailed difference information for this commit, including a list of changed files and the specific line-level changes in each file, i.e., a "list of changed files and changed lines". Subsequently, the system enters the core "execution code change analysis" phase. By processing all changed files in parallel, the system finally generates a "set of changed methods" consisting of the signatures of all affected methods.
[0048] For each modified file, the analyzer performs the following steps: First, it retrieves the file content, obtaining the complete source code of the file before and after the change from the code repository. Second, it performs dual-version structure parsing, using a syntax analyzer to parse the code of both versions, generating their respective "method structure lists." Each entry in the list contains a method signature and its start and end line numbers in the file. Third, it performs line-level impact analysis, matching the specific modified line numbers provided by the code repository with the aforementioned method structure lists. The core logic of the matching algorithm is to determine whether each modified line number falls within the line number range of a certain method signature. If so, it is determined that the code change has affected that method. This algorithm can accurately pinpoint file-level changes to the specific affected method signature.
[0049] Finally, refer to Figure 4 As shown, test cases are recommended based on mapping and filtering rules.
[0050] After obtaining the "set of change methods," the system begins generating a recommended list of test cases. For example... Figure 3 As shown, the backend service interacts with the database in multiple rounds to complete this step. First, the system queries the database for the "blacklist function" rule pre-configured for this project. This rule filters out code that is not related to general libraries, framework methods, etc., ensuring that the recommended results focus on business logic. Next, the system uses the filtered "set of changed methods" as the query condition to search the mapping relationship database. The core SQL (Structured Query Language) logic of the search is: in the mapping table, find all records whose code method signature field values are in the input set, and return the test case identifiers associated with these records. Then, the backend service sends the obtained list of test case identifiers to the test management platform, such as... Figure 3The system uses MeterSphere to obtain detailed descriptions of these test cases, such as the test case name and the module it belongs to. Finally, the backend service returns the integrated "Recommended Test Case Details" to the frontend. The frontend interface displays this information to the user in a clear format, such as tables. These tables typically include basic information about the test cases and the specific code methods associated with the current change, making the recommendations clear and reliable.
[0051] Furthermore, this application includes an automated closed-loop system and knowledge base evolution. This application forms an automated, enhanced closed loop. Once a recommended test case is selected and executed, the execution process triggers new coverage data collection. The newly collected coverage data is used to update the mapping database, refreshing the coverage information of the corresponding test cases. This allows the entire mapping knowledge base to continuously and automatically evolve with project iterations, maintaining high accuracy and timeliness, and effectively reducing long-term maintenance costs.
[0052] Furthermore, this application enables defect correlation analysis. Based on the same set of "test case-code method" mapping relationships, this invention can naturally extend to defect correlation analysis capabilities. When a software defect is fixed, the defect identifier can be associated with the modified code method in the fix submission and recorded. Subsequently, it is possible to analyze whether new code changes may affect code related to historical defects, i.e., for risk assessment; or, based on a specific defect, it can recommend all test cases covering related code methods for organizing targeted verification tests, achieving traceability of "defect-fix-verification".
[0053] In summary, this application provides a complete solution from accurate mapping establishment to intelligent change analysis and automated test recommendation. This method transforms traditional experience-based, coarse-grained regression testing into a data-driven, method-level precision testing model, significantly improving the efficiency, relevance, and intelligence of testing activities.
[0054] Accordingly, see Figure 5 As shown, this application embodiment provides a precise testing device based on code change and test case mapping, including: The mapping library construction module 11 is used to determine the target code selected by the user terminal. When the user terminal triggers the code coverage collection operation, during the execution of each test case, the signature information of the code method in the target code and the coverage of the code method are determined by a preset code coverage tool, and a mapping library is constructed to represent the mapping relationship between the signature information of the code method in the target code, the coverage and the identification information of each test case. The method determination module 12 is used to determine the corresponding initial code file and the modified code file obtained after modifying the initial code file when the user terminal triggers a commit operation for the modified code. It also determines the start and end line numbers of the code methods in the initial code file and the modified code file to determine the corresponding line number range. The module further determines the code change line number of the modified code file. If the code change line number is within the target line number range in each of the line number ranges, the code method corresponding to the target line number range is determined as the modified method affected by the code change. The information sending module 13 is used to determine the change method as the query condition, and to perform a query in the mapping library based on the query condition to obtain the identification information of the target test case corresponding to the change method, so as to send the test case description information corresponding to the identification information to the user terminal to complete the regression test.
[0055] In some specific embodiments, the mapping library construction module 11 specifically includes: The report generation unit is used to record the code paths covered by each test case during the execution of each test case using a preset code coverage tool, and generate corresponding record reports. The information determination unit is used to parse the record report through a preset parser to obtain the signature information of the code methods in the target code and the coverage of the code methods.
[0056] In some specific embodiments, the method determining module 12 specifically includes: The file acquisition unit is used to determine the code change list received by the preset code repository through the version control system when the user terminal triggers a commit operation for the changed code, and to acquire the initial code file in the code change list and the modified code file obtained after modifying the initial code file.
[0057] In some specific embodiments, the method determining module 12 specifically includes: The list generation unit is used to parse the initial code file and the modified code file using a preset syntax analyzer if the modified code file is a file obtained by modifying only the code in the initial code file, so as to generate a method structure list corresponding to the initial code file and a method structure list corresponding to the modified code file, so as to determine the start line number and end line number of the code methods in the initial code file and the modified code file.
[0058] In some specific embodiments, the precise testing device based on code change and test case mapping further includes: The syntax tree determination unit is used to determine the abstract syntax tree of the added or deleted code file if a code file is added or deleted. The information extraction unit is used to parse the abstract syntax tree to extract the signature information of all code methods in the newly added or deleted code files, and to identify all code methods as changed methods affected by the code changes.
[0059] In some specific embodiments, the information sending module 13 further includes: The rule determination unit is used to determine the target filtering rule from the preset database based on the change method; The code filtering unit is used to determine the common libraries and framework methods in the change method using the target filtering rules, and to filter the common libraries and framework methods in the change method.
[0060] In some specific embodiments, the precise testing device based on code change and test case mapping further includes: The mapping library update unit is used to determine the current code selected by the user. When the user triggers the code coverage collection operation, during the execution of the target test case, the signature information and coverage of the code methods in the current code are determined by the preset code coverage tool, and the mapping library is updated using the signature information and coverage of the code methods in the current code.
[0061] Furthermore, embodiments of this application also disclose an electronic device, Figure 6 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content of the diagram should not be construed as limiting the scope of this application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the precise testing method based on code change and test case mapping disclosed in any of the foregoing embodiments. Furthermore, the electronic device 20 in this embodiment may specifically be an electronic computer.
[0062] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 25 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.
[0063] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk, or optical disk, etc. The resources stored thereon can include an operating system 221, computer programs 222, etc., and the storage method can be temporary storage or permanent storage.
[0064] The operating system 221 is used to manage and control the various hardware devices on the electronic device 20 and the computer program 222, which may be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program capable of performing the precise testing method based on code change and test case mapping executed by the electronic device 20 as disclosed in any of the foregoing embodiments, the computer program 222 may further include computer programs capable of performing other specific tasks.
[0065] Furthermore, this application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned disclosed precise testing method based on code change and test case mapping. Specific steps of this method can be found in the corresponding content disclosed in the foregoing embodiments, and will not be repeated here.
[0066] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.
[0067] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0068] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0069] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0070] The technical solutions provided in this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the methods and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A precise testing method based on code change and test case mapping, characterized in that, include: The target code selected by the user is determined. When the user triggers the code coverage collection operation, during the execution of each test case, the signature information of the code method in the target code and the coverage of the code method are determined by a preset code coverage tool. A mapping library is constructed to represent the mapping relationship between the signature information of the code method in the target code, the coverage and the identification information of each test case. When the user terminal triggers a commit operation for the modified code, the corresponding initial code file and the modified code file obtained after modifying the initial code file are determined, and the start line number and end line number of the code method in the initial code file and the modified code file are determined to determine the corresponding line number range; Determine the line number of the code change in the modified code file. If the line number of the code change is within the target line number interval in each of the line number intervals, then the code method corresponding to the target line number interval is determined as the modified method affected by the code change. The change method is determined as the query condition, and a query is performed in the mapping database based on the query condition to obtain the identification information of the target test case corresponding to the change method. The test case description information corresponding to the identification information is then sent to the user terminal to complete the regression test.
2. The precise testing method based on code change and test case mapping according to claim 1, characterized in that, During the execution of each test case, the signature information of the code methods in the target code and the coverage of the code methods are determined by a preset code coverage tool, including: During the execution of each test case, the code paths covered by each test case are recorded using a preset code coverage tool, and corresponding record reports are generated. The record report is parsed by a preset parser to obtain the signature information of the code methods in the target code and the coverage of the code methods.
3. The precise testing method based on code change and test case mapping according to claim 1, characterized in that, When the user terminal triggers a commit operation for the modified code, determining the corresponding initial code file and the modified code file obtained after modifying the initial code file includes: When the user terminal triggers a commit operation for the changed code, the version control system determines the list of code changes received by the preset code repository, and obtains the initial code file in the code change list and the changed code file obtained after modifying the initial code file.
4. The precise testing method based on code change and test case mapping according to claim 1, characterized in that, Determining the start and end line numbers of the code methods in the initial code file and the modified code file includes: If the modified code file is a file obtained by modifying only the code in the initial code file, the initial code file and the modified code file are parsed by a preset syntax analyzer to generate a method structure list corresponding to the initial code file and a method structure list corresponding to the modified code file, so as to determine the start line number and end line number of the code methods in the initial code file and the modified code file.
5. The precise testing method based on code change and test case mapping according to claim 1, characterized in that, Also includes: If a code file is added or deleted, the abstract syntax tree of the added or deleted code file is determined; The abstract syntax tree is parsed to extract the signature information of all code methods in the newly added or deleted code files, and all code methods are identified as modified methods affected by the code changes.
6. The precise testing method based on code change and test case mapping according to any one of claims 1 to 5, characterized in that, Before determining the change method as a query condition, the method further includes: Based on the aforementioned change method, target filtering rules are determined from a preset database; The target filtering rules are used to determine the common libraries and framework methods in the change method, and then the common libraries and framework methods in the change method are filtered.
7. The precise testing method based on code change and test case mapping according to claim 1, characterized in that, Also includes: The current code selected by the user is determined. When the user triggers the code coverage collection operation, during the execution of the target test case, the signature information and coverage of the code methods in the current code are determined by the preset code coverage tool, and the mapping library is updated using the signature information and coverage of the code methods in the current code.
8. A precise testing device based on code change and test case mapping, characterized in that, include: The mapping library construction module is used to determine the target code selected by the user. When the user triggers the code coverage collection operation, during the execution of each test case, the signature information of the code method in the target code and the coverage of the code method are determined by a preset code coverage tool, and a mapping library is constructed to represent the mapping relationship between the signature information of the code method in the target code, the coverage and the identification information of each test case. The method determination module is used to determine the corresponding initial code file and the modified code file obtained after modifying the initial code file when the user terminal triggers a commit operation for the modified code, and to determine the start line number and end line number of the code method in the initial code file and the modified code file, so as to determine the corresponding line number range; Determine the line number of the code change in the modified code file. If the line number of the code change is within the target line number interval in each of the line number intervals, then the code method corresponding to the target line number interval is determined as the modified method affected by the code change. The information sending module is used to determine the change method as the query condition, and to perform a query in the mapping database based on the query condition to obtain the identification information of the target test case corresponding to the change method, so as to send the test case description information corresponding to the identification information to the user terminal to complete the regression test.
9. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the precise testing method based on code change and test case mapping as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, Used to store computer programs; wherein, when the computer programs are executed by a processor, they implement the precise testing method based on code change and test case mapping as described in any one of claims 1 to 7.