Information acquisition method and device, electronic equipment and computer readable storage medium

The software project information is obtained through the target plug-in, the operation interface is generated and the coverage information is filtered, which solves the problem of obtaining coverage of local test codes in software projects, and improves the construction efficiency and accuracy of test cases.

CN119201720APending Publication Date: 2024-12-27SHENZHEN FALCON NETWORK MEDIA CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411288313.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-13
Publication Date
2024-12-27

AI Technical Summary

Technical Problem

It is difficult for the prior art to obtain local test code coverage information in software projects, resulting in limited targeted construction efficiency and accuracy of test cases.

Method used

Obtain project information through the target plug-in, generate an operation interface, respond to information acquisition requests, determine information acquisition condition information, and filter target coverage information from the comprehensive test coverage information to realize local test code coverage acquisition in software projects.

Benefits of technology

It improves the targeted construction efficiency and accuracy of test cases, and generates operation interfaces through plug-ins, which improves the convenience of obtaining coverage information.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119201720A_ABST
    Figure CN119201720A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses an information acquisition method and device, electronic equipment and a computer readable storage medium, and the method comprises the steps: obtaining project information of a target project through a target plug-in, and generating an operation interface through the target plug-in according to the project information; in response to an information acquisition request generated through the operation interface, determining information acquisition condition information corresponding to the information acquisition request; and screening target coverage rate information from the comprehensive test coverage rate information of the target project according to the information acquisition condition information. The target coverage rate information is screened from the comprehensive test coverage rate information through the information acquisition condition information, so that acquisition of local test coverage rate information in the software project is realized, and targeted construction of the test case is facilitated.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of testing, and specifically to an information acquisition method, device, electronic device, and computer-readable storage medium. Background Art

[0002] To improve the quality of software development, in addition to dedicated testing by testers, developers also conduct simple self-tests after developing software features. Currently, software project testing relies on test cases, which are executed to test the software project. However, with the increasing complexity of software and the shortening of development cycles, the demand for test case development is also increasing. To ensure software quality, the requirements for test cases are also becoming increasingly stringent.

[0003] Currently, code coverage of test cases is an important indicator of test effectiveness or test case quality. This information provides information about both the code covered by the test and the code not covered. Therefore, once code coverage is determined, targeted test cases can be constructed based on the uncovered code, improving the accuracy and efficiency of test case development. Therefore, obtaining code coverage is crucial for efficient test case development.

[0004] Currently, a variety of coverage standards have been proposed (such as statement coverage, decision coverage, and condition coverage), and various automated testing and coverage analysis tools have been developed (such as unit testing frameworks such as JUnit, Cobertura, Jacoco, and Istanbul, and integration testing frameworks such as AndroidTest). However, current code coverage is primarily focused on the entire software project, making it difficult to obtain coverage of test code within a specific software project, hindering the targeted construction of test cases. Summary of the Invention

[0005] The embodiments of the present application provide an information acquisition method, device, electronic device, and computer-readable storage medium, which can achieve the acquisition of local test code coverage of a software project.

[0006] In a first aspect, an embodiment of the present application provides an information acquisition method, the method comprising:

[0007] Acquire project information of a target project through a target plug-in, and generate an operation interface based on the project information using the target plug-in;

[0008] In response to an information acquisition request generated through the operation interface, determining information acquisition condition information corresponding to the information acquisition request;

[0009] Target coverage information is filtered from the comprehensive test coverage information of the target project according to the information acquisition condition information.

[0010] In a second aspect, an embodiment of the present application further provides an information acquisition device, the device comprising:

[0011] A generation module, configured to obtain project information of a target project through a target plug-in, and generate an operation interface based on the project information using the target plug-in;

[0012] a determination module, configured to, in response to an information acquisition request generated through the operation interface, determine information acquisition condition information corresponding to the information acquisition request;

[0013] A screening module is used to screen target coverage information from the comprehensive test coverage information of the target project according to the information acquisition condition information.

[0014] Optionally, in some embodiments of the present application, the screening module includes:

[0015] A parsing unit, configured to parse the information acquisition condition information to obtain statistical type information and statistical object information;

[0016] a first determining unit, configured to determine target component information according to the statistical type information and the statistical object information;

[0017] A screening unit is used to screen target coverage information from the comprehensive test coverage information of the target project according to the target component information.

[0018] In some embodiments of the present application, the first determining unit includes:

[0019] a first determining subunit configured to determine a changed component data set from the statistical object information if the statistical type information is incremental coverage statistics, and use component information in the changed component data set as target component information;

[0020] a second determining subunit, configured to, if the statistical type information is impact domain coverage statistics, determine a changed component dataset from the statistical object information, obtain referenced component information of the component information in the changed component dataset, and use both the component information and the referenced component information as target component information;

[0021] The third determining subunit is configured to use all component information included in the statistical object information as target component information if the statistical type information is full coverage statistics.

[0022] In some embodiments of the present application, the first determining subunit is specifically configured to:

[0023] A second determining unit, configured to determine target calling interface information according to the statistical object information;

[0024] The calling unit is used to call the target calling interface corresponding to the target calling interface information to obtain the changed component data set.

[0025] In some embodiments of the present application, the second determining subunit is specifically configured to:

[0026] Recursively call the reference information acquisition component to obtain the parent component information of each level of the component information;

[0027] The parent component information of each level is used as reference component information.

[0028] In some embodiments of the present application, the device further includes an acquisition module, which includes:

[0029] an injection unit, configured to inject the coverage collection component into the target project in response to an information injection request generated through the operation interface;

[0030] The reading unit is used to read the comprehensive test coverage information of the target project, wherein the comprehensive test coverage information is collected by the coverage collection component when the target project is tested through test cases.

[0031] In some embodiments of the present application, the device further includes a rollback module, which includes:

[0032] A deleting unit is configured to delete the coverage collection component from the target project.

[0033] In a third aspect, an embodiment of the present application further provides an electronic device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, the steps in the above-mentioned information acquisition method are implemented.

[0034] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps in the above-mentioned information acquisition method are implemented.

[0035] In a fifth aspect, embodiments of the present application further provide a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the methods provided in the various optional implementations described in the embodiments of the present application.

[0036] In summary, the embodiment of the present application obtains the project information of the target project through the target plug-in, and generates an operation interface based on the project information and using the target plug-in. In response to the information acquisition request generated through the operation interface, the information acquisition condition information corresponding to the information acquisition request is determined, and the target coverage information is filtered from the comprehensive test coverage information of the target project based on the information acquisition condition information.

[0037] The target coverage information is filtered from the comprehensive test coverage information using information acquisition conditions, enabling the acquisition of local test coverage information within a software project and facilitating the targeted construction of test cases. The plug-in generates an operation interface, making it easier to obtain coverage information. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] In order to more clearly illustrate the technical solutions in this application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0039] Figure 1 This is a schematic diagram of a scenario of the information acquisition method provided in an embodiment of the present application;

[0040] Figure 2 Schematic diagram of the information acquisition method provided in the embodiment of the present application;

[0041] Figure 3 is a schematic diagram of the operation interface provided in the embodiment of the present application;

[0042] Figure 4 is a schematic diagram of a new method provided in an embodiment of the present application;

[0043] Figure 5 This is a flowchart of the coverage collection component injection provided by an embodiment of the present application;

[0044] Figure 6 This is a schematic diagram of an embodiment of the functional module of the target plug-in provided in an embodiment of the present application;

[0045] Figure 7 This is a system framework diagram with the target plug-in workbench as the core provided by the embodiment of the present application;

[0046] Figure 8 is a structural diagram of an information acquisition device provided in an embodiment of the present application;

[0047] Figure 9 It is a structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0048] The following will be combined with the drawings in this application to clearly and completely describe the technical solutions in this application. Obviously, the embodiments described are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without making any creative efforts shall fall within the scope of protection of the present invention.

[0049] The embodiments of the present application provide an information acquisition method, device, electronic device and computer-readable storage medium. Specifically, the embodiments of the present application provide an information acquisition device suitable for an electronic device, which includes a terminal device or a server, and the terminal device includes a laptop computer, a desktop computer, a television and other devices. The server can 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 functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content distribution networks (CDN, Content Delivery Network), and basic cloud computing services such as big data and artificial intelligence platforms, etc. The server can be directly or indirectly connected via wired or wireless communication.

[0050] For details, please refer to Figure 1 , Figure 1 : This is a schematic diagram of a scenario in which a terminal device according to an embodiment of the present application executes the information acquisition method. The server executing the information acquisition method can be understood by referring to the steps of executing the information acquisition method by the terminal device. The specific execution process of the information acquisition method executed by the terminal device is as follows:

[0051] The terminal device 10 obtains the project information of the target project through the target plug-in, and generates an operation interface based on the project information and using the target plug-in. The terminal device 10 responds to the information acquisition request generated through the operation interface, determines the information acquisition condition information corresponding to the information acquisition request, and filters the target coverage information from the comprehensive test coverage information of the target project based on the information acquisition condition information.

[0052] It is understood that the embodiments of the present application use information acquisition condition information to filter the target coverage information from the comprehensive test coverage information, thereby achieving the acquisition of local test coverage information in the software project, which facilitates the targeted construction of test cases. Furthermore, the plug-in generates an operation interface, which improves the convenience of obtaining coverage information.

[0053] It should be noted that the order of description of the following embodiments does not limit the priority order of the embodiments.

[0054] See also Figure 2 , Figure 2 This is a flowchart of an information acquisition method provided in an embodiment of the present application. Although a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than shown in the accompanying drawings. Specifically, the specific process of the information acquisition method is as follows:

[0055] 101. Obtain project information of a target project through a target plug-in, and generate an operation interface based on the project information using the target plug-in.

[0056] In the embodiment of the present application, the target project is a software project for which target coverage information is to be collected. The target coverage information is part of the comprehensive test coverage information of the software project, and the comprehensive test coverage information is the global coverage information of the software project obtained after the target project is tested with the test cases.

[0057] The comprehensive test coverage information reflects the comprehensive coverage of the target project's code during the testing process. The comprehensive test coverage information includes both the percentage of code coverage and the specific code covered by the test. For example, the test case's coverage percentage for the software project's test code (e.g., N% of the software project's code is covered by the test) and the specific code covered.

[0058] Similarly, target coverage information also includes code coverage percentage information and specific code coverage information. However, target coverage information is for a specific part of a software project. For example, after testing a software project with test cases, target coverage information is collected for newly added code. For example, this test covers the percentage of newly added code and the portion of the code that is covered.

[0059] Among them, in software projects, plug-ins are generally an extensible component used to enhance or expand the functionality, performance, or capabilities of a project. They can be integrated with the project's build tools, frameworks, development environments, or other supporting software to provide additional functionality or specific behaviors. Among them, in an embodiment of the present application, the target plug-in is a tool that is convenient to use on Android Studio, and the plug-in tool has a corresponding initialization interface after startup.

[0060] Among them, the project information is the identification information of the project, including the project name, the package name of the project, the main module of the parsing process, the link of the project (giturl link), etc. The initialization interface is refreshed with these project information to obtain the operation interface containing these project information.

[0061] For example, see Figure 3 As shown, Figure 3 This is a schematic diagram of the operation interface provided in an embodiment of the present application, which includes project information of the target project so that operations on the target project can be implemented through the project information in the operation interface.

[0062] At the same time, in order to obtain the code coverage information through the operation interface, an operation control is also set in the operation interface to trigger the acquisition of code coverage information. The operation control includes a button or a drop-down box, such as Figure 3 The drop-down box corresponding to the statistical type information includes drop-down contents such as "Incremental Coverage Report", "Incremental Impact Domain Report" and "Full Coverage Report". Similarly, buttons such as "Refresh" and "Clear Cache Files" are also displayed on the operation interface.

[0063] 102. In response to an information acquisition request generated through the operation interface, determine information acquisition condition information corresponding to the information acquisition request.

[0064] The information acquisition request is a request for obtaining information, and the information acquisition request can be triggered by an operation control of the operation interface. For example, the user triggers the generation of the information acquisition request by clicking an operation control provided by the operation interface.

[0065] In order to improve the accuracy of information acquisition or to obtain specific information, the information acquisition request may also carry information on conditions for obtaining the information, that is, information acquisition condition information.

[0066] For example, see Figure 3 To generate an incremental coverage report, you can select "Incremental Coverage Report" from the drop-down box corresponding to the statistical type information on the operation interface, and then click the "Generate Information" control to generate an information acquisition request with "Incremental Coverage Report" as the information acquisition condition information. In this embodiment of the application, the incremental refers to the class or method corresponding to the newly added code.

[0067] 103. Filter target coverage information from the comprehensive test coverage information of the target project according to the information acquisition condition information.

[0068] The target coverage information is obtained by filtering the comprehensive test coverage information based on the information acquisition condition information. For example, the target coverage information is obtained by filtering the comprehensive test coverage information according to the name and identifier corresponding to the information acquisition condition information.

[0069] In summary, the embodiment of the present application obtains target coverage information from comprehensive test coverage information by filtering information acquisition conditions, thereby achieving the acquisition of local test coverage information in a software project and facilitating the targeted construction of test cases. Furthermore, the plug-in generates an operation interface, which improves the convenience of obtaining coverage information.

[0070] Optionally, since software project development is usually based on the development of classes and methods for a single function, testing usually occurs after class development is completed or after the testing of a newly added method is completed. Therefore, embodiments of the present application can obtain code coverage information of the class or method after testing to quickly analyze the development quality of the single function. That is, optionally, in some embodiments of the present application, the step of "filtering target coverage information from the comprehensive test coverage information of the target project according to the information acquisition condition information" includes:

[0071] Parsing the information acquisition condition information to obtain statistical type information and statistical object information;

[0072] Determine target component information according to the statistical type information and the statistical object information;

[0073] Target coverage information is filtered from the comprehensive test coverage information of the target project according to the target component information.

[0074] Among them, the target component information is the component for which coverage information needs to be obtained. The component can be a class or method in the software project. For example, a new class is constructed, or a new method is obtained by adding new code to the class. Adding new code to the method indicates that a new method has been added. Specifically, a class is the basic unit of object-oriented programming, which is used to describe the properties and behaviors of an object. A class can be regarded as a definition of a data structure, which contains a set of data members (attributes) and member functions (methods). Classes can be used to create multiple objects with the same properties and behaviors. A method is a function in a class that is used to describe the behavior or operation of the class. It defines the operations that can be performed on objects of the class. Methods are usually used to access and modify the properties of a class, or perform some specific functions on an object.

[0075] It is understandable that using target component information as a specific screening condition to obtain specific target coverage information is helpful for specifically analyzing the test coverage of the target component corresponding to the target component information. For example, after obtaining the target coverage information for the target component information, the coverage percentage of the test involving the target component and the specific code lines involved can be obtained through the target coverage information. Accordingly, test cases can be constructed based on the code lines not covered by the test to achieve targeted construction of test cases for the untested code lines, simplifying the difficulty of test case construction and improving the efficiency of test case construction.

[0076] Among them, the statistical type information and statistical object information are conditions for determining the target component information for which coverage information needs to be obtained. Among them, in the embodiment of the present application, the statistical type information and statistical object information can be obtained through input in the interface, for example, in Figure 3 Two drop-down boxes are configured in the operation interface, and the user enters statistical type information and statistical object information through the drop-down boxes, and generates an information acquisition request by clicking the "Information Generate" control, wherein the information acquisition request contains statistical type information and statistical object information.

[0077] It should be noted that the statistical type information refers to which types of code are counted, for example, incremental code, domain-affecting code, or global code, etc. The statistical object information refers to which subject's code is counted, for example, the local part, the branch part in the code repository, the merged part of the code repository, etc.

[0078] Local refers to the file system on the developer's computer or workstation, which contains the project's code, resources, and other related files. Local is where developers conduct development work, write code, and test. Locally, developers can modify, add, and delete files and perform various development operations, for example, on their own computer (which has the source code for the software project).

[0079] In software development, a code repository is a central repository that stores all the project's code, version history, branches, and other related information. Code repositories are typically managed by a version control system (VCS), such as Git or Subversion (SVN). A code repository can be located on a local computer or a remote server. Code in a code repository can be obtained through local submissions. For example, a developer submits code to the code repository locally through a version submission service. The main function of a code repository is to track and manage code versions, providing a central source for developers to access and share code. It records the history of each code change, enabling developers to roll back to previous versions, develop new features through branches, collaborate on development, and share and synchronize code with other developers.

[0080] For example, in an embodiment of the present application, when the statistical type information is the code for the statistical increment and the statistical object information is the code for the statistical local part, the target component information is the code for the increment in the local part.

[0081] Accordingly, the step of “determining target component information according to the statistical type information and the statistical object information” includes:

[0082] If the statistical type information is incremental coverage statistics, determining a changed component data set from the statistical object information, and using component information in the changed component data set as target component information;

[0083] If the statistical type information is impact domain coverage statistics, determining a changed component data set from the statistical object information, obtaining referenced component information of the component information in the changed component data set, and using both the component information and the referenced component information as target component information;

[0084] If the statistical type information is full coverage statistics, all component information included in the statistical object information is used as target component information.

[0085] Among them, incremental coverage statistics refer to the coverage of newly added code during testing, impact domain coverage statistics refer to the coverage of the impact range caused by incremental code during testing, and full coverage statistics refer to the coverage of the entire software project during testing.

[0086] Incremental refers to newly added classes or methods in a software project. Newly added classes include newly created classes, for example, creating a new class A. Newly added methods include new methods added to a class, and methods obtained by changing the code of an existing method by adding, deleting, or modifying it. For example, see Figure 4 As shown, Figure 4This is a schematic diagram of a new method provided in an embodiment of the present application, wherein the method click2 is shown before the addition ( Figure 4 The content on the left) and the newly added ( Figure 4 The content on the right side) of the method click2 is a newly added method. Accordingly, the method click2 is the target component information for which the coverage is statistically calculated in the embodiment of the present application. Accordingly, the class (TestExact.java) corresponding to the method click2 can also be the target component information of the embodiment of the present application, that is, the target component information can include both the method click2 and the class (TestExact.java) of the method click2.

[0087] Among them, the scope of influence caused by the incremental code refers to other methods involved in the incremental method (the method of the incremental code). The other methods are usually methods that directly or indirectly reference the incremental method. For example, when method click2 is an incremental method, if method click3 and method click4 reference method click2, then method click3 and method click4 are other methods involved in the incremental method; if method click3 references method click2, and method click4 references method 3, then method click3 and method click4 are both other methods involved in the incremental method, that is, in the embodiment of the present application, the methods that can be affected by the addition of method click2 are the scope of influence caused by the incremental code.

[0088] Accordingly, based on different statistical type information, you can determine the incremental method or the impact domain of the incremental method that requires coverage statistics, and then obtain the code coverage information of the target component information corresponding to the statistical type information in the statistical object information after testing. For example, you can count the test coverage information of the developer's local incremental method.

[0089] Optionally, target component information for which code coverage information during testing needs to be obtained can be obtained by calling relevant interfaces. For example, for incremental methods or classes, interfaces that can obtain incremental methods or classes can be called to obtain them. Since different statistical object information corresponds to different calling interfaces, target calling interface information can be determined based on the statistical object information, and the changed method or class can be obtained based on the target calling interface information. That is, optionally, in some embodiments of the present application, the step of "determining the changed component data set from the statistical object information" includes:

[0090] Determine target call interface information according to the statistical object information;

[0091] The target calling interface corresponding to the target calling interface information is called to obtain a changed component data set.

[0092] For example, the statistical object information includes the local part, the branch part in the code repository, the merged part of the code repository, etc. Among them, if the statistical object information is the local part, the ChangeList dataset can be obtained through the ChangeListManager.getChangeLists interface of IntelliJ, and the class or method corresponding to the ChangeList dataset is the change component dataset; if the statistical object information is the branch part in the code repository, the local GitCommit object can be obtained through the git4idea framework, and the Change dataset can be obtained through the GitCommit.getChanges interface. The class or method corresponding to the Change dataset is the change component dataset; if the statistical object information is the merged part of the code repository, the difference (Diff) data can be obtained through the gitlab interface, and the class or method corresponding to the difference data is the change component dataset.

[0093] Optionally, the step of determining the incremental method using the change data (ChangeList dataset, Change dataset, or Diff data) may include:

[0094] Step 1: Get the changed data;

[0095] Step 2: Determine the difference type of the source file corresponding to the changed data. If the difference type is addition, execute step 3; if the difference type is modification, execute step 4.

[0096] Step 3: Parse the source file and treat all methods of the source file as incremental methods;

[0097] Step 4: Parse the source file and the old version file corresponding to the source file;

[0098] Step 5: Determine whether the signature of the method in the source file is included in the signature of the method in the old version file. If not, treat the method as an incremental method. If so, execute step 6.

[0099] Step 6: Determine whether the MD5 values ​​of the two methods with the same signature are consistent. If they are inconsistent, use the method in the source file as the incremental method.

[0100] Among them, the source file is mainly a class file.

[0101] Optionally, other methods of referencing the incremental method can be obtained through the reference information acquisition component. For example, the method of referencing the incremental method can be obtained by calling the general interface of intellij.psi: referencesSearch.search(psiMethod).findAll() method. Accordingly, since any method that directly or indirectly references the incremental method will be affected by the incremental method, the embodiment of the present application obtains each parent reference method of the incremental method by cyclically calling the general interface. That is, optionally, in some embodiments of the present application, the step of "obtaining reference component information of the component information in the changed component dataset" includes:

[0102] Recursively call the reference information acquisition component to obtain the parent component information of each level of the component information;

[0103] The parent component information of each level is used as reference component information.

[0104] Specifically, the steps for obtaining reference component information may include:

[0105] Step 1: Use the PSI parsing framework to parse the input object, convert it into a Psi element, and distinguish the element type. If the element type is PsiMethod, execute step 2;

[0106] Step 2: Call the IntelliJ.Psi general interface: referencesSearch.search(psiMethod).findAll() to obtain all reference objects of this method in the project. Recursively parse the reference objects. If the parent element of the reference object is also a method, continue recursively until there is no parent method at the call site. The recursive parsing here is compatible with Java and Kotlin languages. Finally, the parsed reference chain information is assembled into a MethodNodeList data object to obtain the reference component information.

[0107] Among them, PSI (Program Structure Interface) is part of the IntelliJ platform and is used to parse and structure the code.

[0108] In this embodiment of the present application, a Gradle task is defined to first execute the ec file merge task, configure basic parameters such as the merged ec file, source code file set, compiled file set, and report path, then add the incremental class and method data set change.json parsed by the plug-in, and finally use the java-jar command to call the jacococli.jar package from the jacoco source code to perform incremental method coverage statistics and obtain the incremental method coverage information. The ec file is a file format generated by the jacoco framework when collecting coverage data, similar to the exec file.

[0109] Optionally, in an embodiment of the present application, for a coverage collection component required to obtain coverage information, the coverage collection component can be injected into the target project through the target plug-in, so that when the target project is tested through a test case, the coverage information of the test can be collected through the coverage collection component. That is, optionally, in an embodiment of the present application, before the step of "filtering target coverage information from the comprehensive test coverage information of the target project according to the information acquisition condition information", the method further includes:

[0110] In response to an information injection request generated through the operation interface, injecting a coverage collection component into the target project;

[0111] The comprehensive test coverage information of the target project is read, wherein the comprehensive test coverage information is collected by the coverage collection component when the target project is tested through test cases.

[0112] For example, see Figure 5 As shown, Figure 5 This is a flowchart of the coverage collection component injection provided by an embodiment of the present application. Specifically, the process includes:

[0113] 111. Start the target plug-in and generate the operation interface;

[0114] 112. Trigger the one-click injection installation button through the operation interface to determine the coverage collection component and plug-in execution script;

[0115] 113. In the root directory of the target project, find the build configuration file (build.gradle) for the entire project and configure the plug-in execution script for each sub-module in this file;

[0116] Correspondingly, each submodule can execute the functional tasks of the plug-in execution script.

[0117] 114. Parse the build configuration files (build.gradle) of each module of the target project, identify the project entry (application) class, and inject the coverage collection component into the class;

[0118] 115. Execute the gradle task sync to synchronize the project build configuration.

[0119] Among them, if platform signature is required, the signature plug-in task is called to build the signature, and the build task (such as installApeSignRelease) is executed to generate the apk corresponding to the project; if platform signature is not required, the native task (assembleRelease) of gradle is called to build the apk corresponding to the project.

[0120] Among them, the coverage collection component for collecting coverage information is injected through the plug-in, and the plug-in execution script is injected to improve the component injection efficiency.

[0121] Among them, for the component injected into the target project through the target plug-in, after obtaining the coverage information, a rollback task can be executed to delete the component from the target project. That is, optionally, in the embodiment of the present application, after the step of "filtering target coverage information from the comprehensive test coverage information of the target project according to the information acquisition condition information", the method further includes:

[0122] The coverage collection component is deleted from the target project.

[0123] It is understandable that the plug-in execution script injected into the target project for the function execution of the target plug-in can also be rolled back to be deleted from the target project.

[0124] The coverage collection component includes jacocoUtil.jar, which performs coverage information collection tasks. The plugin execution script includes the jacoco_exact.gradle script, which is built based on Gradle and injected into the target project to ensure the execution of tasks in the target plugin. Gradle is an open source tool for automated project builds, providing powerful dependency management, flexible build configuration, and efficient project builds. jacoco is an open source Java code coverage tool that can be used to measure code coverage.

[0125] For example, see Figure 6 As shown, Figure 6 : is a schematic diagram of an embodiment of the functional module of the target plug-in provided in an embodiment of the present application, wherein the functions of the target plug-in include:

[0126] Project Information Acquisition Module 201 is used to obtain the currently loaded project information of Android Studio when opening the target plug-in tool's main page. This information includes the project name, package name, main module of the parsing process, and the project's giturl link. It also refreshes the project information interface, retrieves the project package name by searching the main module, provides default build parameters such as buildtype and flavor, and supports configuration modification. A buildtype of release indicates a release version, a buildtype of debug indicates a test version, and a flavor is a customized channel package identifier.

[0127] The instrumentation and dependency injection module 202 is used to add dependency integration jacoco_exact.gradle function script for each submodule by modifying the project root build.gradle. The script contains instrumentation logic, retrieves the application entry of the main module, and inserts the startup code of the coverage collection jar package; the script also designs multiple gradle function tasks, which can be executed by calling the gradle command.

[0128] The build and installation module 203 is used to execute the gradle build command according to the project build parameters, such as app:installApeSignRelease, where app is the main module name, install means to install directly after building, ApeSign is a self-developed signature plug-in tool, and release is the default buildtype. The entire command is to build the release package, complete the signature, and install it directly on the connected device.

[0129] ADB communication module 204 is responsible for initializing the ADB device object, obtaining the device IP, device name, connection status, etc. through the object, setting device monitoring, timely refreshing the interface device information, supporting ADB command execution, and also supporting device file transfer to the local computer for exporting EC test files for use in coverage statistics.

[0130] The coverage report generation module 205 is used to implement this function in jacoco_exact.gradle, which includes ec file merging and coverage statistics. The ec file merging uses the jacocoMerge task of jacoco to integrate the ec files exported from the device; the coverage statistics uses the jacocoReport task of jacoco to configure the merged ec file, source code file set, compilation file set, filtering conditions and report path and other parameters, execute the customized task command, and finally output the html coverage report.

[0131] Incremental statistics module 206, used by the plug-in to parse incremental code, obtains MR's code_diffs data through the gitlab interface, or obtains the local code's ChangeList and the local branch's commit information GitCommit list through the git4idea framework. Finally, through data parsing, the change or diff object class is parsed by uast element to obtain all methods of the changed class. Then, the MD5 value of each method is compared with the previous and next versions to filter out the modified methods. Finally, all the results are output to a change.json file;

[0132] The incremental statistics function is similar to the coverage report generation. A gradle task is also defined. First, the ec file merge task is executed, and basic parameters such as the merged ec file, source code file set, compiled file set, and report path are configured. Then, the incremental class and method data set change.json parsed by the plug-in is added. Finally, the jacococli.jar package opened in the jacoco source code is called with the java-jar command to perform incremental method coverage statistics, and finally an HTML-based incremental coverage report is output.

[0133] The report upload and MR association module 207 is used to package and upload two coverage files to the ape service, carry project URL, MR ID and other parameters and associate them with the project code merge request, and store them in the server. When the MR corresponding to the CR is requested, the stored report content can be extracted from the server to verify the coverage indicator access control.

[0134] The source code injection rollback module 208 is used for injection rollback. Since dependency injection and code instrumentation modify the project source code content, in order not to affect the code and build configuration of the original project, an injection rollback function is designed here. It reversely utilizes the principles of instrumentation and dependency injection to delete the modified content and achieve the effect of restoring the source code.

[0135] The change impact domain analysis module 209 first obtains the changed methods from the incremental code, performs static code analysis on these modified methods, obtains their static reference chains, and then reintegrates the collected affected method information into a change.json, and then executes the incremental statistics process to verify the code test coverage affected by the code change.

[0136] It should be noted that the above diagram is a schematic diagram of one embodiment of the functional module diagram of the target plug-in provided in the embodiments of this application. In actual application, the target plug-in includes one or more of the above functional modules. Optionally, in addition to including one or more of the above functional modules, the target plug-in may also include other functional modules based on actual application requirements, which is not limited by this application.

[0137] In summary, the embodiment of the present application uses the target plug-in (idea plug-in) sidebar tool of Android Studio, which is more in line with the developer's habits. It can flexibly select local differences, branch submission differences, code merge differences, and more accurately verify incremental code. The process is simple and ready to use. All functions are executed with one button, and results and reports are automatically output. At the same time, it also supports changes to the impact domain test coverage and reduces the missed detection rate.

[0138] In order to facilitate the understanding of the embodiments of the present application, the system framework diagram with the target plug-in workbench as the core is improved, please refer to Figure 7 As shown, Figure 7 The system shown in FIG. 1 includes:

[0139] The code repository management module 211 is used to manage project codes through the code repository. For example, developers upload locally developed codes to the code repository and perform operations such as project submission, push, and update between the target project module 212.

[0140] The target project module 212, which involves the target project, is the software project tested by the test case in the embodiment of the present application. It not only performs operations such as project code submission, push, and update between the code repository management module 211, but also responds to the precise injection and rollback tasks of the plug-in workbench module 214;

[0141] APE service module 213 ensures pipeline execution, processes code and product information, and provides a plug-in workbench backend interface;

[0142] The plug-in workbench module 214 corresponds to the target plug-in and provides an operation interface, coverage report display, etc.

[0143] Android device 215, the device where the target project is deployed, is used to execute test cases to test the target project and save the coverage file after the test. It also performs target project APK installation, ec file transfer, and ADB communication with the plug-in workbench module 214.

[0144] In summary, the target plug-in of the plug-in workbench module provides an operation interface, triggers the acquisition of coverage information, and triggers operations such as injection and rollback, so as to obtain coverage information after testing the target project.

[0145] The coverage information may also be used to determine the access control for merging. For example, if the incremental coverage is less than 80%, merging is not allowed.

[0146] To facilitate better implementation of the information acquisition method of the present application, the present application also provides an information acquisition device based on the above information acquisition method. The meanings of the terms are the same as those in the above information acquisition method, and the specific implementation details can be referred to the description in the method embodiment.

[0147] See also Figure 8 , Figure 8 : is a schematic diagram of the structure of the information acquisition device provided in an embodiment of the present application, wherein the information acquisition device may specifically include:

[0148] A generating module 301 is configured to obtain project information of a target project through a target plug-in, and generate an operation interface based on the project information using the target plug-in;

[0149] A determination module 302 is configured to determine, in response to an information acquisition request generated through the operation interface, information acquisition condition information corresponding to the information acquisition request;

[0150] The screening module 303 is configured to screen target coverage information from the comprehensive test coverage information of the target project according to the information acquisition condition information.

[0151] Optionally, in some embodiments of the present application, the screening module 303 includes:

[0152] A parsing unit, configured to parse the information acquisition condition information to obtain statistical type information and statistical object information;

[0153] a first determining unit, configured to determine target component information according to the statistical type information and the statistical object information;

[0154] A screening unit is used to screen target coverage information from the comprehensive test coverage information of the target project according to the target component information.

[0155] In some embodiments of the present application, the first determining unit includes:

[0156] a first determining subunit configured to determine a changed component data set from the statistical object information if the statistical type information is incremental coverage statistics, and use component information in the changed component data set as target component information;

[0157] a second determining subunit, configured to, if the statistical type information is impact domain coverage statistics, determine a changed component dataset from the statistical object information, obtain referenced component information of the component information in the changed component dataset, and use both the component information and the referenced component information as target component information;

[0158] The third determining subunit is configured to use all component information included in the statistical object information as target component information if the statistical type information is full coverage statistics.

[0159] In some embodiments of the present application, the first determining subunit is specifically configured to:

[0160] A second determining unit, configured to determine target calling interface information according to the statistical object information;

[0161] The calling unit is used to call the target calling interface corresponding to the target calling interface information to obtain the changed component data set.

[0162] In some embodiments of the present application, the second determining subunit is specifically configured to:

[0163] Recursively call the reference information acquisition component to obtain the parent component information of each level of the component information;

[0164] The parent component information of each level is used as reference component information.

[0165] In some embodiments of the present application, the device further includes an acquisition module, which includes:

[0166] an injection unit, configured to inject the coverage collection component into the target project in response to an information injection request generated through the operation interface;

[0167] The reading unit is used to read the comprehensive test coverage information of the target project, wherein the comprehensive test coverage information is collected by the coverage collection component when the target project is tested through test cases.

[0168] In some embodiments of the present application, the device further includes a rollback module, which includes:

[0169] A deleting unit is configured to delete the coverage collection component from the target project.

[0170] In the embodiment of the present application, the generation module 301 first obtains the project information of the target project through the target plug-in, and generates an operation interface based on the project information and using the target plug-in. Then, the determination module 302 responds to the information acquisition request generated through the operation interface and determines the information acquisition condition information corresponding to the information acquisition request. Subsequently, the screening module 303 screens the target coverage information from the comprehensive test coverage information of the target project based on the information acquisition condition information.

[0171] The embodiment of the present application filters the target coverage information from the comprehensive test coverage information through information acquisition condition information, thereby achieving the acquisition of local test coverage information in the software project and facilitating the targeted construction of test cases. The plug-in generates an operation interface, which improves the convenience of obtaining coverage information.

[0172] In addition, the present application also provides an electronic device, such as Figure 9 As shown, it shows a schematic diagram of the structure of the electronic device involved in this application, specifically:

[0173] The electronic device may include one or more processing core processors 401, one or more computer-readable storage media memories 402, a power supply 403, an input unit 404 and other components. Those skilled in the art will understand that Figure 9 The electronic device structure shown in the figure does not constitute a limitation of the electronic device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange components differently.

[0174] Processor 401 is the control center of the electronic device, connecting the various parts of the entire electronic device using various interfaces and lines. By running or executing software programs and / or modules stored in memory 402 and accessing data stored in memory 402, it performs various functions of the electronic device and processes data, thereby monitoring the electronic device as a whole. Optionally, processor 401 may include one or more processing cores; preferably, processor 401 may integrate an application processor and a modem processor, wherein the application processor primarily processes the operating system, user interface, and application programs, while the modem processor primarily handles wireless communications. It is understood that the modem processor may not be integrated into processor 401.

[0175] The memory 402 can be used to store software programs and modules. The processor 401 executes various functional applications and data processing by running the software programs and modules stored in the memory 402. The memory 402 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the electronic device, etc. In addition, the memory 402 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage device. Accordingly, the memory 402 may also include a memory controller to provide the processor 401 with access to the memory 402.

[0176] The electronic device also includes a power supply 403 for supplying power to various components. Preferably, the power supply 403 can be logically connected to the processor 401 via a power management system, thereby enabling the power management system to manage charging, discharging, and power consumption. The power supply 403 can also include one or more DC or AC power supplies, a recharging system, a power supply device debugging circuit, a power converter or inverter, a power status indicator, and other arbitrary components.

[0177] The electronic device may further include an input unit 404, which may be configured to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control.

[0178] Although not shown, the electronic device may further include a display unit, etc., which will not be described in detail here. Specifically, in this embodiment, the processor 401 in the electronic device will load the executable files corresponding to the processes of one or more application programs into the memory 402 according to the following instructions, and the processor 401 will run the application programs stored in the memory 402, thereby implementing the steps of any of the information acquisition methods provided in the embodiments of the present application.

[0179] An embodiment of the present application obtains project information of a target project through a target plug-in, and generates an operation interface based on the project information using the target plug-in. In response to an information acquisition request generated through the operation interface, information acquisition condition information corresponding to the information acquisition request is determined, and target coverage information is filtered from the comprehensive test coverage information of the target project based on the information acquisition condition information.

[0180] The target coverage information is filtered from the comprehensive test coverage information using information acquisition conditions, enabling the acquisition of local test coverage information within a software project and facilitating the targeted construction of test cases. The plug-in generates an operation interface, making it easier to obtain coverage information.

[0181] The specific implementation of the above operations can be found in the previous embodiments and will not be repeated here.

[0182] Those skilled in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be accomplished by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.

[0183] To this end, the present application provides a computer-readable storage medium, on which a computer program is stored. The computer program can be loaded by a processor to execute the steps in any information acquisition method provided in the present application.

[0184] The specific implementation of the above operations can be found in the previous embodiments and will not be repeated here.

[0185] The computer-readable storage medium may include a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.

[0186] Since the instructions stored in the computer-readable storage medium can execute the steps in any information acquisition method provided in the present application, the beneficial effects that can be achieved by any information acquisition method provided in the present application can be achieved. Please refer to the previous embodiments for details and will not be repeated here.

[0187] The above is a detailed introduction to the information acquisition method, device, electronic device and computer-readable storage medium provided by the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.

Claims

1. A method for obtaining information, characterized in that: The method comprises: Acquire project information of a target project through a target plug-in, and generate an operation interface based on the project information and using the target plug-in; In response to an information acquisition request generated through the operation interface, determining information acquisition condition information corresponding to the information acquisition request; Target coverage information is filtered from the comprehensive test coverage information of the target project according to the information acquisition condition information.

2. The information acquisition method according to claim 1, characterized in that: The step of filtering target coverage information from the comprehensive test coverage information of the target project according to the information acquisition condition information includes: Parsing the information acquisition condition information to obtain statistical type information and statistical object information; Determine target component information according to the statistical type information and the statistical object information; Target coverage information is filtered from the comprehensive test coverage information of the target project according to the target component information.

3. The information acquisition method according to claim 2, characterized in that: The determining the target component information according to the statistical type information and the statistical object information includes: If the statistical type information is incremental coverage statistics, determining a changed component data set from the statistical object information, and using component information in the changed component data set as target component information; If the statistical type information is impact domain coverage statistics, determining a changed component data set from the statistical object information, and obtaining reference component information of the component information in the changed component data set, and using both the component information and the reference component information as target component information; If the statistical type information is full coverage statistics, all component information included in the statistical object information is used as target component information.

4. The information acquisition method according to claim 3, characterized in that: The step of determining the changed component data set from the statistical object information includes: Determine target calling interface information according to the statistical object information; The target calling interface corresponding to the target calling interface information is called to obtain a changed component data set.

5. The information acquisition method according to claim 3, characterized in that: The obtaining the referenced component information of the component information in the changed component data set includes: Recursively call the reference information acquisition component to obtain parent component information of each level of the component information; The parent component information of each level is used as reference component information.

6. The information acquisition method according to claim 1, characterized in that: Before filtering target coverage information from the comprehensive test coverage information of the target project according to the information acquisition condition information, the method further includes: In response to an information injection request generated through the operation interface, injecting a coverage collection component into the target project; The comprehensive test coverage information of the target project is read, wherein the comprehensive test coverage information is collected by the coverage collection component when the target project is tested through test cases.

7. The information acquisition method according to claim 5, characterized in that: After filtering the target coverage information from the comprehensive test coverage information of the target project according to the information acquisition condition information, the method further includes: The coverage collection component is deleted from the target project.

8. An information acquisition device, characterized in that: The device comprises: A generation module, used to obtain project information of a target project through a target plug-in, and generate an operation interface based on the project information and using the target plug-in; A determination module, configured to determine, in response to an information acquisition request generated through the operation interface, information acquisition condition information corresponding to the information acquisition request; A screening module is used to screen target coverage information from the comprehensive test coverage information of the target project according to the information acquisition condition information.

9. An electronic device, characterized in that: The method comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps in the information acquisition method according to any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the information acquisition method according to any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • Incremental code coverage rate determination method and device, equipment and storage medium

    CN120276998A