Code testing method, device, electronic device and storage medium

By detecting changes in the code to be tested and determining the target operation unit and test cases based on the preset relationship, the problems of high testing cost and low efficiency in the prior art are solved, and a more accurate test case recommendation and a more efficient testing process are achieved.

CN114218118BActive Publication Date: 2025-02-28BEIJING DAJIA INTERNET INFORMATION TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111595771.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-23
Publication Date
2025-02-28
Estimated Expiration
2041-12-23

AI Technical Summary

Technical Problem

In the prior art, the business code testing of applications is costly and inefficient, mainly because the tester needs to manually select target test cases for multiple testing links.

Method used

Provide a code testing method, which performs test operations by detecting whether the code to be tested has changed, determining the changed code segment, and determining the target operation unit and the target test case based on the preset relationship.

Benefits of technology

Through pre-established preset relationships, test cases are indirectly associated with code segments, accurately find required test cases, reduce participation of unnecessary test cases, reduce test costs, and improve test efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114218118B_ABST
    Figure CN114218118B_ABST
Patent Text Reader

Abstract

The present disclosure provides a code testing method, device, electronic device and storage medium. In an embodiment of the present disclosure, in response to a test operation, it is detected whether the code to be tested has changed. If the code to be tested has changed, the changed code segment to which the change belongs is determined, and at least one target operation unit corresponding to the changed code segment is determined based on a first preset relationship. At least one target test case corresponding to the at least one target operation unit is determined based on a second preset relationship. A test operation is performed on the at least one target test case. In this way, by indirectly associating the test case with the code segment through the pre-established first preset relationship and the second preset relationship, it can be ensured to a certain extent that the test case required for this time can be found more accurately, and unnecessary test cases are avoided from participating in the test link, thereby reducing the test cost and improving the test efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure belongs to the field of network technology, and in particular, relates to a code testing method, device, electronic device and storage medium. Background Art

[0002] Currently, in order to ensure that the business code of an application can normally implement various business functions of the application, it is often necessary to test the business code of each function.

[0003] In the related art, the target test cases used in the test phase are often manually selected by the tester for testing. In this way, sometimes too many target test cases are selected, which leads to high test cost and low test efficiency. Summary of the invention

[0004] In order to overcome the problems existing in the related art, the present disclosure provides a code testing method, device, electronic device and storage medium.

[0005] According to a first aspect of the present disclosure, a code testing method is provided, the method comprising:

[0006] In response to the test operation, detecting whether the code to be tested has been changed;

[0007] If the code to be tested is changed, determining a changed code segment to which the change belongs, and determining at least one target operation unit corresponding to the changed code segment based on a first preset relationship;

[0008] Determine at least one target test case corresponding to the at least one target operation unit based on the second preset relationship;

[0009] A test operation is performed on the at least one target test case.

[0010] Optionally, the method comprises:

[0011] Based on the description content of the created test case, split the first operation unit corresponding to the created test case;

[0012] Determining a code segment covered when executing the operation represented by the first operation unit as the code segment covered by the first operation unit;

[0013] A corresponding relationship between the created test case and the first operation unit is established to generate the second preset relationship; and a corresponding relationship between the first operation unit and the covered code segment is established to generate the first preset relationship.

[0014] Optionally, splitting the first operation unit corresponding to the created test case based on the description content of the created test case includes:

[0015] Based on the description content of the created test case, determine the operation information of the operation involved in the created test case and the view information of the operation view corresponding to the involved operation;

[0016] The operation information and the corresponding view information are combined into the first operation unit.

[0017] Optionally, the determining the code segment covered when the operation represented by the first operation unit is executed as the code segment covered by the first operation unit includes:

[0018] Execute each operation in sequence according to the order of operations involved in the created test case, and after each operation is executed, determine the first function set currently covered and the second function set covered after the previous operation is executed;

[0019] The functions in the difference set between the first function set and the second function set are determined as code segments covered by the first operation unit corresponding to the operation.

[0020] Optionally, the method further includes:

[0021] In response to the adding instruction, determining an operation unit corresponding to the test case to be added as a second operation unit;

[0022] Based on the first preset relationship, determine a second operation unit that is not currently recorded by the first preset relationship as a third operation unit;

[0023] A correspondence relationship between the third operation unit and the code segment covered by the third operation unit is added to the first preset relationship, and a correspondence relationship between the test case to be added and the second operation unit is added to the second preset relationship.

[0024] Optionally, the method further includes:

[0025] When the target test case passes the test operation, based on the changed code segment, the code segment corresponding to the target operation unit in the first preset relationship is updated.

[0026] According to a second aspect of the present disclosure, a code testing device is provided, the device comprising:

[0027] A detection module is configured to detect whether the code to be tested has been changed in response to the test operation;

[0028] A first determination module is configured to determine, if the code to be tested is changed, a changed code segment to which the change belongs, and determine at least one target operation unit corresponding to the changed code segment based on a first preset relationship;

[0029] A second determination module is configured to determine at least one target test case corresponding to the at least one target operation unit based on a second preset relationship;

[0030] The testing module is configured to perform a testing operation on the at least one target test case.

[0031] Optionally, the device comprises:

[0032] A splitting module is configured to split the first operation unit corresponding to the created test case based on the description content of the created test case;

[0033] A third determining module is configured to determine a code segment covered when the operation represented by the first operating unit is executed as the code segment covered by the first operating unit;

[0034] An establishing module is configured to establish a corresponding relationship between the created test case and the first operating unit to generate the second preset relationship; and to establish a corresponding relationship between the first operating unit and the covered code segment to generate the first preset relationship.

[0035] Optionally, the splitting module is specifically configured as follows:

[0036] Based on the description content of the created test case, determine the operation information of the operation involved in the created test case and the view information of the operation view corresponding to the involved operation;

[0037] The operation information and the corresponding view information are combined into the first operation unit.

[0038] Optionally, the third determining module is specifically configured to:

[0039] Execute each operation in sequence according to the order of operations involved in the created test case, and after each operation is executed, determine the first function set currently covered and the second function set covered after the previous operation is executed;

[0040] The functions in the difference set between the first function set and the second function set are determined as code segments covered by the first operation unit corresponding to the operation.

[0041] Optionally, the device further comprises:

[0042] A fourth determining module is configured to determine, in response to the adding instruction, an operation unit corresponding to the test case to be added as a second operation unit;

[0043] a fifth determining module, configured to determine, based on the first preset relationship, a second operating unit that is not currently recorded by the first preset relationship, as a third operating unit;

[0044] The adding module is configured to add a corresponding relationship between the third operation unit and the code segment covered by the third operation unit in the first preset relationship, and to add a corresponding relationship between the test case to be added and the second operation unit in the second preset relationship.

[0045] Optionally, the device further comprises:

[0046] The updating module is configured to update the code segment corresponding to the target operation unit in the first preset relationship based on the changed code segment when the target test case passes the test operation.

[0047] According to a third aspect of the present disclosure, there is provided an electronic device, including:

[0048] processor;

[0049] a memory for storing instructions executable by the processor;

[0050] The processor is configured to execute the instructions to implement the method as described in any one of the first aspects.

[0051] According to a fourth aspect of the present disclosure, a storage medium is provided. When instructions in the storage medium are executed by a processor of an electronic device, the electronic device executes the method as described in any one of the first aspects.

[0052] According to a fifth aspect of the present disclosure, a computer program product is provided, the computer program product comprising readable program instructions, and when the readable program instructions are executed by a processor of an electronic device, the electronic device executes the method as described in any one of the first aspects.

[0053] Compared with the related art, the present invention has the following advantages and positive effects:

[0054] The code testing method provided by the embodiment of the present disclosure detects whether the code to be tested has changed in response to a test operation. If the code to be tested has changed, the changed code segment to which the change belongs is determined, and at least one target operation unit corresponding to the changed code segment is determined based on the first preset relationship. At least one target test case corresponding to the at least one target operation unit is determined based on the second preset relationship. A test operation is performed on the at least one target test case. In this way, by indirectly associating the test case with the code segment through the pre-established first preset relationship and the second preset relationship, it can be ensured to a certain extent that the test case required for this time can be found more accurately, and unnecessary test cases are avoided from participating in the test process, thereby reducing the test cost and improving the test efficiency.

[0055] At the same time, by pre-establishing the first preset relationship and the second preset relationship respectively, the test case and the code segment are indirectly associated, which can further reduce the operation cost of the preset relationship.

[0056] The above description is only an overview of the technical solution of the present disclosure. In order to more clearly understand the technical means of the present disclosure, it can be implemented according to the contents of the specification. In order to make the above and other purposes, features and advantages of the present disclosure more obvious and easy to understand, the specific implementation methods of the present disclosure are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0057] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present disclosure. Also, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:

[0058] Figure 1 is a flowchart of a code testing method provided by an embodiment of the present disclosure;

[0059] Figure 2 is a schematic diagram of a knowledge base provided by an embodiment of the present disclosure;

[0060] Figure 3 is a schematic diagram of an operating unit provided in an embodiment of the present disclosure;

[0061] Figure 4 is a related schematic diagram of another knowledge base provided by an embodiment of the present disclosure;

[0062] Figure 5 is a partial schematic diagram of a knowledge base provided by an embodiment of the present disclosure;

[0063] Figure 6 is a block diagram of a code testing device provided by an embodiment of the present disclosure;

[0064] Figure 7 is a block diagram of a device for code testing according to an exemplary embodiment;

[0065] Figure 8 The invention is a block diagram of a device for code testing according to an exemplary embodiment. DETAILED DESCRIPTION

[0066] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.

[0067] First, the concepts involved in this disclosure are explained:

[0068] Code snippet: It can be composed of multiple lines of code. A code snippet can implement a complete processing logic. For example, a code snippet can correspond to a function, and a function can represent the method involved in the code.

[0069] Changed code segment: The function in the application's business code that has changed.

[0070] Test case: refers to the description of the test task, which can reflect the test plan and test strategy. A test case can describe a series of operations required to test a specific function.

[0071] Operation unit: used to characterize the operations involved in a test case.

[0072] Code segments covered by test cases: refers to the functions in the business code that will be executed when testing based on test cases.

[0073] The code segment covered by the operation unit: also known as the code segment involved in the operation unit, refers to the function that will be executed in the business code when the operation represented by the operation unit is executed during the test.

[0074] Figure 1 is a flowchart of a code testing method provided by an embodiment of the present disclosure, such as Figure 1 As shown, the method may include:

[0075] Step 101: In response to a test operation, detect whether the code to be tested has been changed.

[0076] In the embodiment of the present invention, the code to be tested may be the code indicated by the test operation. The test operation may be triggered based on a test instruction sent by a user, or may be periodically and automatically triggered, or may be triggered by a specified operation. For example, the specified operation may be a code file editing operation, which is not limited in the embodiment of the present invention.

[0077] Step 102: If the code to be tested is changed, determine the changed code segment to which the change belongs, and determine at least one target operation unit corresponding to the changed code segment based on a first preset relationship.

[0078] In the embodiment of the present invention, subsequent test operations are performed only when changes to the code to be tested are actually detected, which can avoid the problem of executing unnecessary test operations due to false triggering to a certain extent, thereby saving processing resources.

[0079] The target operation unit may be an operation unit covering the changed code segment, and the first preset relationship may be used to characterize the corresponding relationship between the operation unit and the code segment covered by the operation unit.

[0080] Specifically, the business code of the application can be monitored to determine whether a code change occurs. For example, the code repository storing the business code can be monitored based on a preset monitoring tool. When a change is detected, the preset monitoring tool can detect the specific changed code segment as the changed code segment to which the change belongs. Further, the first preset relationship can be pre-constructed, and the first preset relationship can be used to characterize the correspondence between the operation unit corresponding to each operation involved in each test case and the code segment covered by the operation unit. Among them, when the code of the constituent function is covered (executed) when the operation represented by the operation unit is executed, it is determined that the function is the code segment covered by the operation unit. Alternatively, it can also be determined that the function is the code segment covered by the operation unit only when the coverage rate of the code of the constituent function is greater than the preset coverage rate threshold, and the present disclosure does not limit this.

[0081] Optionally, the identifier of the changed code segment can be obtained. The identifier can be the function name of the function represented by the changed code segment. Specifically, the identifier of the changed code segment sent by the preset monitoring tool can be received. Then, based on the first preset relationship, the operation unit corresponding to the code segment whose identifier matches the identifier of the changed code segment can be searched as the target operation unit. For example, the identifier of the changed code segment can be matched with the identifiers of each code segment stored in the first preset relationship. The operation unit corresponding to the matching identifier is used as the target operation unit.

[0082] Step 103: Determine at least one target test case corresponding to the at least one target operation unit based on the second preset relationship.

[0083] Step 104: Execute a test operation on the at least one target test case.

[0084] Among them, the target test case can be a test case involving the operation represented by the target operation unit, and the second preset relationship can be used to represent the correspondence between the test case and the operation unit corresponding to the test case, and one operation unit corresponds to one operation involved in the test case.

[0085] In the disclosed embodiment, the second preset relationship may be pre-built. Since the target operation unit covers the changed code segment, that is, the change in the changed code segment may affect the operation represented by the target operation unit, for example, causing the operation to fail to proceed normally. There is often a front-to-back relationship between a series of operations involved in the test case. If there is a problem with a certain operation, it may cause problems with the business functions implemented by this series of operations. Therefore, in the disclosed embodiment, after determining the target operation unit that the changed code segment will affect, the target test case can be further determined based on the target operation unit, so as to ensure that the impact that this change may bring can be accurately tested based on the target test case. At the same time, it can avoid test cases that are not related to this update and will not be affected from participating in the test link, thereby saving test costs and improving test efficiency to a certain extent. For example, the test case whose corresponding operation unit matches the target operation unit can be found in the second preset relationship as the target test case.

[0086] Furthermore, since the second preset relationship can characterize the correspondence between the test case and the operation unit, and the first preset relationship can characterize the correspondence between the operation unit and the code segment covered by the operation unit, therefore, based on the first preset relationship and the second preset relationship, the test case can be indirectly associated with the covered code segment. Furthermore, by using these two preset relationships to indirectly associate the test case with the covered code segment, when the code related to a certain operation changes, there is no need to update all the test cases involved in the operation and the code segment corresponding to the test case as a whole, only the code segment corresponding to the operation unit representing the operation needs to be updated, thereby saving operation costs. At the same time, when it is necessary to add test cases, the currently stored operation units and their corresponding code segments can be reused according to the operations involved in the test cases, thereby simplifying the addition of operations to a certain extent, and avoiding the problem of duplicate storage, thereby further saving operation costs.

[0087] In summary, the code testing method provided by the embodiment of the present disclosure detects whether the code to be tested has changed in response to a test operation. If the code to be tested has changed, the changed code segment to which the change belongs is determined, and at least one target operation unit corresponding to the changed code segment is determined based on the first preset relationship. At least one target test case corresponding to the at least one target operation unit is determined based on the second preset relationship. A test operation is performed on the at least one target test case. In this way, by indirectly associating the test case with the code segment through the pre-established first preset relationship and the second preset relationship, it can be ensured to a certain extent that the test case required for this time can be found more accurately, and unnecessary test cases are avoided from participating in the test link, thereby reducing the test cost and improving the test efficiency.

[0088] At the same time, by pre-establishing the first preset relationship and the second preset relationship respectively, the test case and the code segment are indirectly associated, which can further reduce the operation cost of the preset relationship.

[0089] Optionally, the first preset relationship and the second preset relationship involved in the embodiment of the present disclosure may be pre-generated based on the following operations:

[0090] Step S21: split the first operation unit corresponding to the created test case based on the description content of the created test case.

[0091] In the embodiment of the present disclosure, the created test cases involved in the splitting may be all the created test cases, or may be part of the created test cases, for example, may be part of the created test cases that need to be added to the preset relationship. The number of created test cases involved in the splitting may be set based on actual needs, and the embodiment of the present disclosure does not limit this. Furthermore, the created test cases may include description content, which may be used to describe a series of operations required to be performed when testing a specific function. For example, the description content may be "select any album to enter the editing page, perform beautification, soundtrack, clip, cover operations, and store it in the local collection without loss, and directly publish / re-edit and publish the work with normal effects". Furthermore, based on the description content of the created test case, the operation units corresponding to the various operations involved in the created test case can be split to obtain the first operation unit.

[0092] Step S22: determine the code segment covered when the operation represented by the first operation unit is executed as the code segment covered by the first operation unit.

[0093] Among them, the code segment covered by the first operation unit is the code segment corresponding to the first operation unit. In the embodiment of the present disclosure, the coverage of the operation on the specific function in the specific class when the operation is executed can be determined based on the preset coverage collection tool, so as to determine the covered code segment based on the coverage. For example, it can be determined that the code segment is covered when the coverage is greater than the preset coverage threshold. Among them, the preset coverage threshold can be set based on actual needs, and the preset coverage threshold can be adjusted according to cost and benefit. The smaller the threshold, the more functions are included in the coverage, and the more recommended use cases. Furthermore, the coverage collection tool can be Jacoco, and the coverage can indicate the percentage of the function code covered by the operation. There may be multiple code segments covered by an operation unit, and these multiple code segments can constitute the code call chain corresponding to the operation unit.

[0094] Step S23, establishing a corresponding relationship between the created test case and the first operation unit to generate the second preset relationship; and establishing a corresponding relationship between the first operation unit and the covered code segment to generate the first preset relationship.

[0095] The created test case may be stored in correspondence with the first operation unit, or partial information of the created test case may be stored in correspondence, for example, the case identification is stored in correspondence with the first operation unit, to generate a second preset relationship. Further, the code segment covered by the first operation unit may be used as the code segment corresponding to the first operation unit, and the first operation unit may be stored in correspondence with the covered code segment, or partial information of the first operation unit may be stored in correspondence with the covered code segment, for example, the first operation unit may be stored in correspondence with the identification of the covered code segment, to generate a first preset relationship. Further, the first preset relationship and the second preset relationship may respectively constitute two knowledge bases. Test cases participating in the test process are subsequently selected based on the two knowledge bases. Figure 2 is a schematic diagram of a knowledge base provided by an embodiment of the present disclosure, such as Figure 2 As shown, the first preset relationship can be represented in the "operation unit" - "code call chain" knowledge base. The second preset relationship can be represented in the "test case" - "operation unit" knowledge base. Among them, the code call chain can be a collection of code segments covered by the operation unit. Based on these two knowledge bases, the "test case" and the "code call chain" can be indirectly linked, so as to achieve accurate use case recommendation in a precise testing method based on the operation unit. Among them, precise testing can refer to accurately assessing the test scope, recommending effective test cases, and avoiding unnecessary test cases from participating in the testing process.

[0096] Furthermore, if Figure 2As shown, in the "operation unit" - "code call chain" knowledge base, the operation units are represented as: "operation 1", "operation 2", where the covered code segments corresponding to "operation 1" are represented as "code 1", "code 2", and a mapping relationship is formed, and the covered code segments corresponding to "operation 2" are represented as "code 1", "code 3", and a mapping relationship is formed. In the "test case" - "operation unit" knowledge base, "use case 1" and "use case 2" are stored, where the operation units corresponding to "use case 1" are represented as "operation 1", "operation 2", and the operation unit corresponding to "use case 2" is represented as "operation 1". Assuming that "code 1" changes, and "code 2" and "code 3" do not change, then it can be queried in the "operation unit" - "code call chain" knowledge base, and it can be concluded that "code 1" affects "operation 1" and "operation 2". Further, by querying in the "test case" - "operation unit", it can be concluded that "operation 1" and "operation 2" affect "use case 1" and "use case 2", and then "use case 1" and "use case 2" can be used as target test cases, and it is recommended to execute "use case 1" and "use case 2".

[0097] In an embodiment of the present disclosure, based on the description content of the created test case, the first operation unit corresponding to the created test case is split. The code segment covered when executing the operation represented by the first operation unit is determined as the code segment covered by the first operation unit. A corresponding relationship between the created test case and the first operation unit is established to generate a second preset relationship; and a corresponding relationship between the first operation unit and the covered code segment is established to generate a first preset relationship. Compared to the method of directly establishing a mapping relationship between a test case and the code segment covered by the test case, in an embodiment of the present disclosure, by splitting the created test case into the first operation unit, a mapping relationship between the created test case and the first operation unit, as well as a mapping relationship between the first operation unit and the code segment covered by the first operation unit are respectively established, so that the preset relationship can be easily maintained.

[0098] Optionally, the splitting of the operations of the first operation unit corresponding to the created test case based on the description content of the created test case may specifically include:

[0099] Step S31: Based on the description content of the created test case, determine the operation information of the operation involved in the created test case and the view information of the operation view corresponding to the involved operation.

[0100] In the embodiments of the present disclosure, operation information can be used to describe an operation. For example, the operation information can be "click the capture button", "swipe up", "switch tab", etc. The operation view can be a page, or a specific area, component, space, etc. in a page. In other words, the operation view can be an Activity, Fragement, or View. The operation view corresponding to the operation can be the execution area for performing the operation. For example, for the operation of clicking the capture button, the corresponding operation view can be "capture button". The view information can be the name, number, and other information of the operation view.

[0101] Furthermore, in this step, the description content can be identified and split based on a pre-defined semantic recognition algorithm and a text splitting algorithm, thereby obtaining the operation information of the operation involved in the created test case. Furthermore, the view information of the operation view corresponding to the operation involved can be determined based on the correspondence between the preset operation and the view information of the operation view. The view information of the operation view when executing each operation can be recorded in the correspondence.

[0102] In actual application scenarios, test cases are often written by different testers, so there will be problems with non-standard expressions. Such a situation will lead to the inability to accurately recommend use cases. In this solution, the test case can be split into operation units, that is, it is clear which operation units are included in the test case. Furthermore, in order to ensure the accuracy of the splitting, the description content of the created test case can also be displayed; and the input operation information and the view information of the corresponding operation view are received in response to the displayed description content. Specifically, the user can judge the operation designed for the created test case and the operation view corresponding to the operation based on the displayed description content, and accordingly, the operation information and the view information of the corresponding operation view can be input to the terminal.

[0103] Step S32: Combine the operation information and the corresponding view information into the first operation unit.

[0104] For example, the combination may be performed in the form of "view information.operation information" to identify the first operation unit. Figure 3 is a schematic diagram of an operation unit provided by an embodiment of the present disclosure. The first operation unit representing a series of operations involved in the created test case can be as follows: Figure 3 as shown in .

[0105] In the disclosed embodiment, based on the description content of the created test case, the operation information of the operation involved in the created test case and the view information of the operation view corresponding to the involved operation are determined. The operation information and the corresponding view information are combined into a first operation unit. In this way, by further introducing the view information of the operation view, it is possible to clearly distinguish the cases where the same operation is executed in different views, thereby ensuring the test effect.

[0106] Optionally, the above-mentioned determination of the code segment covered when executing the operation represented by the first operation unit as the operation of the code segment covered by the first operation unit may specifically include:

[0107] Step S41, executing each operation in sequence according to the order of operations involved in the created test case, and after each operation is executed, determining the first function set currently covered and the second function set covered after the previous operation is executed.

[0108] In the embodiment of the present disclosure, the code can be covered based on the characteristics of the preset coverage collection tool. In this way, coverage information can be collected after the start of operation. It should be noted that after the start of operation, the coverage information will be collected during the running progress, that is, from the opening of the application, the coverage information will be collected and recorded all the time, and the starting point of the collection cannot be set arbitrarily. Therefore, in the implementation of the present disclosure, the function set consisting of the current covered functions can be recorded after an operation is not completed. For example, the function set consisting of the functions covered by the currently executed operation can be recorded as the first function set, and the function set consisting of the functions covered by the previous operation can be recorded as the second function set. Correspondingly, the functions newly added to the first function set relative to the second function set are the code segments covered by the execution of the current operation.

[0109] Step S42: Determine the functions in the difference set between the first function set and the second function set as the code segment covered by the first operation unit corresponding to the operation.

[0110] For example, for the operation unit "Open Album", before opening the album, the functions covered by the previous operation on the application are collected. Assume that the second function set is covered at this time: Function 1 and Function 2. After clicking "Open Album", the coverage rate at this time is collected to determine the functions covered at this time. Assume that the first function set is covered at this time: Function 1, Function 2, Function 3 and Function 4. Further, by subtracting the two covered functions, the code segments "Function 3, Function 4" covered by "Open Album" can be obtained.

[0111] In the disclosed embodiment, each operation is performed in sequence according to the order of operations involved in the created test case, and after each operation is performed, the first function set currently covered and the second function set covered after the previous operation are determined. The functions in the difference set of the second function set relative to the first function set are determined as the code segments covered by the first operation units corresponding to the operations. In this way, the code segments covered by each first operation unit can be determined more accurately. At the same time, compared to the method of directly determining the code segments covered by the entire test case and establishing a preset relationship, in the disclosed embodiment, the code segments covered by each operation unit are accurately determined, that is, the covered code segments are divided in a more fine-grained manner, which can facilitate subsequent maintenance to a certain extent.

[0112] Furthermore, in the embodiment of the present disclosure, the knowledge base composed of the first preset relationship may include a view layer, a function layer, and a code layer. For example, Figure 4 is a related schematic diagram of another knowledge base provided by an embodiment of the present disclosure, wherein the main function of the view layer may be to organize operation units. Specifically, the operation units corresponding to the same view information may be divided into a group based on the view layer. The function layer may also be called the operation unit layer. The function layer may be a collection of operation units corresponding to the operations that can be executed in each operation view. The function layer may list the operation units corresponding to all required operations. In an embodiment of the present disclosure, even in the face of complex or abstract operations, such as clicking the next step on the album page, sliding the magic table on the magic table interface, and the like, the operation units corresponding to these operations may be listed in the function layer, thereby facilitating processing. The code layer may also be called the "code call chain" layer, which may refer to the functions affected by the operations represented by each operation unit in the implementation function layer. Of course, it should be noted that the "operation unit" group may also be customized based on the view layer, that is, the operation units that logically belong to a group may be set according to actual needs, and the present disclosure does not limit this.

[0113] The following is an example to illustrate: Figure 5 is a partial schematic diagram of a knowledge base provided by an embodiment of the present disclosure. For the MainActivity of a certain APP, the operation units corresponding to the operations that can be performed in the "MainActivity" view can be listed. Then, based on the coverage rate, it can be determined which functions in which classes are affected by the operations corresponding to the operation units, thereby obtaining Figure 5 Content shown.

[0114] Optionally, the following operations may also be performed in the embodiment of the present disclosure:

[0115] Step S51: In response to the adding instruction, determine the operation unit corresponding to the test case to be added as the second operation unit.

[0116] In the embodiment of the present disclosure, the input test case to be added can be received first, and based on the description of the test case to be added, the second operation unit corresponding to the test case to be added can be split. The specific splitting method can refer to the implementation method of splitting the first operation unit mentioned above, which will not be repeated here.

[0117] Step S52: Based on the first preset relationship, determine a second operation unit that is not currently recorded in the first preset relationship as a third operation unit.

[0118] In this step, the second operation unit can be searched in the first preset relationship, and if the second operation unit exists, it can be determined that the second operation unit is currently recorded in the first preset relationship. Otherwise, it can be determined that it is not currently recorded in the first preset relationship, and the second operation unit can be determined as the third operation unit.

[0119] Step S53: adding a correspondence between the third operation unit and the code segment covered by the third operation unit in the first preset relationship, and adding a correspondence between the test case to be added and the second operation unit in the second preset relationship.

[0120] In this step, the code segment that will be covered when the operation corresponding to the third operation unit is executed can be determined first, and then the corresponding relationship between the third operation unit and the code segment covered by the third operation unit can be stored in the knowledge base formed by the first preset relationship. Specifically, the third operation unit can be stored in correspondence with the covered code segment, or the third operation unit can be stored in correspondence with part of the information of the covered code segment, for example, the third operation unit can be stored in correspondence with the identifier of the covered code segment.

[0121] Furthermore, the correspondence between the test case to be added and the second operation unit can be further stored in the second preset relationship. Specifically, the test case to be added can be stored in correspondence with the second operation unit, or partial information of the test case to be added can be stored in correspondence, for example, the use case identifier is stored in correspondence with the second operation unit. It should be noted that in the case where the test case to be added is a combination of existing operation units, the third operation unit does not exist, and accordingly, the operation of adding the correspondence between the third operation unit and the code segment covered by the third operation unit may not be performed, and only the operation of adding the correspondence between the test case to be added and the second operation unit in the second preset relationship is performed.

[0122] Compared with the method in the related art that requires manual execution of a new test case each time, the amount of data in the actual application scenario is often large, and the execution cost of manual testing and the update cost of the database are often very high. In the embodiment of the present disclosure, some / all of the operation units stored in the first preset relationship and their corresponding covered code segments can be reused. In other words, when adding a new test case, the storage operation of some / all of the recorded operation units of the test case to be added can be omitted, and only the operations corresponding to some of the currently unrecorded operation units are executed, or the recorded operation units are combined without executing the operation to obtain the code call chain of the test case to be added, and the addition can be achieved by only updating the second preset relationship accordingly, thereby reducing the update cost to a certain extent.

[0123] It should be noted that in the disclosed embodiment, some test cases that need to be processed during the establishment process can be regarded as created test cases, and other test cases can be regarded as test cases to be added, so as to improve the reuse rate and reduce the overall establishment cost. In complex business scenarios, test cases are ever-changing and cannot be enumerated, while operation units can be enumerated. Which operations can be performed on a certain page is often relatively fixed. As more and more test cases are stored, the reuse rate can be higher and higher, and accordingly, the construction and maintenance costs of the knowledge base are lower.

[0124] Optionally, the following operation may also be performed in the disclosed embodiment: when the target test case passes the test operation, based on the changed code segment, the code segment corresponding to the target operation unit in the first preset relationship is updated. In the disclosed embodiment, if the test passes, it can be determined that the content of the changed code segment is correct, and accordingly, the code segment corresponding to the target operation unit in the first preset relationship can be updated to the changed code segment, thereby improving the update effect to a certain extent.

[0125] The following is an explanation based on application scenarios. In the field of testing, manual testing is still the mainstream method. One of the prominent problems of manual testing is that there are too many regression test cases, which consumes a lot of manpower and energy. If the test cases are directly stored in correspondence with the code covered by the test cases, the test cases need to be manually executed, and then the entire code part covered by the entire test case is obtained through the coverage collection tool, and then stored in the database. In the case of complex business scenarios and many test cases, the establishment and maintenance costs are very high. Suppose there are two test cases here: Test case 1: Enter the shooting page, open the album, select the material, and deselect the material. Test case 2: Enter the shooting page, open the album, select the material, and enter the shooting page. When establishing a knowledge base, these two test cases need to be executed in sequence to enter the code corresponding to these two test cases into the knowledge base. In the case that the code segment corresponding to a certain operation changes, all test cases involving the operation need to be re-executed in order to update. For example, assuming that the code related to "opening the album" changes, the above two test cases need to be executed separately, and the knowledge base is updated twice.

[0126] In the disclosed embodiments, a better knowledge base establishment method and a matching precision testing solution are provided, which can ensure that precise testing can be performed. When adding test cases to the preset relationship, only the operation units that are not currently recorded by the first preset relationship need to be added. For example, after test case 1 is stored, the operation units corresponding to the operations repeated in test case 1 in test case 2 do not need to be stored, thereby reducing costs to a certain extent. Furthermore, when updating. Only the code segment corresponding to the "open photo album" operation unit needs to be updated, which only needs to be executed once, and the knowledge base update only needs to be performed once, thereby reducing the number of executions of manual testing, reducing maintenance costs and update frequency.

[0127] At the same time, in the disclosed embodiment, by pre-establishing the first preset relationship and the second preset relationship, the test case is indirectly associated with the code, which can reduce the processing volume when matching one by one in a single preset relationship to a certain extent, and the logic is clearer and the calculation volume is smaller when recommending test cases. In addition, in the process of recommending test cases, it can be specifically recommended which operation units have changed their codes, that is, the target operation unit is determined, which can facilitate the subsequent problem to a certain extent, and conveniently focus on the operation where the problem occurs.

[0128] Figure 6 is a block diagram of a code testing device provided by an embodiment of the present disclosure, which is applied to a server, such as Figure 6 As shown, the device 20 may include:

[0129] The detection module 201 is configured to detect whether the code to be tested has been changed in response to the test operation;

[0130] A first determination module 202 is configured to determine, if the code to be tested is changed, a changed code segment to which the change belongs, and determine at least one target operation unit corresponding to the changed code segment based on a first preset relationship;

[0131] A second determination module 203 is configured to determine at least one target test case corresponding to the at least one target operation unit based on a second preset relationship;

[0132] The testing module 204 is configured to perform a testing operation on the at least one target test case.

[0133] In summary, the code testing device provided by the embodiment of the present disclosure detects whether the code to be tested has changed in response to a test operation. If the code to be tested has changed, the changed code segment to which the change belongs is determined, and at least one target operation unit corresponding to the changed code segment is determined based on the first preset relationship. At least one target test case corresponding to the at least one target operation unit is determined based on the second preset relationship. A test operation is performed on the at least one target test case. In this way, by indirectly associating the test case with the code segment through the pre-established first preset relationship and the second preset relationship, it can be ensured to a certain extent that the test case required for this time can be found more accurately, and unnecessary test cases are avoided from participating in the test link, thereby reducing the test cost and improving the test efficiency.

[0134] At the same time, by pre-establishing the first preset relationship and the second preset relationship respectively, the test case and the code segment are indirectly associated, which can further reduce the operation cost of the preset relationship.

[0135] Optionally, the device 20 includes:

[0136] A splitting module is configured to split the first operation unit corresponding to the created test case based on the description content of the created test case;

[0137] A third determining module is configured to determine a code segment covered when the operation represented by the first operating unit is executed as the code segment covered by the first operating unit;

[0138] An establishing module is configured to establish a corresponding relationship between the created test case and the first operating unit to generate the second preset relationship; and to establish a corresponding relationship between the first operating unit and the covered code segment to generate the first preset relationship.

[0139] Optionally, the splitting module is specifically configured as follows:

[0140] Based on the description content of the created test case, determine the operation information of the operation involved in the created test case and the view information of the operation view corresponding to the involved operation;

[0141] The operation information and the corresponding view information are combined into the first operation unit.

[0142] Optionally, the third determining module is specifically configured to:

[0143] Execute each operation in sequence according to the order of operations involved in the created test case, and after each operation is executed, determine the first function set currently covered and the second function set covered after the previous operation is executed;

[0144] The functions in the difference set between the first function set and the second function set are determined as code segments covered by the first operation unit corresponding to the operation.

[0145] Optionally, the device 20 further includes:

[0146] A fourth determining module is configured to determine, in response to the adding instruction, an operation unit corresponding to the test case to be added as a second operation unit;

[0147] a fifth determining module, configured to determine, based on the first preset relationship, a second operating unit that is not currently recorded by the first preset relationship, as a third operating unit;

[0148] The adding module is configured to add a corresponding relationship between the third operation unit and the code segment covered by the third operation unit in the first preset relationship, and to add a corresponding relationship between the test case to be added and the second operation unit in the second preset relationship.

[0149] Optionally, the device 20 further includes:

[0150] The updating module is configured to update the code segment corresponding to the target operation unit in the first preset relationship based on the changed code segment when the target test case passes the test operation.

[0151] According to one embodiment of the present disclosure, an electronic device is provided, comprising: a processor and a memory for storing processor executable instructions, wherein the processor is configured to implement the steps in the code testing method in any of the above embodiments when executing.

[0152] According to an embodiment of the present disclosure, a storage medium is further provided. When instructions in the storage medium are executed by a processor of an electronic device, the electronic device can execute the steps in the code testing method in any of the above embodiments.

[0153] According to one embodiment of the present disclosure, a computer program product is also provided. The computer program product includes readable program instructions. When the readable program instructions are executed by a processor of an electronic device, the electronic device can execute the steps in the code testing method in any of the above embodiments.

[0154] Figure 7 700 is a block diagram of a device for code testing according to an exemplary embodiment. For example, the device 700 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.

[0155] Reference Figure 7 , the device 700 may include one or more of the following components: a processing component 702 , a memory 704 , a power component 706 , a multimedia component 708 , an audio component 710 , an input / output (I / O) interface 712 , a sensor component 714 , and a communication component 716 .

[0156] The processing component 702 generally controls the overall operation of the device 700, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 702 may include one or more processors 720 to execute instructions to complete all or part of the steps of the above-mentioned code testing method. In addition, the processing component 702 may include one or more modules to facilitate the interaction between the processing component 702 and other components. For example, the processing component 702 may include a multimedia module to facilitate the interaction between the multimedia component 708 and the processing component 702.

[0157] The memory 704 is configured to store various types of data to support operations on the device 700. Examples of such data include instructions for any application or method operating on the device 700, contact data, phone book data, messages, pictures, videos, etc. The memory 704 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.

[0158] The power supply component 706 provides power to the various components of the device 700. The power supply component 706 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the device 700.

[0159] The multimedia component 708 includes a screen that provides an output interface between the device 700 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 708 includes a front camera and / or a rear camera. When the device 700 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.

[0160] The audio component 710 is configured to output and / or input audio signals. For example, the audio component 710 includes a microphone (MIC), and when the device 700 is in an operating mode, such as a call mode, a recording mode, and a speech recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 704 or sent via the communication component 716. In some embodiments, the audio component 710 also includes a speaker for outputting audio signals.

[0161] I / O interface 712 provides an interface between processing component 702 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.

[0162] The sensor assembly 714 includes one or more sensors for providing various aspects of status assessment for the device 700. For example, the sensor assembly 714 can detect the open / closed state of the device 700, the relative positioning of components, such as the display and keypad of the device 700, the sensor assembly 714 can also detect the position change of the device 700 or a component of the device 700, the presence or absence of user contact with the device 700, the orientation or acceleration / deceleration of the device 700, and the temperature change of the device 700. The sensor assembly 714 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 714 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 714 may also include an accelerometer, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.

[0163] The communication component 716 is configured to facilitate wired or wireless communication between the device 700 and other devices. The device 700 can access a wireless network based on a communication standard, such as WiFi, a carrier network (such as 2G, 3G, 4G or 5G), or a combination thereof. In an exemplary embodiment, the communication component 716 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 716 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.

[0164] In an exemplary embodiment, the apparatus 700 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors or other electronic components to execute the above-mentioned code testing method.

[0165] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 704 including instructions, and the instructions can be executed by a processor 720 of the device 700 to complete the above code testing method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.

[0166] Figure 8 800 is a block diagram of a device for code testing according to an exemplary embodiment. For example, the device 800 may be provided as a server. Figure 8 , the apparatus 800 includes a processing component 822, which further includes one or more processors, and a memory resource represented by a memory 832 for storing instructions executable by the processing component 822, such as an application. The application stored in the memory 832 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 822 is configured to execute instructions to perform the above-mentioned code testing method.

[0167] The device 800 may also include a power supply component 826 configured to perform power management of the device 800, a wired or wireless network interface 850 configured to connect the device 800 to a network, and an input / output (I / O) interface 858. The device 800 may operate based on an operating system stored in the memory 832, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, or the like.

[0168] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. The present disclosure is intended to cover any variations, uses or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The description and examples are to be considered exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.

[0169] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims

1. A code testing method, characterized in that: The method comprises: In response to the test operation, detecting whether the code to be tested has been changed; If the code to be tested is changed, determining a changed code segment to which the change belongs, and determining at least one target operation unit corresponding to the changed code segment based on a first preset relationship; Determining at least one target test case corresponding to the at least one target operation unit based on the second preset relationship; performing a test operation on the at least one target test case; Wherein, the method further comprises: Based on the description content of the created test case, split the first operation unit corresponding to the created test case; Determining a code segment covered when executing the operation represented by the first operation unit as the code segment covered by the first operation unit; Establishing a corresponding relationship between the created test case and the first operation unit to generate the second preset relationship; and establishing a corresponding relationship between the first operation unit and the covered code segment to generate the first preset relationship; The step of splitting the first operation unit corresponding to the created test case based on the description content of the created test case includes: Based on the description content of the created test case, determine the operation information of the operation involved in the created test case and the view information of the operation view corresponding to the involved operation; Combining the operation information and the operation view information corresponding to the operation involved into the first operation unit; The determining of the code segment covered when executing the operation represented by the first operation unit as the code segment covered by the first operation unit includes: Execute each operation in sequence according to the order of operations involved in the created test case, and after each operation is executed, determine the first function set currently covered and the second function set covered after the previous operation is executed; The functions in the difference set between the first function set and the second function set are determined as code segments covered by the first operation unit corresponding to the operation.

2. The method according to claim 1, characterized in that The method further comprises: In response to the adding instruction, determining an operation unit corresponding to the test case to be added as a second operation unit; Based on the first preset relationship, determine a second operation unit that is not currently recorded by the first preset relationship as a third operation unit; A correspondence relationship between the third operation unit and the code segment covered by the third operation unit is added to the first preset relationship, and a correspondence relationship between the test case to be added and the second operation unit is added to the second preset relationship.

3. The method according to claim 1, characterized in that The method further comprises: When the target test case passes the test operation, based on the changed code segment, the code segment corresponding to the target operation unit in the first preset relationship is updated.

4. A code testing device, characterized in that: The device comprises: A detection module is configured to detect whether the code to be tested has been changed in response to the test operation; A first determination module is configured to determine, if the code to be tested is changed, a changed code segment to which the change belongs, and determine at least one target operation unit corresponding to the changed code segment based on a first preset relationship; A second determination module is configured to determine at least one target test case corresponding to the at least one target operation unit based on a second preset relationship; A testing module, configured to perform a testing operation on the at least one target test case; Wherein, the device further comprises: A splitting module is configured to split the first operation unit corresponding to the created test case based on the description content of the created test case; A third determining module is configured to determine a code segment covered when the operation represented by the first operating unit is executed as the code segment covered by the first operating unit; an establishing module configured to establish a corresponding relationship between the created test case and the first operating unit to generate the second preset relationship; and to establish a corresponding relationship between the first operating unit and the covered code segment to generate the first preset relationship; The splitting module is specifically configured as follows: Based on the description content of the created test case, determine the operation information of the operation involved in the created test case and the view information of the operation view corresponding to the involved operation; Combining the operation information and the view information of the operation view corresponding to the operation involved into the first operation unit; The third determining module is specifically configured to: Execute each operation in sequence according to the order of operations involved in the created test case, and after each operation is executed, determine the first function set currently covered and the second function set covered after the previous operation is executed; The functions in the difference set between the first function set and the second function set are determined as code segments covered by the first operation unit corresponding to the operation.

5. The device according to claim 4, characterized in that The device also includes: A fourth determining module is configured to determine, in response to the adding instruction, an operation unit corresponding to the test case to be added as a second operation unit; a fifth determining module, configured to determine, based on the first preset relationship, a second operating unit that is not currently recorded by the first preset relationship, as a third operating unit; The adding module is configured to add a corresponding relationship between the third operation unit and the code segment covered by the third operation unit in the first preset relationship, and to add a corresponding relationship between the test case to be added and the second operation unit in the second preset relationship.

6. The device according to claim 4, characterized in that The device also includes: The updating module is configured to update the code segment corresponding to the target operation unit in the first preset relationship based on the changed code segment when the target test case passes the test operation.

7. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the method according to any one of claims 1 to 3.

8. A storage medium, characterized in that: When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device executes the method as claimed in any one of claims 1 to 3.

9. A computer program product, characterized in that The computer program product comprises readable program instructions, and when the readable program instructions are executed by a processor of an electronic device, the electronic device executes the method according to any one of claims 1 to 3.

Citation Information

Patent Citations

  • Test case determination method and apparatus

    CN106528399A