Code testing method, device, computer device and storage medium for language conversion

By receiving the caller's test request and initial code data to be tested, the processing scripting language of the target test tool is determined and scripting language conversion is carried out, which solves the compatibility problem between different scripting languages, and uses the optimal test tool to perform code coverage testing, improving the test effect.

CN115328783BActive Publication Date: 2025-05-27PING AN TECH (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210980576.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-08-16
Publication Date
2025-05-27
Estimated Expiration
2042-08-16

AI Technical Summary

Technical Problem

In existing code coverage testing, software applications written in different scripting languages ​​need testing tools in the corresponding language to be tested, resulting in the inability to perform testing when the scripting language of the software application is inconsistent with the scripting language of the provided test tools, or the optimal testing tools cannot be used.

Method used

Provide a code testing method for converting languages. By receiving the caller's test request and initial code data to be tested, the script language of the target test tool is determined. If the script language of the initial code data to be tested is inconsistent with the script language of the target test tool, the script language is converted to obtain the target code data to be tested, so that it is consistent with the script language of the target test tool, and the code coverage test is carried out.

Benefits of technology

Through script language conversion, test failures caused by inconsistency in script languages ​​are avoided, and the code coverage test can be used to use test tools with better results, which improves the test effect.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115328783B_ABST
    Figure CN115328783B_ABST
Patent Text Reader

Abstract

The present invention provides a code testing method, device, computer device and storage medium for converting languages, including: receiving a test request sent by a calling party and initial code data to be tested corresponding to the test request; determining a target test tool for testing the initial code data to be tested and the processing script language of the target test tool; when the code script language of the initial code data to be tested is inconsistent with the processing script language of the target test tool, performing script language conversion on the initial code data to be tested to obtain target code data to be tested; the code script language of the target code data to be tested is consistent with the processing script language of the target test tool; based on the target test tool, performing code coverage testing on the target code data to be tested to obtain the target code coverage rate of the target code data to be tested. It avoids the problems of being unable to perform code coverage testing and being unable to use a better-performing test tool to perform code coverage testing, and improves the test effect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of application testing, and particularly to a code testing method, device, computer device and storage medium for converting languages. Background Art

[0002] In the modern software application R & D system, test measurement activities are an essential part of the software R & D process. Through measurement, the effectiveness, integrity of the test, and the quality of the work products are judged, and quantitative guidance is provided for the improvement of the R & D process. The measurement scope includes time schedule, cost investment, scale, test quality, product quality, etc. Among them, the measurement of test quality is the most important dimension, which has direct reference value for evaluating the final release quality of the work products. Test quality measurement includes various methods, such as requirement coverage rate, use case pass rate, code coverage rate, etc. Among them, the measurement of code coverage rate is the most accurate and intuitive method to reflect the test effect.

[0003] In the existing code coverage test, software applications written in different scripting languages require corresponding language test tools for testing. When the scripting language of the software application to be tested is inconsistent with the scripting language of the provided test tool, testing cannot be carried out; or there are multiple provided test tools corresponding to different scripting languages respectively. If the scripting language of the software application can be consistent with the scripting language of one of the provided test tools, but this test tool is not the most optimal, and the scripting language corresponding to the most optimal test tool is inconsistent with the scripting language of the software application, then one has to settle for the test tool with consistent scripting language, resulting in a reduction in the test effect. Summary of the Invention

[0004] In view of the deficiencies in the prior art, the present invention provides a code testing method, device, computer device and storage medium for converting languages.

[0005] In a first aspect, in one embodiment, the present invention provides a code testing method for converting languages, including:

[0006] Receiving a test request sent by a calling party and initial code data to be tested corresponding to the test request;

[0007] Determining a target test tool for testing the initial code data to be tested and the processing scripting language of the target test tool;

[0008] If the code scripting language of the initial code data to be tested is inconsistent with the processing scripting language of the target test tool, performing scripting language conversion on the initial code data to be tested to obtain target code data to be tested; the code scripting language of the target code data to be tested is consistent with the processing scripting language of the target test tool;

[0009] Based on a target test tool, perform a code coverage test on target code data to be tested, and obtain the target code coverage rate of the target code data to be tested.

[0010] In one embodiment, determining a target test tool for testing initial code data to be tested includes:

[0011] Parse the test request to obtain the target tool type of the test tool for testing the initial code data to be tested;

[0012] Determine the test tool that matches the target tool type as the target test tool.

[0013] In one embodiment, determining a target test tool for testing initial code data to be tested includes:

[0014] Determine the target application type of the application to be tested corresponding to the initial code data to be tested;

[0015] Obtain a preset test tool library; the test tool library includes multiple sample test tools and the sample application types of the sample test tools;

[0016] According to the target application type, match the corresponding sample application type in the test tool library, and determine the sample test tool corresponding to the matched sample application type as the target test tool.

[0017] In one embodiment, performing a script language conversion on the initial code data to be tested to obtain target code data to be tested includes:

[0018] Invoke a preset script language conversion engine;

[0019] Based on the script language conversion engine, perform a script language conversion on the initial code data to be tested to obtain target code data to be tested.

[0020] In one embodiment, based on the target test tool, perform a code coverage test on the target code data to be tested to obtain the target code coverage rate of the target code data to be tested, including:

[0021] Based on the target test tool, perform code execution on the target code data to be tested to obtain the target code coverage data of the target code data to be tested;

[0022] Determine the target code coverage rate of the target code coverage data.

[0023] In one embodiment, determining the target code coverage rate of the target code coverage data includes:

[0024] Determine the executed code data and the total code data in the target code coverage data;

[0025] Determine the target code coverage rate according to the quantity ratio of the executed code data and the total code data.

[0026] In one embodiment, after the step of obtaining the target code coverage rate of the target code to be tested, the above code testing method for converting languages further includes:

[0027] Evaluate and analyze the target code coverage rate to obtain a coverage analysis report corresponding to the target code coverage rate;

[0028] Output a prompt message according to the coverage analysis report.

[0029] In a second aspect, in one embodiment, the present invention provides a code testing device for converting languages, including:

[0030] A receiving and obtaining module, configured to receive a test request sent by a calling party and the initial code to be tested corresponding to the test request;

[0031] A tool determination module, configured to determine a target test tool for testing the initial code to be tested and the processing script language of the target test tool;

[0032] A language conversion module, if the code script language of the initial code to be tested is inconsistent with the processing script language of the target test tool, then configured to perform script language conversion on the initial code to be tested to obtain target code to be tested; the code script language of the target code to be tested is consistent with the processing script language of the target test tool;

[0033] A coverage testing module, configured to perform code coverage testing on the target code to be tested based on the target test tool to obtain the target code coverage rate of the target code to be tested.

[0034] In a third aspect, in one embodiment, the present invention provides a computer device, including a memory and a processor; the memory stores a computer program, and the processor is configured to run the computer program in the memory to execute the steps in the code testing method for converting languages in any of the above embodiments.

[0035] In a fourth aspect, in one embodiment, the present invention provides a storage medium, the storage medium stores a computer program, and the computer program is loaded by a processor to execute the steps in the code testing method for converting languages in any of the above embodiments.

[0036] Through the above code testing method, device, computer equipment and storage medium for converting languages, by using the accessed script language conversion mechanism, when the caller sends a test request to perform code coverage testing on the initial code data to be tested, the processing script language of the target test tool can be determined first. If the processing script language of the target test tool is inconsistent with the code script language of the initial code data to be tested, then the script language can be converted to make them consistent, that is, the target code data to be tested is obtained, and finally code coverage testing is performed on the target code data to be tested. Through script language conversion, it is possible to avoid the problem that the code data to be tested cannot be subjected to code coverage testing due to inconsistent script languages, and it is also possible to avoid the problem that the code data to be tested cannot use a better test tool to perform code coverage testing due to inconsistent script languages, thereby improving the test effect of code coverage testing. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following will briefly introduce the accompanying drawings required for the description of the embodiments. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For those skilled in the art, without creative efforts, other accompanying drawings can be obtained based on these drawings.

[0038] Figure 1 It is a schematic diagram of the scenario of the code testing method for converting languages in an embodiment of the present invention;

[0039] Figure 2 It is a schematic flowchart of the code testing method for converting languages in an embodiment of the present invention;

[0040] Figure 3 It is a schematic flowchart of the specific process for determining the target test tool in an embodiment of the present invention;

[0041] Figure 4 It is a schematic flowchart of the specific process for determining the target test tool in another embodiment of the present invention;

[0042] Figure 5 It is a schematic flowchart of the specific process for script language conversion in an embodiment of the present invention;

[0043] Figure 6 It is a schematic flowchart of the specific process for determining the target code coverage rate in an embodiment of the present invention;

[0044] Figure 7 It is a schematic diagram of the structure of the code testing device for converting languages in an embodiment of the present invention;

[0045] Figure 8 It is a schematic diagram of the internal structure of a computer device in an embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0046] The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.

[0047] In the description of the present invention, it should be understood that the terms "center", "longitudinal", "transverse", "length", "width", "thickness", "upper", "lower", "front", "rear", "left", "right", "vertical", "horizontal", "top", "bottom", "inner", "outer", etc. indicate the orientation or positional relationship based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and thus cannot be understood as a limitation on the present invention. In addition, the terms "first" and "second" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance or implicitly indicating the quantity of the indicated technical features. Thus, the features defined with "first" and "second" may explicitly or implicitly include one or more of the described features. In the description of this application, "a plurality" means two or more, unless otherwise specifically defined. In this application, the term "exemplary" is used to mean "serving as an example, illustration, or description". Any embodiment described as "exemplary" in this application is not necessarily to be construed as more preferred or more advantageous than other embodiments. In order for any person skilled in the art to implement and use the present invention, the following description is given. In the following description, details are set forth for the purpose of explanation. It should be understood by those skilled in the art that the present invention may be practiced without these specific details. In other instances, well-known structures and processes are not described in detail to avoid obscuring the description of the present invention with unnecessary details. Therefore, the present invention is not intended to be limited to the embodiments shown, but is to be accorded the widest scope consistent with the principles and features disclosed in this application.

[0048] The code testing method for converting languages in the embodiments of the present invention is applied to a code testing device for converting languages, and the code testing device for converting languages is set in a computer device; the computer device may be a terminal, for example, a mobile phone or a tablet computer, and the computer device may also be a server, or a service cluster composed of multiple servers.

[0049] As Figure 1 shown, Figure 1FIG. 0 is a schematic diagram of an application scenario of the code testing method for language conversion in an embodiment of the present invention. The application scenario of the code testing method for language conversion in an embodiment of the present invention includes a computer device 100 (a code testing device based on a version is integrated in the computer device 100), and a computer-readable storage medium in which the code testing method for language conversion runs in the computer device 100 to execute the steps of the code testing method for language conversion.

[0050] It can be understood that Figure 1 The computer device in the application scenario of the code testing method for language conversion shown, or the devices included in the computer device do not constitute a limitation to the embodiments of the present invention. That is, the number of devices, the types of devices in the application scenario of the code testing method for language conversion, or the number of devices included in each device, the types of devices do not affect the overall implementation of the technical solution in the embodiments of the present invention, and can all be regarded as equivalent replacements or derivatives of the technical solution required to be protected in the embodiments of the present invention.

[0051] The computer device 100 in the embodiments of the present invention can be an independent device, or a device network or device cluster composed of devices. For example, the computer device 100 described in the embodiments of the present invention includes, but is not limited to, a computer, a network host, a single network device, a set of multiple network devices, or cloud devices composed of multiple devices. Among them, cloud devices are composed of a large number of computers or network devices based on cloud computing.

[0052] Those skilled in the art can understand that Figure 1 The application scenario shown in Figure 1 is only an application scenario corresponding to the technical solution of the present invention, and does not constitute a limitation to the application scenario of the technical solution of the present invention. Other application scenarios can also include more or fewer computer devices than shown in Figure 1 For example, only 1 computer device is shown in Figure 1 . It can be understood that the scenario of the code testing method for language conversion can also include one or more other computer devices, which are not specifically limited here; the computer device 100 can also include a memory for storing information related to the code testing method for language conversion.

[0053] In addition, in the application scenario of the code testing method for converting languages in the embodiments of the present invention, the computer device 100 may be provided with a display device, or the computer device 100 may not be provided with a display device and is communicatively connected to an external display device 200. The display device 200 is used to output the result of the execution of the code testing method for converting languages in the computer device. The computer device 100 may access the background database 300 (the background database 300 may be the local memory of the computer device 100, and the background database 300 may also be set in the cloud). The background database 300 stores information related to the code testing method for converting languages.

[0054] It should be noted that Figure 1 The application scenario of the code testing method for converting languages shown is merely an example. The application scenario of the code testing method for converting languages described in the embodiments of the present invention is for more clearly explaining the technical solutions of the embodiments of the present invention, and does not constitute a limitation on the technical solutions provided by the embodiments of the present invention.

[0055] Based on the above application scenario of the code testing method for converting languages, embodiments of the code testing method for converting languages are proposed.

[0056] In the first aspect, as Figure 2 shown, in one embodiment, the present invention provides a code testing method for converting languages, including:

[0057] Step 201, receiving a test request sent by a calling party and initial code data to be tested corresponding to the test request;

[0058] Among them, the initial code data to be tested may be directly included in the test request sent by the calling party (in this case, it is necessary to parse the test request to obtain the initial code data to be tested), or it may be stored at an address, and the address is included in the test request sent by the calling party. Using the address method can reduce the data volume of the test request, thereby saving transmission resources;

[0059] Among them, the calling party refers to the terminal device that needs to send a test request to call the service party to perform code coverage testing on the corresponding software application. Similar to the calling party, the execution entity of the code testing method for converting languages in this embodiment is the service party, which refers to the terminal device that performs code coverage testing in response to the test request of the calling party. Usually, the calling party and the service party respectively send test requests and respond to test requests based on different terminal devices. Among them, the calling party and the service party can send and receive test requests through the HTTP protocol (HyperText Transfer Protocol, which is an application layer transport protocol based on the TCP protocol. Simply put, it is a rule for data transmission between the client and the server), that is, the test request is an http request (the http request includes an http request line, an http request header, and an http request body). In this http request, the initial code data to be tested or address data is stored in the http request body;

[0060] Step 202, determine the target test tool for testing the initial code data to be tested and the processing script language of the target test tool;

[0061] Among them, the test tools include test tools with the script language c / c++ (C language) (such as gcc+gcov+lcov, unit tests: CUnit, CPPUnit, Google GTest), test tools with the script language Java (Maven cobertura plugin, Clover, EMMA, Jtest, eclemma plugin in eclipse), test tools with the script language Python (PyUnit+coverage.py), test tools with the script language PHP (phpunit+–coverage-html+Xdebug), test tools with the script language Perl (Test::Class and Devel::Cover), and test tools with the script language Shell (shUnit2+shcov). The testing methods and calculation focuses of different test tools are different;

[0062] Among them, when there is only one test tool provided by the service party, only this test tool can be determined as the target test tool. When there are multiple test tools provided by the service party, one of the test tools needs to be determined as the target test tool. For example, the test tool with better test effect for the application to be tested corresponding to the initial code data to be tested is determined as the target test tool; the test effect characterizes the evaluation performance of the code coverage obtained by testing on the application to be tested;

[0063] Step 203, if the code scripting language of the initial code data to be tested is inconsistent with the processing scripting language of the target test tool, perform scripting language conversion on the initial code data to be tested to obtain the target code data to be tested; the code scripting language of the target code data to be tested is consistent with the processing scripting language of the target test tool;

[0064] Among them, the scripting language conversion can be implemented by a third-party service provider. For example, after determining the processing scripting language of the target test tool, use the processing scripting language of the target test tool as the expected scripting language for conversion, and send a conversion request containing the initial code data to be tested to the third-party service provider. After the conversion is completed, receive the target code data to be tested sent by the third-party service provider. Since the target code data to be tested is converted with the processing scripting language of the target test tool as the expected scripting language for conversion, the code scripting language of the target code data to be tested is consistent with the processing scripting language of the target test tool;

[0065] Among them, there can be multiple determined target test tools, that is, multiple scripting language conversions need to be performed on the initial code data to be tested to obtain multiple target code data to be tested;

[0066] Step 204, based on the target test tool, perform code coverage testing on the target code data to be tested to obtain the target code coverage rate of the target code data to be tested;

[0067] Among them, after the scripting language conversion, the code scripting language of the target code data to be tested is consistent with the processing scripting language of the target test tool. Therefore, the target test tool can be used to perform code coverage testing on the target code data to be tested, and finally obtain the required target code coverage rate;

[0068] Among them, when there are multiple target test tools, multiple target code coverage rates will be obtained correspondingly.

[0069] Through the above code testing method for converting languages, using the connected scripting language conversion mechanism, when the caller sends a test request to perform code coverage testing on the initial code data to be tested, the processing scripting language of the target test tool can be determined first. If the processing scripting language of the target test tool is inconsistent with the code scripting language of the initial code data to be tested, then scripting language conversion can be performed to make them consistent, that is, the target code data to be tested is obtained, and finally code coverage testing is performed on the target code data to be tested; through scripting language conversion, it is possible to avoid the problem that the code data to be tested cannot be subjected to code coverage testing due to inconsistent scripting languages, and it is also possible to avoid the problem that the code data to be tested cannot use a better test tool to perform code coverage testing due to inconsistent scripting languages, improving the test effect of code coverage testing.

[0070] Such as Figure 3As shown, in one embodiment, determining a target test tool for testing initial code data to be tested includes:

[0071] Step 301: Parse the test request to obtain the target tool type of the test tool for testing the initial code data to be tested;

[0072] Among them, the tester can, based on their own experience, select a test tool suitable for the application to be tested. That is, when the caller sends a test request, add the target tool type of the selected test tool to the test request. Thus, when the service side parses the test request, it can obtain this target tool type;

[0073] Step 302: Determine the test tool that matches the target tool type as the target test tool;

[0074] Among them, multiple provided test tools can be pre-managed and stored in a library. For example, a test tool library can be established in advance. The test tool library includes multiple sample test tools and the sample tool types of the sample test tools. Thus, after obtaining the target tool type, the corresponding sample tool type can be matched in the test tool library according to the target tool type, and finally the sample test tool corresponding to the matched sample tool type is determined as the target test tool for subsequent use.

[0075] Through the test tool library in this embodiment, testers can flexibly select the required test tools, improving the flexibility of testing.

[0076] As Figure 4 shown, in one embodiment, determining a target test tool for testing initial code data to be tested includes:

[0077] Step 401: Determine the target application type of the application to be tested corresponding to the initial code data to be tested;

[0078] Among them, different types of applications have different code focuses. Therefore, for a certain type of application, using different test tools will result in different test effects. By determining the target application type of the application to be tested, a test tool with better test effects for the application to be tested can be determined subsequently;

[0079] Among them, the target application type can be obtained by identifying and analyzing the initial code data to be tested, or it can be added to the test request by the tester when the caller sends the test request, and then parsed after receiving the test request to obtain it;

[0080] Among them, when obtaining the target application type through recognition and analysis, an AI (Artificial Intelligence) model can be used to efficiently process various typical high-performance machine learning algorithms. Specifically, a trained type recognition model is obtained, and the initial code data to be tested is input into the type recognition module to obtain the target application type output by the type recognition model. By taking advantage of the AI algorithm, through the training and learning of a large amount of data, the type recognition model can automatically avoid some errors, thereby greatly improving the recognition accuracy and efficiency.

[0081] Step 402, obtain a preset test tool library.

[0082] Among them, the test tool library includes multiple sample test tools and the sample application types of the sample test tools.

[0083] Among them, multiple provided test tools can be pre-managed and built into a library to obtain the test tool library. The mapping relationship between the test tools and the application types can be obtained through big data empirical values.

[0084] Step 403, according to the target application type, match the corresponding sample application type in the test tool library, and determine the sample test tool corresponding to the matched sample application type as the target test tool.

[0085] Through the test tool library in this embodiment, the target test tool required for the application to be tested can be automatically determined without manual selection by the tester, improving the test efficiency.

[0086] In one embodiment, the training steps of the type recognition model include:

[0087] Obtain a training sample set, which includes multiple training samples. Each training sample includes training code data to be tested and a training application type. Among them, the training application type is obtained by manually processing the training code data to be tested.

[0088] Obtain a training sample, use the training code data to be tested as the input of the type recognition model, and use the training application type as the expected output of the type recognition model to train the type recognition model, that is, complete one training.

[0089] Determine the comparison result between the actual output and the expected output of the type recognition model. If the comparison result does not meet the requirements, update the model parameters of the type recognition model according to the comparison result.

[0090] Obtain the next training sample, and then re-enter the step of using the training code data to be tested as the input of the type recognition model and the training application type as the expected output of the type recognition model to train the type recognition model until the obtained comparison result meets the requirements, and then stop training to obtain the trained type recognition model.

[0091] In one embodiment, to determine the comparison result between the actual output and the expected output of the type recognition model, if the comparison result does not meet the requirements, update the model parameters of the type recognition model according to the comparison result, including:

[0092] Determine the comparison difference between the actual output and the expected output of the type recognition model, and calculate the loss value according to the comparison difference;

[0093] If the loss value does not meet the preset convergence condition, update the model parameters of the type recognition model according to the loss value.

[0094] In one embodiment, after the type recognition model is trained, it further includes:

[0095] Obtain a test sample set, where the test sample set includes multiple test samples, and each test sample includes test code data to be tested;

[0096] Input each test sample into the trained type recognition model for testing in turn. The testing process is the same as the above actual usage process and will not be elaborated here;

[0097] If the test effect is not good, the model parameters of the type recognition model need to be further adjusted.

[0098] As Figure 5 shown, in one embodiment, perform script language conversion on the initial code data to be tested to obtain the target code data to be tested, including:

[0099] Step 501, call the preset script language conversion engine;

[0100] As mentioned in the above embodiment, the script language conversion can be implemented by a third-party service provider, but in this case, there will be data transmission. When the data volume of the initial code data to be tested is large, the testing efficiency will be greatly reduced. Therefore, a script language conversion engine can be preset locally, and when script language conversion is required during the testing process, the script language conversion engine can be directly called;

[0101] Step 502, based on the script language conversion engine, perform script language conversion on the initial code data to be tested to obtain the target code data to be tested;

[0102] Among them, multiple conversion strategies are set in the script language conversion engine, and each conversion strategy corresponds to a conversion rule from one script language to another. Therefore, after determining the processing script language of the target test tool and the code script language of the initial code data to be tested, the conversion strategy for achieving this conversion purpose can be determined, and finally, the script language conversion is completed according to this conversion strategy.

[0103] As Figure 6 shown, in one embodiment, based on the target test tool, code coverage testing is performed on the target code data to be tested, and the target code coverage rate of the target code data to be tested is obtained, including:

[0104] Step 601, based on the target test tool, execute the target code data to be tested to obtain the target code coverage data of the target code data to be tested;

[0105] Among them, the target code coverage data refers to the code data containing the marks of the executed code data obtained after the execution of the target code data to be tested by the target test tool, and the marked executed code data can be used for subsequent calculation of the code coverage rate;

[0106] Step 602, determine the target code coverage rate of the target code coverage data;

[0107] Among them, for the target code coverage data, different coverage analysis strategies can be used to obtain the corresponding target code coverage rate. For example, the decision coverage analysis strategy (indicating the correct or incorrect execution of each boolean expression in the source code, and the goal of decision coverage is to cover and verify all accessible source code by checking and ensuring that each branch of each decision point is executed at least once), the branch coverage analysis strategy (testing each result from a code module (statement or loop), and the purpose of branch coverage is to ensure that each decision condition from each branch is executed at least once, which helps measure the percentage of independent code segments and find the parts without branches; for example, if the result is of boolean type, both the True and False results need to be tested) or the condition coverage analysis strategy (used to test and evaluate variables or sub-expressions in conditional statements, and the goal of condition coverage is to check the individual results of each logical condition. Compared with decision coverage, condition coverage is more sensitive to the control flow).

[0108] In one embodiment, determining the target code coverage rate of the target code coverage data includes:

[0109] Determine the executed code data and the total code data in the target code coverage data;

[0110] As mentioned above, in the target code coverage data, the executed code data is marked, so the executed code data can be obtained based on the mark, and the total code data is the target code coverage data itself;

[0111] According to the ratio of the executed code data to the total code data, the target code coverage is determined;

[0112] Among them, determining the corresponding code coverage rate according to the quantity ratio is an efficient coverage analysis strategy, namely, the statement coverage analysis strategy (all executable statements in the source code are executed at least once, which is used to calculate the number of statements executed in the source code. The main purpose of statement coverage is to cover all possible paths, lines and statements in the source code);

[0113] Among them, if the executed code data includes 800 statements and the total code data includes 1000 statements, the corresponding quantity ratio is 800 / 1000. Converting it into a percentage, we can get the corresponding target code coverage rate: 80%.

[0114] The structure of the statement coverage analysis strategy is simple and can easily handle the test code data with a large amount of code.

[0115] In one embodiment, after the step of obtaining the target code coverage of the target code data to be tested, the code testing method for converting the language further includes:

[0116] Evaluate and analyze the target code coverage to obtain a coverage analysis report corresponding to the target code coverage;

[0117] Output prompt information according to the coverage analysis report;

[0118] Among them, the coverage analysis report can be directly added to the prompt information and thus output to the tester's terminal device. When the tester receives the prompt information, he can immediately obtain the corresponding coverage analysis report;

[0119] The target code coverage is only a percentage, and the relevant personnel cannot conduct in-depth analysis based on the percentage. However, in the testing service provider, due to the existence of various intermediate data, the specific composition of the target code coverage can be further analyzed, such as which part of the code has a lower coverage rate and which part of the code has a higher coverage rate, so as to obtain a comprehensive coverage analysis report. When the relevant personnel view the coverage analysis report, they can intuitively judge the quality of the initial code data to be tested.

[0120] Among them, the output of the prompt message can be in the forms of emails, text messages, and phone calls. It can be understood that the data forms of the prompt messages corresponding to different output methods are different, including forms such as voice, text, pictures, and videos;

[0121] Among them, the prompt message can be adjusted according to the evaluation identifier of the coverage analysis report. The evaluation identifier is used to represent the size of the target code coverage. For example, if the target code coverage is lower than 60%, the evaluation identifier can be "poor". For example, if the target code coverage is higher than 90%, the evaluation identifier can be "good"; when the evaluation identifier is "poor", the prompt message can be output through multiple channels such as emails, text messages, and phone calls. When the evaluation identifier is "good", the prompt message can be output only through the email channel, so that the output of the prompt message takes into account the urgency of the coverage analysis report, so as to use the output resources more efficiently;

[0122] Among them, when there are multiple target code coverages, the coverage analysis reports corresponding to each target code coverage can be generated respectively. Of course, in other embodiments, a single coverage analysis report can also be generated, that is, the coverage analysis report corresponds to each target code coverage; when there are multiple coverage analysis reports, similarly, the prompt messages corresponding to each coverage analysis report can be output respectively. Currently, in other embodiments, a single prompt message can also be output, that is, the prompt message corresponds to each coverage analysis report.

[0123] In one embodiment, according to the coverage analysis report, the output of the prompt message includes:

[0124] Through the first thread, obtain the target code coverage data and the target code coverage rate corresponding to the coverage analysis report. According to the coverage analysis report, the target code coverage data, and the target code coverage rate, generate traceability information, and store the traceability information in a preset traceability information table;

[0125] Among them, a special traceability information table is defined to store the traceability information. The traceability information does not need to be added to the prompt message, and the main thread for code coverage testing (i.e., the first thread in this embodiment) is not responsible for the output of the prompt message. In this way, the main thread can have sufficient processing space, thus ensuring that the main steps of the code coverage testing can be executed reliably;

[0126] Through the second thread, monitor the data in the traceability information table, and when the traceability information in the traceability information table is monitored, output the prompt message;

[0127] Among them, the second thread, as a secondary thread, is independent of the main thread and works in parallel. The secondary thread is dedicated to outputting prompt information. Specifically, the second thread can monitor the data of the traceability information table through the way of monitoring by the Mirror Platform. As long as data exists in the traceability information table, it outputs prompt information. Thus, when the main thread generates traceability information and stores it in the traceability information table, the secondary thread can immediately output prompt information according to the traceability information table. After receiving the prompt information, the tester can obtain the traceability information in the traceability information table, that is, obtain the corresponding coverage analysis report, target code coverage data, and target code coverage rate.

[0128] In a second aspect, as Figure 7 shown, in one embodiment, the present invention provides a code testing device for converting languages, including:

[0129] A receiving and obtaining module 701, configured to receive a test request sent by a calling party and initial code data to be tested corresponding to the test request;

[0130] A tool determination module 702, configured to determine a target test tool for testing the initial code data to be tested and the processing script language of the target test tool;

[0131] A language conversion module 703, if the code script language of the initial code data to be tested is inconsistent with the processing script language of the target test tool, is configured to perform script language conversion on the initial code data to be tested to obtain target code data to be tested; the code script language of the target code data to be tested is consistent with the processing script language of the target test tool;

[0132] A coverage testing module 704, configured to perform code coverage testing on the target code data to be tested based on the target test tool to obtain the target code coverage rate of the target code data to be tested.

[0133] Through the above code testing device for converting languages, by using the accessed script language conversion mechanism, when a calling party sends a test request to perform code coverage testing on the initial code data to be tested, the processing script language of the target test tool can be determined first. If the processing script language of the target test tool is inconsistent with the code script language of the initial code data to be tested, then script language conversion can be performed to make them consistent, that is, obtain the target code data to be tested, and finally perform code coverage testing on the target code data to be tested. Through script language conversion, it is possible to avoid the problem that the code data to be tested cannot be subjected to code coverage testing due to inconsistent script languages, and it is also possible to avoid the problem that the code data to be tested cannot use a better test tool to perform code coverage testing due to inconsistent script languages, improving the test effect of code coverage testing.

[0134] In one embodiment, the tool determination module is specifically configured to parse a test request to obtain a target tool type of a test tool for testing initial code data to be tested; and determine a test tool matching the target tool type as the target test tool.

[0135] In one embodiment, the tool determination module is specifically configured to determine a target application type of a to-be-tested application corresponding to the initial code data to be tested; obtain a preset test tool library; the test tool library includes a plurality of sample test tools and sample application types of the sample test tools; and according to the target application type, match a corresponding sample application type in the test tool library, and determine the sample test tool corresponding to the matched sample application type as the target test tool.

[0136] In one embodiment, the language conversion module is specifically configured to call a preset script language conversion engine; and based on the script language conversion engine, perform script language conversion on the initial code data to be tested to obtain target code data to be tested.

[0137] In one embodiment, the coverage test module is specifically configured to execute the code on the target code data to be tested based on the target test tool to obtain target code coverage data of the target code data to be tested; and determine a target code coverage rate of the target code coverage data.

[0138] In one embodiment, the coverage test module is specifically configured to determine executed code data and total code data in the target code coverage data; and determine the target code coverage rate according to a quantity ratio of the executed code data to the total code data.

[0139] In one embodiment, the above-mentioned code testing device for converting languages further includes:

[0140] An evaluation and analysis module, configured to, after the step of obtaining the target code coverage rate of the target code data to be tested, evaluate and analyze the target code coverage rate to obtain a coverage rate analysis report corresponding to the target code coverage rate; and output a prompt message according to the coverage rate analysis report.

[0141] In a third aspect, in one embodiment, the present invention provides a computer device, as Figure 8 shown, which shows the structure of the computer device involved in the present invention. Specifically:

[0142] The computer device may include a processor 801 with one or more processing cores, a memory 802 with one or more computer-readable storage media, a power supply 803, an input unit 804, and other components. Those skilled in the art can understand that Figure 8 the structure of the computer device shown in

[0143] The processor 801 is the control center of the computer device, connecting various parts of the entire computer device through various interfaces and circuits. By running or executing software programs and / or modules stored in the memory 802, and by invoking the data stored in the memory 802, it executes various functions of the computer device and processes data, thereby monitoring the computer device as a whole. Optionally, the processor 801 may include one or more processing cores; preferably, the processor 801 may integrate an application processor and a modem processor. Among them, the application processor mainly processes the operating system, user interface, computer programs, etc., and the modem processor mainly processes wireless communication. It can be understood that the above-mentioned modem processor may not be integrated into the processor 801 either.

[0144] The memory 802 can be used to store software programs and modules. The processor 801 executes various functional applications and data processing by running the software programs and modules stored in the memory 802. The memory 802 mainly includes a program storage area and a data storage area. Among them, the program storage area can store the operating system, computer programs required for at least one function (such as the sound playback function, image playback function, etc.); the data storage area can store data created according to the use of the server, etc. In addition, the memory 802 may include high-speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid-state storage devices. Correspondingly, the memory 802 may also include a memory controller to provide the processor 801 with access to the memory 802.

[0145] The computer device also includes a power supply 803 for supplying power to each component. Preferably, the power supply 803 can be logically connected to the processor 801 through a power management system, thereby realizing functions such as management of charging, discharging, and power consumption management through the power management system. The power supply 803 may also include any components such as one or more DC or AC power supplies, a recharge system, a power failure detection circuit, a power converter or inverter, and a power status indicator.

[0146] The computer device may further include an input unit 804, which can be used to receive input digital or character information, and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function controls.

[0147] Although not shown, the computer device may further include a display unit and the like, which will not be elaborated here. Specifically, in this embodiment, the processor 801 in the computer device will load the executable files corresponding to the processes of one or more computer programs into the memory 802 according to the following instructions, and the processor 801 will run the computer programs stored in the memory 802 to perform the following steps:

[0148] Receive a test request sent by a caller and the initial code data to be tested corresponding to the test request;

[0149] Determine the target test tool for testing the initial code data to be tested and the processing script language of the target test tool;

[0150] If the code script language of the initial code data to be tested is inconsistent with the processing script language of the target test tool, perform script language conversion on the initial code data to be tested to obtain the target code data to be tested; the code script language of the target code data to be tested is consistent with the processing script language of the target test tool;

[0151] Based on the target test tool, perform code coverage testing on the target code data to be tested to obtain the target code coverage rate of the target code data to be tested.

[0152] Through the above computer device, by using the accessed script language conversion mechanism, when the caller sends a test request to perform code coverage testing on the initial code data to be tested, the processing script language of the target test tool can be determined first. If the processing script language of the target test tool is inconsistent with the code script language of the initial code data to be tested, then script language conversion can be performed to make them consistent, that is, the target code data to be tested is obtained, and finally code coverage testing is performed on the target code data to be tested; through script language conversion, it is possible to avoid the problem that the code data to be tested cannot be subjected to code coverage testing due to inconsistent script languages, and it is also possible to avoid the problem that the code data to be tested cannot use a better test tool to perform code coverage testing due to inconsistent script languages, improving the test effect of code coverage testing.

[0153] Those of ordinary skill in the art can understand that all or part of the steps in any of the above methods can be completed by a computer program, or by a computer program controlling related hardware. The computer program can be stored in a computer-readable storage medium and loaded and executed by a processor.

[0154] In a fourth aspect, in an embodiment, the present invention provides a storage medium in which multiple computer programs are stored, and the computer programs can be loaded by a processor to perform the following steps:

[0155] Receive a test request sent by a calling party and initial code data to be tested corresponding to the test request;

[0156] Determine a target test tool for testing the initial code data to be tested and the processing script language of the target test tool;

[0157] When the code script language of the initial code data to be tested is inconsistent with the processing script language of the target test tool, perform script language conversion on the initial code data to be tested to obtain target code data to be tested; the code script language of the target code data to be tested is consistent with the processing script language of the target test tool;

[0158] Based on the target test tool, perform code coverage testing on the target code data to be tested to obtain the target code coverage rate of the target code data to be tested.

[0159] Through the above storage medium, by using the accessed script language conversion mechanism, when the calling party sends a test request to perform code coverage testing on the initial code data to be tested, the processing script language of the target test tool can be determined first. When the processing script language of the target test tool is inconsistent with the code script language of the initial code data to be tested, script language conversion can be performed to make them consistent, that is, obtain the target code data to be tested, and finally perform code coverage testing on the target code data to be tested; through script language conversion, it is possible to avoid the problem that the code data to be tested cannot be subjected to code coverage testing due to inconsistent script languages, and it is also possible to avoid the problem that the code data to be tested cannot use a test tool with better effects to perform code coverage testing due to inconsistent script languages, improving the test effect of code coverage testing.

[0160] Those of ordinary skill in the art can understand that any reference to a memory, storage, database, or other medium used in the embodiments provided by the present invention may include non-volatile and / or volatile memories. Non-volatile memories may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memories may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0161] Since the computer program stored in the storage medium can execute the steps in the code testing method for converting languages in any of the embodiments provided by the present invention, the beneficial effects achievable by the code testing method for converting languages in any of the embodiments provided by the present invention can be realized. For details, refer to the previous embodiments and will not be elaborated herein.

[0162] For the specific implementation of each of the above operations, refer to the previous embodiments and will not be elaborated herein.

[0163] In the above embodiments, the descriptions of the respective embodiments have their own emphases. For the parts not elaborated in a certain embodiment, refer to the detailed descriptions of other embodiments above and will not be elaborated herein.

[0164] The above has introduced in detail a code testing method, device, computer device, and storage medium for converting languages provided by the present invention. Specific examples are used herein to elaborate on the principle and implementation manner of the present invention. The description of the above embodiments is only used to help understand the method and its core idea of the present invention; at the same time, for those skilled in the art, based on the idea of the present invention, there will be changes in the specific implementation manner and application scope. In summary, the content of this specification should not be construed as a limitation to the present invention.

[0165] The technical features of the above embodiments can be combined arbitrarily. For the sake of concise description, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered as the scope described in this specification.

Claims

1. A code testing method for converting languages, characterized in that, it includes: Receiving a test request sent by a caller and the initial code data to be tested corresponding to the test request; Determining a target test tool for testing the initial code data to be tested and the processing script language of the target test tool; When the code script language of the initial code data to be tested is inconsistent with the processing script language of the target test tool, performing script language conversion on the initial code data to be tested to obtain target code data to be tested; the code script language of the target code data to be tested is consistent with the processing script language of the target test tool; Based on the target test tool, performing code coverage testing on the target code data to be tested to obtain the target code coverage rate of the target code data to be tested; Evaluating and analyzing the target code coverage rate to obtain a coverage analysis report corresponding to the target code coverage rate; Through the first thread, obtaining the target code coverage data and the target code coverage rate corresponding to the coverage analysis report, generating traceability information according to the coverage analysis report, the target code coverage data and the target code coverage rate, and storing the traceability information in a preset traceability information table; Through the second thread, monitoring the data of the traceability information table, and outputting a prompt message when the traceability information in the traceability information table is monitored.

2. The code testing method for converting languages according to claim 1, characterized in that, The determining of the target test tool for testing the initial code data to be tested includes: Parsing the test request to obtain the target tool type of the test tool for testing the initial code data to be tested; Determining the test tool matching the target tool type as the target test tool.

3. The code testing method for converting languages according to claim 1, characterized in that, The determining of the target test tool for testing the initial code data to be tested includes: Determining the target application type of the application to be tested corresponding to the initial code data to be tested; Obtaining a preset test tool library; the test tool library includes multiple sample test tools and the sample application types of the sample test tools; According to the target application type, matching the corresponding sample application type in the test tool library, and determining the sample test tool corresponding to the matched sample application type as the target test tool.

4. The code testing method for converting languages according to claim 1, characterized in that, The performing of script language conversion on the initial code data to be tested to obtain target code data to be tested includes: Invoking a preset script language conversion engine; Based on the script language conversion engine, performing script language conversion on the initial code data to be tested to obtain the target code data to be tested.

5. The code testing method for converting languages according to claim 1, characterized in that, The performing of code coverage testing on the target code data to be tested based on the target test tool to obtain the target code coverage rate of the target code data to be tested includes: Based on the target test tool, execute the code for the target code data to be tested, and obtain the target code coverage data of the target code data to be tested; Determine the target code coverage rate of the target code coverage data.

6. The code testing method for converting languages according to claim 5, wherein, the determining the target code coverage rate of the target code coverage data includes: Determine the executed code data and the total code data in the target code coverage data; Determine the target code coverage rate according to the quantity ratio of the executed code data and the total code data.

7. A code testing device for converting languages, wherein, it includes: A receiving and obtaining module, configured to receive a test request sent by a calling party and the initial code data to be tested corresponding to the test request; A tool determining module, configured to determine a target test tool for testing the initial code data to be tested and the processing script language of the target test tool; A language conversion module, if the code script language of the initial code data to be tested is inconsistent with the processing script language of the target test tool, then configured to perform script language conversion on the initial code data to be tested to obtain target code data to be tested; the code script language of the target code data to be tested is consistent with the processing script language of the target test tool; A coverage testing module, configured to perform code coverage testing on the target code data to be tested based on the target test tool, and obtain the target code coverage rate of the target code data to be tested; An evaluation and analysis module, configured to evaluate and analyze the target code coverage rate to obtain a coverage analysis report corresponding to the target code coverage rate, obtain the target code coverage data and the target code coverage rate corresponding to the coverage analysis report through a first thread, generate traceability information according to the coverage analysis report, the target code coverage data and the target code coverage rate, store the traceability information in a preset traceability information table, and monitor the data of the traceability information table through a second thread, and output a prompt message when the traceability information in the traceability information table is monitored.

8. A computer device, wherein, it includes a memory and a processor; the memory stores a computer program, and the processor is configured to run the computer program in the memory to execute the steps in the code testing method for converting languages according to any one of claims 1 to 6.

9. A storage medium, wherein, the storage medium stores a computer program, and the computer program is loaded by a processor to execute the steps in the code testing method for converting languages according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Application testing method, terminal device and computer readable storage medium

    CN108415826A

  • Code coverage rate determination method and device and electronic equipment

    CN113326190A