A method, device, electronic device and medium for obtaining a code use case

By building a clustering model of use cases and code, and selecting the use case collection with the highest coverage, the problems of strong subjectivity and low use case execution efficiency in traditional testing are solved, and efficient code test coverage is achieved.

CN112052160BActive Publication Date: 2024-09-06CHINA CITIC BANK CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202010785347.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-08-06
Publication Date
2024-09-06
Estimated Expiration
2040-08-06

AI Technical Summary

Technical Problem

Traditional functional testing is highly subjective in regression scope assessment and is easy to miss tests. When code merging errors or development entrainment goes online, it is difficult to ensure comprehensive testing by relying on requirements testing alone.

Method used

By establishing the matching relationship between sample use cases and sample code, unsupervised learning training is performed, a clustering model of use cases and code is constructed, code change differentiated files are obtained, the use case collection with the highest coverage is screened out, and use cases are assigned using a clustering algorithm In different sets, only some use cases are recommended for execution.

Benefits of technology

It improves testing efficiency, ensures differentiated code coverage of more than 80%, reduces use case density, and avoids unnecessary use case execution.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112052160B
    Figure CN112052160B
Patent Text Reader

Abstract

The present application provides a method, device, electronic device and medium for obtaining use cases of code, wherein the steps of the method for obtaining use cases of code are as follows: establishing a matching relationship between sample use cases and sample codes; performing unsupervised learning training on the matching relationship between sample use cases and sample codes to construct a clustering model of use cases and codes; obtaining code change differential files; screening out test cases according to code change differential files; using test cases as inputs of the clustering model of use cases and codes, so that the clustering model of use cases and codes classifies test cases and outputs a set of use cases with the highest coverage. The present application can use the relationship between use cases and codes as feature vectors, use clustering algorithms to assign use cases to different use case sets, and when recommending test cases, only recommend some use cases without executing all use cases. In this way, the differential code coverage is guaranteed to be above 80%, and the use case density is also reduced, thereby improving the test efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and more specifically, to a method, device, electronic device and medium for obtaining a use case of a code. Background Art

[0002] Traditional functional testing only focuses on black box testing at the requirements level. When performing test scope regression, the regression scope is only evaluated under the guidance of developers. The evaluation is too subjective, and it is inevitable that the evaluation is not in place, resulting in a large number of missed test problems. In addition, due to code merging errors or development and online release, it is easy to complete the test only based on the requirements, which may lead to incomplete testing.

[0003] In order to solve the problems existing in black box testing, code-based white box testing has attracted everyone's attention. The difference between white box testing and black box testing is that when white box testing executes use cases, it will pay attention to the code covered by the use cases and establish the relationship between the code and the use cases. In each round of testing, the corresponding use cases are recommended based on the changes in the code.

[0004] However, in the code, there are many basic methods that will be called by many use cases. Once such basic methods are changed, a large number of use cases will be recommended for execution, resulting in a significant increase in the number of use cases that need to be executed, and the efficiency of testers will be seriously affected. Summary of the invention

[0005] The present application provides a method, device, electronic device and medium for obtaining a use case of a code, aiming to solve at least one of the above technical defects. The technical solution adopted by the present application is as follows:

[0006] The first aspect of the present application provides a method for obtaining a use case of a code, the method comprising:

[0007] Establish a matching relationship between sample use cases and sample codes;

[0008] Performing unsupervised learning training on the matching relationship between the sample use cases and the sample codes to construct a clustering model of the use cases and codes;

[0009] Get the code change differential file;

[0010] Filter out test cases based on the code change differential files;

[0011] The test cases are used as inputs of the clustering model of the use cases and codes, so that the clustering model of the use cases and codes classifies the test cases and outputs a set of use cases with the highest coverage.

[0012] The method of the first aspect of the present application can use the relationship between use cases and codes as feature vectors, use clustering algorithms to distribute use cases into different use case sets, and when recommending test cases, only some use cases are recommended without the need to execute all use cases. In this way, the differentiated code coverage rate is guaranteed to be above 80%, and the use case density is reduced, thereby improving testing efficiency.

[0013] In the first aspect of the present application, as an optional implementation manner, the establishing a matching relationship between the sample use case and the sample code includes:

[0014] Inserting a monitoring package into the project, so as to monitor code changes in the project according to the monitoring package and determine the sample code when the sample use case is triggered for execution by a target user;

[0015] Obtaining the execution status of the sample use case;

[0016] When it is determined that the execution of the sample use case is completed based on the execution status of the sample use case, a relationship is established between the ID of the sample use case and the ID of the project, the number of lines of the sample code, and the ID of the class to which the sample code belongs, and the relationship between the sample use case ID and the ID of the project, the number of lines of the sample code, and the ID of the class to which the sample code belongs is used as a matching relationship between the sample use case and the sample code.

[0017] In this optional implementation, a matching relationship between the sample use case and the sample code may be established through the ID of the sample use case and the ID of the project, the number of lines of the sample code, and the ID of the class to which the sample code belongs.

[0018] In the first aspect of the present application, as an optional implementation, before inserting a monitoring package into the project to monitor code changes in the project according to the monitoring package when the sample use case is triggered for execution by a user and determining the sample code, the method further includes:

[0019] Obtaining IP addresses of several preset users, and using the IP address of each preset user as a unique identifier of each of the preset users;

[0020] When the sample use case is triggered to be executed by a plurality of the preset users, the target user is determined according to the unique identifier of each of the preset users.

[0021] In this optional implementation, when the sample use case is triggered for execution by multiple preset users, since the IP address can be used as a unique identifier to identify the user, the target user can be determined from the preset users through the IP address, thereby avoiding errors in establishing the relationship between the use case and the code when multiple people execute the use case.

[0022] In the first aspect of the present application, as an optional implementation, the matching relationship between the sample use cases and the sample codes is subjected to unsupervised learning training to construct a clustering model of use cases and codes, including:

[0023] Convert the relationship between the sample use case ID and the project ID, the number of lines of the sample code, and the ID of the class to which the sample code belongs into a relationship matrix;

[0024] Using the relationship matrix as training data, training a plurality of preset clustering models, and determining an optimal clustering model from the plurality of preset clustering models according to the training results of the plurality of preset clustering models;

[0025] The optimal clustering model is used as the clustering model of the use cases and codes.

[0026] In this optional implementation, several preset clustering models are trained through a relationship matrix to determine the optimal clustering model.

[0027] In the first aspect of the present application, as an optional implementation, the step of screening out test cases according to the code change differential file includes:

[0028] Obtaining line number information of the changed code in the code change differential file;

[0029] According to the line number information of the changed code and the matching relationship between the sample use cases and the sample code, use cases involved in the change are screened out from a number of the sample use cases and used as the test cases.

[0030] In this optional implementation, by obtaining the line number information of the changed code in the code change differential file, it is possible to filter out the use cases involved in the change from a number of the sample use cases based on the line number information of the changed code, the matching relationship between the sample use cases and the sample code, and use them as the test cases.

[0031] In the first aspect of the present application, as an optional implementation, before obtaining the code change differential file, the method further includes:

[0032] When creating a code branch, keep the original version of the JAVA file;

[0033] When a new version of the JAVA file is submitted, the original version of the JAVA file is compared with the new version of the JAVA file, and the code change difference file is generated.

[0034] In this optional implementation, the code change differential file can be generated by comparing the original version of the JAVA file with the new version of the JAVA file.

[0035] In the first aspect of the present application, as an optional implementation, the using the test case as the input of the clustering model of the use case and the code so that the clustering model of the use case and the code classifies the test case and outputs a set of use cases with the highest coverage, including:

[0036] Using the test case as an input of the clustering model of the use case and code, so that the clustering model of the use case and code outputs the coverage of the test case;

[0037] Determine a set of test cases with the highest coverage rate according to the coverage rate of the test cases;

[0038] And, after determining the set of test cases with the highest coverage according to the coverage of the test cases, the method further includes:

[0039] Execute each use case in the use case set with the highest coverage rate on the test code, and count the use case density of the test code and the coverage rate of each use case in the use case set with the highest coverage rate, so as to enable the tester to evaluate.

[0040] In this optional implementation, the set of test cases with the highest coverage can be determined through the coverage of the test cases.

[0041] A second aspect of the present application provides a code use case acquisition device, the use case acquisition device comprising:

[0042] Establish a module for establishing a matching relationship between sample use cases and sample codes;

[0043] A construction module, used for performing unsupervised learning training on the matching relationship between the sample use cases and the sample codes to construct a clustering model of the use cases and codes;

[0044] A first acquisition module is used to acquire a code change differential file;

[0045] A screening module, used to screen out test cases according to the code change differential file;

[0046] An output module is used to use the test case as an input of the clustering model of the test case and the code, so that the clustering model of the test case and the code classifies the test case and outputs a set of test cases with the highest coverage.

[0047] The code use case acquisition device provided in the second aspect of the present application can use the use case and code relationship as a feature vector by executing the code use case acquisition method, and use a clustering algorithm to distribute the use cases to different use case sets. When recommending test cases, only some use cases are recommended, and there is no need to execute all use cases. In this way, the differentiated code coverage rate is guaranteed to be above 80%, and the use case density is reduced, thereby improving the testing efficiency.

[0048] A third aspect of the present application provides an electronic device, comprising:

[0049] Processor; and

[0050] A memory configured to store machine-readable instructions, which, when executed by the processor, causes the processor to execute the method for obtaining a use case of the code provided in the first aspect of the present application.

[0051] The electronic device of the code provided in the third aspect of the present application can use the use case acquisition method of the execution code to take the relationship between the use case and the code as a feature vector, and use the clustering algorithm to distribute the use cases to different use case sets. When recommending test cases, only some use cases are recommended, and there is no need to execute all use cases. In this way, the differentiated code coverage rate is guaranteed to be above 80%, and the use case density is reduced, thereby improving the testing efficiency.

[0052] The fourth aspect of the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the use case acquisition method provided in the first aspect of the present application.

[0053] The computer-readable storage medium of the code provided in the fourth aspect of the present application can use the use case acquisition method of the execution code to take the relationship between the use case and the code as a feature vector, and use the clustering algorithm to distribute the use cases to different use case sets. When recommending test cases, only some use cases are recommended, and there is no need to execute all use cases. In this way, the differentiated code coverage rate is guaranteed to be above 80%, and the use case density is reduced, thereby improving the testing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0054] The above and / or additional aspects and advantages of the present application will become apparent and easily understood from the following description of the embodiments in conjunction with the accompanying drawings, in which:

[0055] Figure 1 It is a flowchart of a method for obtaining a use case of a code provided in Example 1 of the present application;

[0056] Figure 2 It is a structural diagram of a code use case acquisition device provided in Example 2 of the present application;

[0057] Figure 3It is a structural schematic diagram of an electronic device provided in Example 3 of the present application. DETAILED DESCRIPTION

[0058] The present application is described in detail below, and examples of embodiments of the present application are shown in the accompanying drawings, wherein the same or similar numbers throughout represent the same or similar components or components with the same or similar functions.

[0059] It will be understood by those skilled in the art that, unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as those generally understood by those skilled in the art to which this application belongs. It should also be understood that terms such as those defined in general dictionaries should be understood to have meanings consistent with those in the context of the prior art, and will not be interpreted with idealized or overly formal meanings unless specifically defined as here.

[0060] It will be understood by those skilled in the art that, unless expressly stated, the singular forms "one", "said", and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present application refers to the presence of the features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof. It should be understood that when we refer to an element as being "connected" or "coupled" to another element, it may be directly connected or coupled to the other element, or there may be an intermediate element. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein includes all or any unit and all combinations of one or more associated listed items.

[0061] See also Figure 1 , Figure 1 1 is a flowchart of a method for obtaining a code example provided in an embodiment of the present application. Figure 1 As shown, the method for obtaining a use case of a code in an embodiment of the present application includes the steps of:

[0062] 101. Establish a matching relationship between sample use cases and sample codes;

[0063] 102. Perform unsupervised learning training on the matching relationship between sample use cases and sample codes to build a clustering model of use cases and codes;

[0064] 103. Obtain code change differential files;

[0065] 104. Filter out test cases based on code change differential files;

[0066] 105. Use the test cases as input to the clustering model of use cases and codes, so that the clustering model of use cases and codes can classify the test cases and output the set of use cases with the highest coverage.

[0067] The method of the embodiment of the present application can use the relationship between use cases and codes as feature vectors, use a clustering algorithm to distribute use cases into different use case sets, and when recommending test cases, only some use cases are recommended without the need to execute all use cases. In this way, the differentiated code coverage rate is guaranteed to be above 80%, and the use case density is reduced, thereby improving testing efficiency.

[0068] In the embodiment of the present application, as an optional implementation mode, establishing a matching relationship between a sample use case and a sample code includes:

[0069] Insert a monitoring package into the project, so that when the sample use case is triggered by the target user, the code changes in the project are monitored according to the monitoring package, and the sample code is determined;

[0070] Get the execution status of the sample use case;

[0071] When it is determined that the execution of the sample use case is completed based on the execution status of the sample use case, a relationship is established between the ID of the sample use case and the ID of the project, the number of lines of sample code, and the ID of the class to which the sample code belongs. The relationship between the ID of the sample use case and the ID of the project, the number of lines of sample code, and the ID of the class to which the sample code belongs is used as a matching relationship between the sample use case and the sample code.

[0072] In this optional implementation, a matching relationship between the sample use case and the sample code can be established through the ID of the sample use case and the ID of the project, the number of lines of the sample code, and the ID of the class to which the sample code belongs.

[0073] In the embodiment of the present application, as an optional implementation, before inserting a monitoring package into the project to monitor code changes in the project according to the monitoring package when the sample use case is triggered by the user and determining the sample code, the method further includes:

[0074] Obtain the IP addresses of several preset users, and use the IP address of each preset user as a unique identifier of each preset user;

[0075] When the sample use case is triggered and executed by multiple preset users, the target user is determined based on the unique identifier of each preset user.

[0076] In this optional implementation, when the sample use case is triggered for execution by multiple preset users, since the IP address can be used as a unique identifier to identify the user, the target user can be determined from the preset users through the IP address, thereby avoiding errors in establishing the relationship between the use case and the code when multiple people execute the use case.

[0077] In the embodiment of the present application, as an optional implementation, the matching relationship between the sample use cases and the sample codes is trained by unsupervised learning to construct a clustering model of the use cases and the codes, including:

[0078] Convert the relationship between the sample use case ID and the project ID, the number of lines of sample code, and the ID of the class to which the sample code belongs into a relationship matrix;

[0079] Using the relationship matrix as training data, training a plurality of preset clustering models, and determining an optimal clustering model from the plurality of preset clustering models according to the training results of the plurality of preset clustering models;

[0080] The optimal clustering model is taken as the clustering model of use cases and codes.

[0081] In this optional implementation, several preset clustering models are trained through a relationship matrix to determine the optimal clustering model.

[0082] In an embodiment of the present application, as an optional implementation, the test cases are screened out according to the code change difference file, including:

[0083] Get the line number information of the changed code in the code change differential file;

[0084] According to the line number information of the changed code and the matching relationship between the sample use cases and the sample code, the use cases involved in the change are screened out from several sample use cases and used as test cases.

[0085] In this optional implementation, by obtaining the line number information of the changed code in the code change differential file, the use cases involved in the change can be filtered out from several sample use cases and used as test cases based on the line number information of the changed code, the matching relationship between the sample use cases and the sample code.

[0086] In the embodiment of the present application, as an optional implementation, before obtaining the code change differential file, the method further includes:

[0087] When creating a code branch, keep the original version of the JAVA file;

[0088] When a new version of a JAVA file is submitted, the original version of the JAVA file is compared with the new version of the JAVA file, and a code change difference file is generated.

[0089] In this optional implementation, a code change differential file can be generated by comparing the original version of the JAVA file with the new version of the JAVA file.

[0090] In an embodiment of the present application, as an optional implementation, the test case is used as an input of the clustering model of the use case and the code, so that the clustering model of the use case and the code classifies the test case and outputs a set of use cases with the highest coverage, including:

[0091] The test cases are used as the input of the clustering model of the use cases and codes, so that the clustering model of the use cases and codes outputs the coverage of the test cases;

[0092] Determine the set of test cases with the highest coverage based on the coverage of the test cases;

[0093] And, after determining the set of test cases with the highest coverage according to the coverage of the test cases, the method further includes:

[0094] Each use case in the set of use cases with the highest coverage is executed for the test code, and the use case density of the test code and the coverage of each use case in the set of use cases with the highest coverage are counted to enable the tester to evaluate.

[0095] In this optional implementation, the set of test cases with the highest coverage can be determined through the coverage of the test cases.

[0096] See also Figure 2 , Figure 2 Schematic diagram of a code use case acquisition device provided in an embodiment of the present application. Figure 2 As shown, the use case acquisition device of the code includes:

[0097] Establishing module 201, used to establish a matching relationship between sample use cases and sample codes;

[0098] A construction module 202 is used to perform unsupervised learning training on the matching relationship between the sample use cases and the sample codes to construct a clustering model of the use cases and the codes;

[0099] The first acquisition module 203 is used to acquire a code change differential file;

[0100] A screening module 204 is used to screen out test cases according to the code change differential files;

[0101] The output module 205 is used to use the test cases as inputs of the clustering model of use cases and codes, so that the clustering model of use cases and codes classifies the test cases and outputs a set of use cases with the highest coverage.

[0102] The code use case acquisition device provided in the embodiment of the present application can use the use case and code relationship as a feature vector by executing the code use case acquisition method, and use a clustering algorithm to distribute the use cases to different use case sets. When recommending test cases, only some use cases are recommended, and there is no need to execute all use cases. In this way, the differentiated code coverage rate is guaranteed to be above 80%, and the use case density is reduced, thereby improving the testing efficiency.

[0103] In the embodiment of the present application, as an optional implementation, the specific manner in which the establishment module 201 performs the establishment of the matching relationship between the sample use case and the sample code is:

[0104] Insert a monitoring package into the project, so that when the sample use case is triggered by the target user, the code changes in the project are monitored according to the monitoring package, and the sample code is determined;

[0105] Get the execution status of the sample use case;

[0106] When it is determined that the execution of the sample use case is completed based on the execution status of the sample use case, a relationship is established between the ID of the sample use case and the ID of the project, the number of lines of sample code, and the ID of the class to which the sample code belongs. The relationship between the ID of the sample use case and the ID of the project, the number of lines of sample code, and the ID of the class to which the sample code belongs is used as a matching relationship between the sample use case and the sample code.

[0107] In this optional implementation, a matching relationship between the sample use case and the sample code can be established through the ID of the sample use case and the ID of the project, the number of lines of the sample code, and the ID of the class to which the sample code belongs.

[0108] In the embodiment of the present application, as an optional implementation, the code use case acquisition device of the embodiment of the present application further includes a second acquisition module and a determination module, wherein:

[0109] The second acquisition module is used to acquire the IP addresses of several preset users and use the IP address of each preset user as a unique identifier of each preset user;

[0110] The determination module is used to determine the target user according to the unique identifier of each preset user when the sample use case is triggered for execution by multiple preset users.

[0111] In this optional implementation, when the sample use case is triggered for execution by multiple preset users, since the IP address can be used as a unique identifier to identify the user, the target user can be determined from the preset users through the IP address, thereby avoiding errors in establishing the relationship between the use case and the code when multiple people execute the use case.

[0112] In the embodiment of the present application, as an optional implementation, the construction module 202 performs unsupervised learning training on the matching relationship between the sample use cases and the sample codes to construct a clustering model of the use cases and the codes in the following specific manner:

[0113] Convert the relationship between the sample use case ID and the project ID, the number of lines of sample code, and the ID of the class to which the sample code belongs into a relationship matrix;

[0114] Using the relationship matrix as training data, training a plurality of preset clustering models, and determining an optimal clustering model from the plurality of preset clustering models according to the training results of the plurality of preset clustering models;

[0115] The optimal clustering model is taken as the clustering model of use cases and codes.

[0116] In this optional implementation, several preset clustering models are trained through a relationship matrix to determine the optimal clustering model.

[0117] In the embodiment of the present application, as an optional implementation, the specific manner in which the screening module 204 screens out test cases according to the code change differential file is:

[0118] Get the line number information of the changed code in the code change differential file;

[0119] According to the line number information of the changed code and the matching relationship between the sample use cases and the sample code, the use cases involved in the change are screened out from several sample use cases and used as test cases.

[0120] In this optional implementation, by obtaining the line number information of the changed code in the code change differential file, the use cases involved in the change can be filtered out from several sample use cases and used as test cases based on the line number information of the changed code, the matching relationship between the sample use cases and the sample code.

[0121] In the embodiment of the present application, as an optional implementation, the code use case acquisition device of the embodiment of the present application further includes a storage module and a comparison module, wherein:

[0122] The storage module is used to keep the original version of the JAVA file when creating a code branch;

[0123] The comparison module is used to compare the original version of the JAVA file with the new version of the JAVA file when the new version of the JAVA file is submitted, and generate a code change difference file.

[0124] In this optional implementation, a code change differential file can be generated by comparing the original version of the JAVA file with the new version of the JAVA file.

[0125] In the embodiment of the present application, as an optional implementation, the output module 205 executes the test case as the input of the clustering model of the use case and the code, so that the clustering model of the use case and the code classifies the test case and outputs the use case set with the highest coverage rate. The specific method is:

[0126] The test cases are used as the input of the clustering model of the use cases and codes, so that the clustering model of the use cases and codes outputs the coverage of the test cases;

[0127] According to the coverage of test cases, determine the set of test cases with the highest coverage.

[0128] Accordingly, the code use case acquisition device of the embodiment of the present application further includes a statistical module, wherein:

[0129] The statistical module is used to execute each use case in the use case set with the highest coverage rate on the test code, and to count the use case density of the test code and the coverage rate of each use case in the use case set with the highest coverage rate, so as to enable the tester to evaluate.

[0130] In this optional implementation, the set of test cases with the highest coverage can be determined through the coverage of the test cases.

[0131] An embodiment of the present application provides an electronic device, comprising:

[0132] Processor 301; and

[0133] The memory 302 is configured to store machine-readable instructions. When the instructions are executed by the processor 301, the processor 301 executes the use case acquisition method of the code provided in the first embodiment of the present application.

[0134] Those skilled in the art will appreciate that the electronic device provided by the embodiments of the present application can be specially designed and manufactured for the desired purpose, or can also include known devices in general-purpose computers. For example, the electronic device can be a mobile phone, a tablet computer, a notebook computer, an ultra-mobile personal computer (ultra-mobile personal computer, UMPC), a netbook and other devices, and the embodiments of the present application do not impose any restrictions on the specific type of the electronic device. These devices have computer programs stored therein, and these computer programs are selectively activated or reconstructed. Such a computer program can be stored in a device (e.g., computer) readable medium or in a medium suitable for storing electronic instructions and coupled to any type of bus respectively.

[0135] The memory 302 in the electronic device of the present application can be a ROM (Read-Only Memory) or other types of static storage devices that can store static information and instructions, can be a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, can also be an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read-Only Memory) or other optical disk storage, optical disk storage (including compressed optical disk, laser disk, optical disk, digital versatile disk, Blu-ray disk, etc.), magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited to this.

[0136] The processor 301 in the electronic device of the present application can be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field-Programmable Gate Array) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. It can implement or execute various exemplary logic blocks, modules and circuits described in conjunction with the disclosure of the present application. The processor 301 can also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.

[0137] The electronic device of the code provided in the embodiment of the present application can use the use case acquisition method of the execution code to take the relationship between the use case and the code as a feature vector, and use the clustering algorithm to distribute the use cases to different use case sets. When recommending test cases, only some use cases are recommended, and there is no need to execute all use cases. In this way, the differentiated code coverage rate is guaranteed to be above 80%, and the use case density is reduced, thereby improving the testing efficiency.

[0138] An embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon. When the program is executed by a processor, the use case acquisition method provided in the first embodiment of the present application is implemented.

[0139] The computer-readable medium provided in the present application includes, but is not limited to, any type of disk (including floppy disk, hard disk, optical disk, CD-ROM, and magneto-optical disk), ROM, RAM, EPROM (Erasable Programmable Read-Only Memory), EEPROM, flash memory, magnetic card or optical card. In other words, the readable medium includes any medium that can store or transmit information in a readable form by a device (e.g., a computer).

[0140] The computer-readable storage medium of the code provided in the embodiment of the present application can use the use case acquisition method of the execution code to use the relationship between the use case and the code as a feature vector, and use the clustering algorithm to distribute the use cases to different use case sets. When recommending test cases, only some use cases are recommended, and there is no need to execute all use cases. In this way, the differentiated code coverage rate is guaranteed to be more than 80%, and the use case density is reduced, thereby improving the testing efficiency.

[0141] It will be appreciated by those skilled in the art that the various operations, methods, steps, measures, and schemes in the processes discussed in this application may be alternated, altered, combined, or deleted. Furthermore, other steps, measures, and schemes in the various operations, methods, and processes discussed in this application may also be alternated, altered, rearranged, decomposed, combined, or deleted. Furthermore, the steps, measures, and schemes in the various operations, methods, and processes provided in this application in the prior art may also be alternated, altered, rearranged, decomposed, combined, or deleted.

[0142] The terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features. In the description of this application, unless otherwise specified, "plurality" means two or more.

[0143] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.

[0144] The above description is only a partial implementation method of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A method for obtaining use cases of codes, It is characterized in that The method comprises: Establish a matching relationship between sample use cases and sample codes; Performing unsupervised learning training on the matching relationship between the sample use cases and the sample codes to construct a clustering model of the use cases and codes; Get the code change differential file; Filter out test cases based on the code change differential files; Using the test cases as input to the clustering model of the test cases and codes, so that the clustering model of the test cases and codes classifies the test cases and outputs a set of test cases with the highest coverage; The establishing of a matching relationship between the sample use case and the sample code includes: Inserting a monitoring package into the project, so as to monitor code changes in the project according to the monitoring package and determine the sample code when the sample use case is triggered for execution by a target user; Obtaining the execution status of the sample use case; When it is determined that the execution of the sample use case is completed based on the execution status of the sample use case, a relationship is established between the ID of the sample use case and the ID of the project, the number of lines of the sample code, and the ID of the class to which the sample code belongs, and the relationship between the sample use case ID and the ID of the project, the number of lines of the sample code, and the ID of the class to which the sample code belongs is used as a matching relationship between the sample use case and the sample code.

2. The use case acquisition method according to claim 1, It is characterized in that Before inserting a monitoring package into the project to monitor code changes in the project according to the monitoring package when the sample use case is triggered for execution by a user and determining the sample code, the method further includes: Obtaining IP addresses of several preset users, and using the IP address of each preset user as a unique identifier of each of the preset users; When the sample use case is triggered to be executed by a plurality of the preset users, the target user is determined according to the unique identifier of each of the preset users.

3. The use case acquisition method according to claim 1, It is characterized in that The performing unsupervised learning training on the matching relationship between the sample use cases and the sample codes to construct a clustering model of use cases and codes includes: Convert the relationship between the sample use case ID and the project ID, the number of lines of the sample code, and the ID of the class to which the sample code belongs into a relationship matrix; Using the relationship matrix as training data, training a plurality of preset clustering models, and determining an optimal clustering model from the plurality of preset clustering models according to the training results of the plurality of preset clustering models; The optimal clustering model is used as the clustering model of the use cases and codes.

4. The use case acquisition method according to claim 1, It is characterized in that The step of screening out test cases according to the code change differential file includes: Obtaining line number information of the changed code in the code change differential file; According to the line number information of the changed code and the matching relationship between the sample use cases and the sample code, use cases involved in the change are screened out from a number of the sample use cases and used as the test cases.

5. The use case acquisition method according to claim 4, It is characterized in that Before obtaining the code change differential file, the method further includes: When creating a code branch, keep the original version of the JAVA file; When a new version of the JAVA file is submitted, the original version of the JAVA file is compared with the new version of the JAVA file, and the code change difference file is generated.

6. The use case acquisition method according to claim 1, It is characterized in that The step of using the test case as an input of the clustering model of the test case and the code so that the clustering model of the test case and the code classifies the test case and outputs a set of test cases with the highest coverage rate includes: Using the test case as an input of the clustering model of the use case and code, so that the clustering model of the use case and code outputs the coverage of the test case; Determine a set of test cases with the highest coverage rate according to the coverage rate of the test cases; And, after determining the set of test cases with the highest coverage according to the coverage of the test cases, the method further includes: Execute each use case in the use case set with the highest coverage rate on the test code, and count the use case density of the test code and the coverage rate of each use case in the use case set with the highest coverage rate, so as to enable the tester to evaluate.

7. A device for obtaining a use case of a code, It is characterized in that The use case acquisition device comprises: Establish a module to establish a matching relationship between sample use cases and sample codes, including: Inserting a monitoring package into the project, so as to monitor code changes in the project according to the monitoring package and determine the sample code when the sample use case is triggered for execution by a target user; Obtaining the execution status of the sample use case; When it is determined according to the execution status of the sample use case that the execution of the sample use case is completed, a relationship is established between the ID of the sample use case and the ID of the project, the number of lines of the sample code, and the ID of the class to which the sample code belongs, and the relationship between the ID of the sample use case and the ID of the project, the number of lines of the sample code, and the ID of the class to which the sample code belongs is used as a matching relationship between the sample use case and the sample code; A construction module, used for performing unsupervised learning training on the matching relationship between the sample use cases and the sample codes to construct a clustering model of the use cases and codes; A first acquisition module is used to acquire a code change differential file; A screening module, used to screen out test cases according to the code change differential file; An output module is used to use the test case as an input of the clustering model of the test case and the code, so that the clustering model of the test case and the code classifies the test case and outputs a set of test cases with the highest coverage.

8. An electronic device, It is characterized in that It includes: Processor; and A memory configured to store machine-readable instructions, which, when executed by the processor, causes the processor to execute the use case acquisition method of the code according to any one of claims 1 to 6.

9. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the program is executed by a processor, the method for obtaining a use case of the code described in any one of claims 1 to 6 is implemented.