Test Code Optimization Method Based on Automated Testing and Related Devices

By introducing problem code generation model and test effectiveness algorithm in automated testing, the test code is optimized, and the problems of inefficiency of test code and defect discovery delay in the existing technology are solved, and the effectiveness verification and optimization of automated test code are realized.

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

Patent Information

Application Number
CN202210837738.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-07-15
Publication Date
2025-05-30
Estimated Expiration
2042-07-15

AI Technical Summary

Technical Problem

Existing automated testing tools are prone to generating a large amount of ineffective testing code when generating test cases, and cannot detect potential defects in the software in advance, resulting in inefficiency in testing and latency in defect discovery.

Method used

A test code optimization method based on automated testing is proposed. By obtaining the source test code set and the function code to be tested, a preset problem code generation model is used to generate the problem code, and a second test is conducted to obtain the preferred test code set. Then, the test validity is judged based on the test validity algorithm, and the optimization conditions are determined whether to replace the source test code set to optimize the test code.

Benefits of technology

Through automated testing, the workload of testers is reduced, the effectiveness of the test code is verified and the automatic optimization is automatically optimized, so that the optimized test code has a reasonable test scope and can promptly detect defects in the program.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115328764B_ABST
    Figure CN115328764B_ABST
Patent Text Reader

Abstract

The embodiment of this application belongs to the field of R & D management and is applied to the field of automated testing. It involves a method for optimizing test code based on automated testing, including obtaining a source test code set and function code to be tested and inputting them into a pre-constructed automated testing tool; generating corresponding problem codes for the function code based on a preset problem code generation model; obtaining a primary selection test code set and an optimized selection test code set; determining the effectiveness of the source test code set; judging whether the effectiveness can be optimized; if it can be optimized, perform the optimization; if it cannot be optimized, terminate the automated testing program. It can not only reduce the workload of testers through automated testing, but also verify the effectiveness of the test code and automatically optimize it, so that the optimized test code not only has a reasonable test scope, but also can detect BUGs in time when defects occur in the program.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical fields of R & D management and test code optimization based on automated testing, and in particular, to a test code optimization method based on automated testing and related devices. Background Art

[0002] Test code should be able to discover and expand the scope of testing, reasonably expand the test coverage, and discover potential defects in software in advance. Therefore, when testers design test code, they are required to design test code with a reasonable test scope and be able to avoid potential business defects.

[0003] Currently, most testers often use automated testing tools to automatically generate test cases in order to improve testing efficiency and reduce the construction time of test code. This can ensure the comprehensiveness of test coverage. However, it is easy to generate a large number of ineffective test codes and cannot discover potential defects in software in advance. Therefore, there is an urgent need to provide an optimization scheme for test code of automated testing to optimize automated test cases and solve the above technical problems. Summary of the Invention

[0004] The purpose of the embodiments of this application is to propose a test code optimization method, device, computer device, and storage medium based on automated testing, so that when performing automated testing, it can not only reduce the workload of testers through automated testing, but also verify the effectiveness of test code and automatically optimize it, so that the optimized test code has a reasonable test scope and can discover BUGs in time when the program has defects.

[0005] To solve the above technical problems, the embodiments of this application provide a test code optimization method based on automated testing, and adopt the following technical solutions:

[0006] A test code optimization method based on automated testing includes the following steps:

[0007] Obtain a source test code set and a function code to be tested and input them into a pre-constructed automated testing tool;

[0008] Based on the source test code set, perform a first test on the function code to be tested, and obtain a first test success set as a preliminary selected test code set;

[0009] Based on a preset problem code generation model, generate corresponding problem codes for the function code;

[0010] Based on the preliminary selected test code set, perform a second test on the problem code, and obtain a second test failure set as a preferred test code set;

[0011] Obtain the number of test code entries in the source test code set and the preferred test code set respectively, and determine the validity of the source test code set based on a preset test validity algorithm;

[0012] Based on preset optimization conditions, determine whether the validity can be optimized;

[0013] If it can be optimized, replace the preferred test code set with the source test code set;

[0014] If it cannot be optimized, send a test end instruction to a preset monitoring interface and terminate the automated test program.

[0015] Further, after the step of obtaining the first test success set as the primary selected test code set, it further includes:

[0016] Based on the test log and the test return value, obtain the source test code entries used by the function code when the test is successful, and take them as set elements and add them to the first test success set.

[0017] Further, after the step of obtaining the source test code entries used by the function code when the test is successful, taking them as set elements and adding them to and constructing the first test success set, it further includes:

[0018] Identify the elements in the first test success set;

[0019] If the elements in the first test success set are null values, send a test end instruction to a preset monitoring interface and terminate the automated test program.

[0020] Further, the step of generating corresponding problem codes for the function code based on a preset problem code generation model specifically includes:

[0021] Pre-construct a problem code generation model, where the problem code generation model includes: a model input layer, a model processing layer, and a model output layer;

[0022] Obtain the function code input from the model input layer, and use the problem introduction conditions preset in the model processing layer as replacement conditions to replace the corresponding code positions in the function code;

[0023] Output the replaced function code through the model output layer and use it as the problem code.

[0024] Further, the step of determining the validity of the source test code set based on a preset test validity algorithm specifically includes:

[0025] The preset test validity algorithm: Determine the validity of the source test code set, where Q2 Represents the number of test code entries in the preferred test code set, Q 1 Represents the number of test code entries in the source test code set, and P represents the effectiveness of the source test code set.

[0026] Furthermore, based on the preset optimization conditions, determining whether the effectiveness can be optimized specifically includes:

[0027] If the test effectiveness is 0 or 100%, then the test effectiveness cannot be optimized;

[0028] If the test effectiveness is neither 0 nor 100%, then the test effectiveness can be optimized.

[0029] Furthermore, after determining the effectiveness of the source test code set, the method further includes:

[0030] When it is monitored that the preset monitoring interface receives a test end instruction, obtain the test effectiveness at the termination of the automated test program and the source test code set corresponding to the test effectiveness, and output them as the automated test result.

[0031] To solve the above technical problems, an embodiment of the present application further provides a test code optimization device based on automated testing, adopting the following technical solutions:

[0032] A test code optimization device based on automated testing, including:

[0033] A test preparation module, configured to obtain a source test code set and a to-be-tested function code and input them into a pre-constructed automated testing tool;

[0034] A first test module, configured to perform a first test on the to-be-tested function code based on the source test code set, and obtain a first test success set as the primary selected test code set;

[0035] A problem code generation module, configured to generate corresponding problem codes for the function code based on a preset problem code generation model;

[0036] A second test module, configured to perform a second test on the problem code based on the primary selected test code set, and obtain a second test failure set as the preferred test code set;

[0037] A test effectiveness algorithm module, configured to respectively obtain the number of test code entries in the source test code set and the preferred test code set, and determine the effectiveness of the source test code set based on a preset test effectiveness algorithm;

[0038] An optimization judgment module, configured to judge whether the effectiveness can be optimized based on preset optimization conditions;

[0039] An optimization processing module, configured to replace the preferred test code set with the source test code set if optimization is possible;

[0040] A test termination module, configured to send a test end instruction to a preset monitoring interface and terminate the automated test program if optimization is not possible.

[0041] Compared with the prior art, the embodiments of the present application mainly have the following beneficial effects:

[0042] The test code optimization method based on automated testing in the embodiments of the present application obtains a source test code set and a function code to be tested and inputs them into a pre-constructed automated testing tool; generates corresponding problem codes for the function code based on a preset problem code generation model; obtains a primary selection test code set and a preferred test code set; determines the effectiveness of the source test code set; determines whether the effectiveness can be optimized; if it can be optimized, perform optimization; if it cannot be optimized, terminate the automated test program. It can not only reduce the workload of testers through automated testing, but also verify the effectiveness of the test code and automatically optimize it, so that the optimized test code not only has a reasonable test scope, but also can detect BUGs in time when defects occur in the program. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] To more clearly illustrate the solutions in the present application, the following will briefly introduce the drawings required for the description of the embodiments of the present application. Obviously, the drawings in the following description are some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0044] Figure 1 is an exemplary system architecture diagram to which the present application can be applied;

[0045] Figure 2 A flowchart of an embodiment of the test code optimization method based on automated testing according to the present application;

[0046] Figure 3 is Figure 2 A flowchart of a specific implementation manner of step 203 shown;

[0047] Figure 4 A schematic structural diagram of an embodiment of the test code optimization device based on automated testing according to the present application;

[0048] Figure 5 is Figure 4 A schematic structural diagram of a specific implementation manner of module 403 shown;

[0049] Figure 6 A schematic structural diagram of an embodiment of a computer device according to the present application. Detailed implementation manners

[0050] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the technical field to which this application belongs; the terms used in the specification of this application are only for the purpose of describing specific embodiments and are not intended to limit this application; the terms "including" and "having" and any variations thereof in the specification and claims of this application and the above drawings are intended to cover non-exclusive inclusion. The terms "first", "second", etc. in the specification and claims of this application or the above drawings are used to distinguish different objects and not to describe a specific order.

[0051] Reference to "embodiment" herein means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of this application. The phrase appears in various places in the specification and does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those skilled in the art will explicitly and implicitly understand that the embodiments described herein can be combined with other embodiments.

[0052] In order to enable those skilled in the art of this technology to better understand the solution of this application, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings.

[0053] As Figure 1 shown, the system architecture 100 may include terminal devices 101, 102, 103, a network 104, and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, etc.

[0054] Users can use the terminal devices 101, 102, 103 to interact with the server 105 through the network 104 to receive or send messages, etc. Various communication client applications may be installed on the terminal devices 101, 102, 103, such as a web browser application, a shopping application, a search application, an instant messaging tool, an email client, a social platform software, etc.

[0055] The terminal devices 101, 102, and 103 can be various electronic devices with a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, e-book readers, MP3 players (Moving Picture Experts Group Audio Layer III), MP4 (Moving Picture Experts Group Audio Layer IV) players, laptop computers, desktop computers, and so on.

[0056] The server 105 can be a server that provides various services, such as a background server that supports the pages displayed on the terminal devices 101, 102, and 103.

[0057] It should be noted that the test code optimization method based on automated testing provided by the embodiments of the present application is generally executed by the server / terminal device. Correspondingly, the test code optimization device based on automated testing is generally set in the server / terminal device.

[0058] It should be understood that Figure 1 the numbers of the terminal devices, network, and server in are merely illustrative. According to the implementation requirements, there can be any number of terminal devices, network, and server.

[0059] Continuing to refer to Figure 2 , a flowchart of an embodiment of the test code optimization method based on automated testing according to the present application is shown. The test code optimization method based on automated testing includes the following steps:

[0060] Step 201, obtain a source test code set and a to-be-tested function code and input them into a pre-constructed automated testing tool.

[0061] In this embodiment, the automated testing tool can be an existing open-source automated testing tool or an automated testing tool designed by testers themselves that conforms to the test logic in this embodiment. As long as it includes an input layer, a test layer, and an output layer, it meets the requirements of the automated testing tool in this embodiment.

[0062] Either an existing open-source automated testing tool can be selected to improve the test logic of the test layer, or it can be designed by oneself to obtain an automated testing tool that conforms to the test logic in this embodiment. As long as it has an input layer, a test layer, and an output layer, it is more convenient in the selection of the testing tool, and it is not necessary to introduce a relatively complex testing tool, which is more friendly to novice testers.

[0063] In this embodiment, the source test code set includes: several verification codes pre-constructed by testers.

[0064] In this embodiment, the function code to be tested includes: service code and performance code to be tested.

[0065] The function code to be tested can be a single function method or multiple function methods in a service scenario. If it is a single function method, directly test the validity of the test code of this method to obtain the test result. If it is multiple function methods in a service scenario, directly test each method with several pre-constructed verification codes, and then optimize the test code and test validity corresponding to each method, indirectly achieving the classification of the test code for testing. There is no need for testers to create test codes according to individual methods respectively, and the testing and identification of the function methods applicable to the test code are automated, saving the labor consumption of testers.

[0066] Step 202: Based on the source test code set, perform a first test on the function code to be tested, and obtain a first test success set as the preliminary selected test code set.

[0067] In this embodiment, after the step of obtaining the first test success set as the preliminary selected test code set, it further includes: based on the test log and test return value, obtain the source test code entries used when the function code is tested successfully, and use them as set elements to add to the first test success set.

[0068] In this embodiment, after the step of obtaining the source test code entries used when the function code is tested successfully, using them as set elements to add to and construct the first test success set, it further includes: identify the elements in the first test success set; if the elements in the first test success set are null values, send a test end instruction to the preset monitoring interface and terminate the automated test program.

[0069] If the elements in the first test success set are null values, it means that there are no source test code entries in the source test code set that can make the function code to be tested pass the test. Obviously, there is no test validity at this time. Immediately send a test end instruction to the preset monitoring interface to remind the test monitor that the source test code set is invalid, and terminate the automated test program, so that the test monitor can provide a new source test code set in time.

[0070] Step 203: Based on the preset problem code generation model, generate corresponding problem codes for the function code.

[0071] In this embodiment, the step of generating corresponding problem codes for the function codes based on the preset problem code generation model specifically includes: pre-constructing a problem code generation model, where the problem code generation model includes: a model input layer, a model processing layer, and a model output layer; obtaining the function codes input from the model input layer, using the problem introduction conditions preset in the model processing layer as replacement conditions, and replacing the corresponding code positions in the function codes; outputting the replaced function codes through the model output layer and using them as problem codes.

[0072] Continue to refer to Figure 3 , which shows a flowchart of a specific implementation manner of problem code generation in step 203, specifically including:

[0073] Step 301, pre-construct a problem code generation model, where the problem code generation model includes: a model input layer, a model processing layer, and a model output layer;

[0074] Step 302, obtain the function codes input from the model input layer, use the problem introduction conditions preset in the model processing layer as replacement conditions, and replace the corresponding code positions in the function codes;

[0075] In this embodiment, the problem introduction conditions include: when the function code to be tested contains the following codes, make corresponding changes, specifically:

[0076] When there are operators, change the arithmetic operators "+ to -, + to -, * to / , + to -", relational operators "!= to ==, > to <, == to!=, < to >", bitwise operators "& to |, << to >>, | to &, >> to <<", logical operators "&& to ||, || to &&", assignment operators "+= to -=, -= to +=";

[0077] When there are specific code structures, such as loop structures, conditional statements, exception statements, and null judgments, make corresponding changes. For example: for loop structures "break to continue, continue to break", conditional statements "if statement always true, if statement always false", exception statements "delete try catch exception code blocks", null judgments "delete various null-checking statements";

[0078] For specific variable values, such as Boolean values, date formats, and numerical precisions, make corresponding changes. For example: for Boolean values "true to false, false to true", date formats "yyyy to YYYY, YYYY to yyyy", numerical precisions "integer to decimal, decimal to integer";

[0079] For specific function calls, such as similar functions, polymorphic functions, and error-prone functions, corresponding changes are made. For example: for similar functions, "getList becomes getWhiteList, getWhiteList becomes getList"; for polymorphic functions, "foo(xx,0) becomes foo(xx), foo(xx) becomes foo(xx,0)"; for error-prone functions, "parseBool becomes getBool, getBool becomes parseBool".

[0080] Step 303: Output the replaced functional code through the model output layer and use it as the problem code.

[0081] Step 204: Based on the preliminary selected test code set, conduct a second test on the problem code to obtain a second test failure set as the preferred test code set.

[0082] In this embodiment, after the step of obtaining the second test failure set as the preferred test code set, it further includes: Based on the test log and test return value, obtain the preliminary selected test code entry used by the problem code when the test fails, and use it as a set element to add to the second test failure set.

[0083] Using the reverse test method, use the problem code to verify the source test code entry that the functional code test is successful. When it can also pass the test, the test results of the source test code entry for the problem code and the functional code are the same, and it is impossible to distinguish between the problem code and the functional code. Therefore, obtain the source test code entry corresponding to its test failure as the optimized test code entry.

[0084] Through the positive and negative test methods, screen out the source test code entries that have no differentiating effect on automated testing, and only retain the source test code entries that have a differentiating effect on automated testing, reducing the storage pressure on the relevant database.

[0085] Step 205: Respectively obtain the number of test code entries in the source test code set and the preferred test code set, and based on a preset test effectiveness algorithm, determine the effectiveness of the source test code set.

[0086] In this embodiment, the step of determining the effectiveness of the source test code set based on the preset test effectiveness algorithm specifically includes: The preset test effectiveness algorithm: Determine the effectiveness of the source test code set, where Q 2 represents the number of test code entries in the preferred test code set, Q 1 represents the number of test code entries in the source test code set, and P represents the effectiveness of the source test code set.

[0087] Step 206: Based on the preset optimization conditions, determine whether the effectiveness can be optimized.

[0088] In this embodiment, the determining whether the effectiveness can be optimized based on the preset optimization conditions specifically includes: if the test effectiveness is 0 or 100%, then the test effectiveness cannot be optimized; if the test effectiveness is neither 0 nor 100%, then the test effectiveness can be optimized.

[0089] If the test effectiveness is 0, that is, when the second test is performed, there are no elements in the second test failure set, which means that the function code can be tested successfully and the problem code can also be tested successfully. Therefore, the test effectiveness is 0. If the test effectiveness is 100%, that is, when the second test is performed, the elements in the second test failure set include all the elements in the primary selected test code set, which means that the function code can be tested successfully but the problem codes cannot be tested successfully. Therefore, the test effectiveness is 100%. If the test effectiveness is neither 0 nor 100%, that is, when the second test is performed, there are elements in the second test failure set, but the number of its elements is less than the number of elements in the primary selected test code set. Therefore, the preferred test code set can be replaced with the source test code set for automatic optimization.

[0090] Step 207: If it can be optimized, replace the preferred test code set with the source test code set.

[0091] Step 208: If it cannot be optimized, send a test end instruction to the preset monitoring interface and terminate the automated test program.

[0092] In this embodiment, after determining the effectiveness of the source test code set, the method further includes: when it is monitored that the preset monitoring interface receives a test end instruction, obtain the test effectiveness at the time when the automated test program terminates and the source test code set corresponding to the test effectiveness, and output them as the automated test result. Substantially, if a test end instruction is received, obtain the test effectiveness at the time when the automated test program terminates and the source test code set corresponding to the test effectiveness as the automated test result. At this time, the output test effectiveness is a binary result, that is, either 0 or 100%. Sampling the automated test tool to obtain the binary test effectiveness result is more convenient for testers to distinguish, avoiding the difficulty of distinction when the previous test effectiveness was in multiple interval values. At the same time, it also provides the source test code set corresponding to the test effectiveness, that is, the empty set corresponding to 0, or the preferred test code set corresponding to 100%, which is convenient for testers to further construct the source test code set and screen out applicable test codes.

[0093] This application obtains the source test code set and the function code to be tested and inputs them into a pre-constructed automated test tool; based on a preset problem code generation model, corresponding problem codes are generated for the function code; a primary selection test code set and a preferred test code set are obtained; the validity of the source test code set is determined; it is judged whether the validity can be optimized; if it can be optimized, optimization is carried out; if it cannot be optimized, the automated test program is terminated. Among them, during the automated test processing, by introducing a problem code generation model, positive and negative tests and automatic optimization are carried out to obtain binary test validity and output results, which can not only reduce the workload of testers through automated testing, but also verify the validity of the test code and automatically optimize it, so that the optimized test code not only has a reasonable test scope, but also can detect BUGs in time when defects occur in the program.

[0094] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through computer-readable instructions. These computer-readable instructions can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above methods. Among them, the aforementioned storage medium can be a non-volatile storage medium such as a magnetic disk, an optical disk, a read-only memory (ROM), etc., or a random access memory (RAM), etc.

[0095] It should be understood that although the steps in the flowchart of the accompanying drawings are shown in sequence according to the indication of the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless there is a clear indication in this article, the execution of these steps has no strict order limit, 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. 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 alternately or alternately with at least a part of other steps or sub-steps or stages of other steps.

[0096] Further reference Figure 4 to Figure 2 As an implementation of the method shown above, this application provides an embodiment of a test code optimization device based on automated testing. This device embodiment corresponds to the method embodiment shown in Figure 2 and can be specifically applied to various electronic devices.

[0097] As Figure 4As shown in the figure, the test code optimization device 400 based on automated testing described in this embodiment includes: a test preparation module 401, a first test module 402, a problem code generation module 403, a second test module 404, a test effectiveness algorithm module 405, an optimization judgment module 406, an optimization processing module 407, and a test termination module 408. Among them:

[0098] The test preparation module 401 is configured to obtain a source test code set and a function code to be tested and input them into a pre-constructed automated testing tool;

[0099] The first test module 402 is configured to perform a first test on the function code to be tested based on the source test code set, and obtain a first test success set as a primary selected test code set;

[0100] The problem code generation module 403 is configured to generate corresponding problem codes for the function code based on a preset problem code generation model;

[0101] The second test module 404 is configured to perform a second test on the problem code based on the primary selected test code set, and obtain a second test failure set as a preferred test code set;

[0102] The test effectiveness algorithm module 405 is configured to respectively obtain the number of test code entries in the source test code set and the preferred test code set, and determine the effectiveness of the source test code set based on a preset test effectiveness algorithm;

[0103] The optimization judgment module 406 is configured to judge whether the effectiveness can be optimized based on a preset optimization condition;

[0104] The optimization processing module 407 is configured to, if it can be optimized, replace the preferred test code set with the source test code set;

[0105] The test termination module 408 is configured to, if it cannot be optimized, send a test end instruction to a preset monitoring interface and terminate the automated testing program.

[0106] Continue to refer to Figure 5 , which is a structural schematic diagram of a specific implementation manner of the problem code generation module. The problem code generation module includes a model construction sub-module 4031, a model processing sub-module 4032, and a problem code output sub-module 4033.

[0107] Among them, the model construction sub-module 4031 is configured to pre-construct a problem code generation model, where the problem code generation model includes: a model input layer, a model processing layer, and a model output layer;

[0108] The model processing sub-module 4032 obtains the function code input from the input layer of the model, and uses the problem introduction condition preset in the model processing layer as the replacement condition to replace the corresponding code position in the function code.

[0109] The problem code output sub-module 4033 is used to output the replaced function code through the output layer of the model and use it as the problem code.

[0110] The test code optimization device based on automated testing provided by the present application obtains a source test code set and a function code to be tested and inputs them into a pre-constructed automated testing tool; generates corresponding problem codes for the function code based on a preset problem code generation model; obtains a primary selection test code set and an optimized test code set; determines the effectiveness of the source test code set; determines whether the effectiveness can be optimized; if it can be optimized, perform optimization; if it cannot be optimized, terminate the automated testing program to pre-construct the automated testing tool; obtain the source test code set and the function code to be tested and input them into the first input layer; perform automated testing processing on the source test code set and the function code to be tested based on the testing layer; until a preset output condition is met, output an automated testing result based on the first output layer. Among them, during the automated testing process, by introducing a problem code generation model, positive and negative tests and automatic optimization are performed to obtain binary test effectiveness and output results, which can not only reduce the workload of testers through automated testing, but also verify the effectiveness of the test code and automatically optimize it, so that the optimized test code not only has a reasonable test scope, but also can detect BUGs in time when defects occur in the program.

[0111] To solve the above technical problems, the embodiments of the present application also provide a computer device. For details, please refer to Figure 6 , Figure 6 which is the basic structural block diagram of the computer device in this embodiment.

[0112] The computer device 6 includes a memory 61, a processor 62, and a network interface 63 that are communicatively connected to each other via a system bus. It should be noted that only the computer device 6 with components 61-63 is shown in the figure, but it should be understood that it is not required to implement all the shown components, and more or fewer components can be implemented alternatively. Among them, those skilled in the art of the present technology can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), digital signal processors (DSPs), embedded devices, etc.

[0113] The computer device can be a computing device such as a desktop computer, a notebook, a palm computer, and a cloud server. The computer device can perform human-computer interaction with the user through means such as a keyboard, a mouse, a remote control, a touchpad, or a voice control device.

[0114] The memory 61 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, a hard disk, a multimedia card, a card-type memory (such as an SD or DX memory, etc.), a random access memory (RAM), a static random access memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a magnetic disk, an optical disk, etc. In some embodiments, the memory 61 can be an internal storage unit of the computer device 6, such as the hard disk or memory of the computer device 6. In other embodiments, the memory 61 can also be an external storage device of the computer device 6, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the computer device 6. Of course, the memory 61 can also include both the internal storage unit of the computer device 6 and its external storage device. In this embodiment, the memory 61 is generally used to store the operating system installed on the computer device 6 and various application software, such as computer-readable instructions of a test code optimization method based on automated testing. In addition, the memory 61 can also be used to temporarily store various data that have been output or will be output.

[0115] In some embodiments, the processor 62 may be a Central Processing Unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips. The processor 62 is generally used to control the overall operation of the computer device 6. In this embodiment, the processor 62 is used to run the computer-readable instructions stored in the memory 61 or process data, such as running the computer-readable instructions of the test code optimization method based on automated testing.

[0116] The network interface 63 may include a wireless network interface or a wired network interface, and this network interface 63 is generally used to establish a communication connection between the computer device 6 and other electronic devices.

[0117] Through the description of the above embodiments, those skilled in the art can clearly understand that the above-described embodiment methods can be implemented by means of software plus a necessary general hardware platform. Of course, they can also be implemented by hardware, but in many cases, the former is a better implementation method. Based on such an understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disc) and includes several instructions to enable a terminal device (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the methods described in the various embodiments of the present application.

[0118] Obviously, the above-described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. The drawings of the present application show preferred embodiments, but do not limit the patent scope of the present application. The present application can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosed content of the present application more thorough and comprehensive. Although the present application has been described in detail with reference to the foregoing embodiments, for those skilled in the art, they can still modify the technical solutions described in the foregoing specific embodiments, or perform equivalent replacements for some of the technical features. Any equivalent structures directly or indirectly using the content of the specification and drawings of the present application in other related technical fields are equally within the scope of the patent protection of the present application.

Claims

1. A method for optimizing test code based on automated testing, characterized in that, it includes the following steps: Obtain the source test code set and the function code to be tested and input them into a pre-constructed automated testing tool; Based on the source test code set, conduct a first test on the function code to be tested, and obtain the first test success set as the preliminary selected test code set; Based on a preset problem code generation model, generate corresponding problem codes for the function code. Among them, the step of generating corresponding problem codes for the function code based on the preset problem code generation model specifically includes: Pre-construct a problem code generation model, where the problem code generation model includes: a model input layer, a model processing layer, and a model output layer; Obtain the function code input from the model input layer, use the problem introduction condition preset in the model processing layer as the replacement condition, and replace the corresponding code positions in the function code; Output the replaced function code through the model output layer and use it as the problem code; Based on the preliminary selected test code set, conduct a second test on the problem code, and obtain the second test failure set as the preferred test code set; Respectively obtain the number of test code entries in the source test code set and the preferred test code set, and based on a preset test effectiveness algorithm, determine the effectiveness of the source test code set; Based on a preset optimization condition, judge whether the effectiveness can be optimized; If it can be optimized, replace the preferred test code set with the source test code set; If it cannot be optimized, send a test end instruction to a preset monitoring interface and terminate the automated testing program.

2. The method for optimizing test code based on automated testing according to claim 1, characterized in that, after the step of obtaining the first test success set as the preliminary selected test code set, it further includes: Based on the test log and the test return value, obtain the source test code entries used when the function code is tested successfully, use them as set elements, and add them to the first test success set.

3. The method for optimizing test code based on automated testing according to claim 2, characterized in that, the method further includes: Identify the elements in the first test success set; If the elements in the first test success set are null values, send a test end instruction to a preset monitoring interface and terminate the automated testing program.

4. The method for optimizing test code based on automated testing according to claim 1, characterized in that, the step of determining the effectiveness of the source test code set based on a preset test effectiveness algorithm specifically includes: The preset test validity algorithm: , determine the validity of the source test code set, where represents the number of test code entries in the preferred test code set, represents the number of test code entries in the source test code set, represents the validity of the source test code set.

5. The method for optimizing test code based on automated testing according to claim 4, characterized in that, the step of judging whether the effectiveness can be optimized based on a preset optimization condition specifically includes: If the test effectiveness is 0 or 100%, the test effectiveness cannot be optimized; If the test effectiveness is not 0 and not 100%, the test effectiveness can be optimized.

6. The method for optimizing test code based on automated testing according to any one of claims 1 to 5, characterized in that, after determining the effectiveness of the source test code set, the method further includes: When it is monitored that the preset monitoring interface receives a test end instruction, obtain the test effectiveness at the termination of the automated test program and the source test code set corresponding to the test effectiveness, and output them as the automated test result.

7. A test code optimization device based on automated testing, characterized in that it includes: A test preparation module, configured to obtain a source test code set and a code of a function to be tested and input them into a pre-constructed automated test tool; A first test module, configured to perform a first test on the code of the function to be tested based on the source test code set, and obtain a first test success set as a preliminary selected test code set; A problem code generation module, configured to generate corresponding problem codes for the function code based on a preset problem code generation model. The problem code generation module includes a model construction sub-module, a model processing sub-module, and a problem code output sub-module. Among them, the model construction sub-module is configured to pre-construct a problem code generation model. The problem code generation model includes: a model input layer, a model processing layer, and a model output layer; The model processing sub-module obtains the function code input from the model input layer, uses the problem introduction condition preset in the model processing layer as a replacement condition, and replaces the corresponding code position in the function code; The problem code output sub-module is configured to output the replaced function code through the model output layer and use it as the problem code; A second test module, configured to perform a second test on the problem code based on the preliminary selected test code set, and obtain a second test failure set as a preferred test code set; A test effectiveness algorithm module, configured to respectively obtain the number of test code entries in the source test code set and the preferred test code set, and determine the effectiveness of the source test code set based on a preset test effectiveness algorithm; An optimization judgment module, configured to judge whether the effectiveness can be optimized based on a preset optimization condition; An optimization processing module, configured to, if it can be optimized, replace the preferred test code set with the source test code set; A test termination module, configured to, if it cannot be optimized, send a test end instruction to a preset monitoring interface and terminate the automated test program.

8. A computer device, characterized in that it includes a memory and a processor. A computer-readable instruction is stored in the memory. When the processor executes the computer-readable instruction, the steps of the test code optimization method based on automated testing according to any one of claims 1 to 6 are implemented.

9. A computer-readable storage medium, characterized in that a computer-readable instruction is stored on the computer-readable storage medium. When the computer-readable instruction is executed by a processor, the steps of the test code optimization method based on automated testing according to any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Optimization method for software code abstract automatic generation model

    CN108491459A

  • Runtime profitability control for speculative automatic parallelization

    US20090276766A1