Code testing method, device and equipment and storage medium thereof
By introducing integrated testing tools and filtering components into the code testing method, filtering out the target classes to be tested and generating test index data, the problems of missing tests and low coverage in the existing technology are solved, and more scientific and comprehensive code test.
Patent Information
- Application Number
- CN202411340773.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-24
- Publication Date
- 2025-02-11
AI Technical Summary
The existing business testing methods will have test omissions, which are not scientific and rational enough, resulting in low code testing coverage.
A code testing method is proposed. By receiving instructions to start the integrated testing tool, calling the filtering component to filter out the target class to be tested, traversing the methods in the target class to generate test index data, and selecting different testing methods according to the type of the target test interface Perform a test.
By filtering components, filtering all target classes in the code, generating test index data, and adopting different testing methods according to the test interface type, more scientific and comprehensive testing is achieved, avoiding test omissions and improving the Test coverage.
Smart Images

Figure CN119415420A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of R&D and design technology, and is applied to code testing scenarios, and in particular to a code testing method, apparatus, device, and storage medium thereof. Background Art
[0002] Currently, all companies require that the code must have execution records in the test environment before it is officially put into production. The ratio of execution records to the total amount of online code is the code coverage rate. In most cases, development and testing are carried out in accordance with company standards, but in the user rights system, certain testing difficulties have been encountered.
[0003] Since the user rights system is aimed at C-end users and has complex and diverse requirements, it is inevitable to use a lot of tool code. When writing tool code, for the sake of universality and scalability, it is inevitable to write many more methods, which leads to a large amount of code to be tested in the tool class. The simple use of business testing methods will result in test omissions, which is not scientific and rational, resulting in low code test coverage. Summary of the invention
[0004] The purpose of the embodiments of the present application is to propose a code testing method, device, equipment and storage medium thereof to solve the problem that the existing business testing method has test omissions, is not scientific and rational, and causes low code testing coverage.
[0005] In order to solve the above technical problems, the embodiment of the present application provides a code testing method, which adopts the following technical solution:
[0006] A code testing method comprises the following steps:
[0007] Receiving a first execution instruction, wherein the first execution instruction is an instruction to start a preset integrated testing tool;
[0008] Starting the integrated testing tool based on the first execution instruction;
[0009] Calling a preset screening component in the integrated testing tool to screen out the target class to be tested;
[0010] Traverse the methods in the target class and generate test index data of the target structure;
[0011] receiving a second execution instruction, wherein the second execution instruction is a target test interface selection calling instruction;
[0012] A target test interface is selected based on the second execution instruction, the target test interface is called, and a method to be tested is screened out from the test index data for testing.
[0013] Furthermore, before executing the step of starting the integrated testing tool based on the first execution instruction, the method further includes:
[0014] Get pre-built filter components;
[0015] The preset first screening condition and the second screening condition are configured as screening identification parameters into the pre-built screening component to obtain the preset screening component, wherein the first screening condition includes identifying whether the class name of the class where the target code is located contains a target specified field, and the second screening condition includes identifying whether the class name of the class where the target code is located has a target specified annotation;
[0016] The interface name of a unique full-scale test interface and the interface names of other non-full-scale test interfaces are pre-configured in the integrated test tool.
[0017] Furthermore, the step of calling a preset screening component in the integrated testing tool to screen out the target class to be tested specifically includes:
[0018] Obtaining the full test code as the target code;
[0019] Identify the code classes to which the target codes belong respectively;
[0020] Identify, according to the first screening condition, the code class containing the target specified field in all code classes, add the class name of the code class containing the target specified field to a preset first set, and add the class name of the code class not containing the target specified field to a preset second set;
[0021] Identify, according to the second screening condition, code classes in the second set that do not contain the target specified annotation, and add the class names of the code classes that do not contain the target specified annotation to the first set;
[0022] The code classes corresponding to all the elements in the first set are used as the target classes to be tested.
[0023] Furthermore, the step of traversing the methods in the target class and generating test index data of the target structure specifically includes:
[0024] Traverse the methods contained in all target classes through code traversal;
[0025] Generate according to the correspondence between class name and method name <key:value>The test index data of the structure, where key and value represent the class name and method name respectively;
[0026] or,
[0027] According to the correspondence between the class name and the method name, test index data of the JSON array structure is generated, wherein the class name is the JSON array name in the JSON array structure, and the method name is the array element in the JSON array structure.
[0028] Further, after executing the step of receiving the second execution instruction, the method further includes:
[0029] Parsing the second execution instruction to obtain target test information contained in the second execution instruction;
[0030] According to the target test information, the test interface type of the target test interface is identified, wherein the test interface type includes a full test interface and a non-full test interface. The full test interface refers to testing all methods in all target classes, and the non-full test interface refers to testing only the tool class corresponding to the method to be tested in the target test information.
[0031] Furthermore, the target test information includes an interface name of a target test interface, and the step of identifying the test interface type of the target test interface according to the target test information specifically includes:
[0032] If the interface name of the target test interface is the interface name of the full-scale test interface, then the target test interface is a full-scale test interface;
[0033] If the interface name of the target test interface is not the interface name of the full-type test interface, then the target test interface is a non-full-type test interface.
[0034] Further, the step of selecting a target test interface based on the second execution instruction, calling the target test interface, and screening out a method to be tested from the test index data for testing includes:
[0035] If the target test interface is a full test interface, the preset full test interface is called, and by parsing all test index data, all classes to be tested and all methods to be tested corresponding to all classes to be tested are identified, and all methods to be tested corresponding to all classes to be tested are tested.
[0036] Furthermore, the target test information also includes the name of the method to be tested, and the step of selecting the target test interface based on the second execution instruction, calling the target test interface, and screening the method to be tested from the test index data for testing also includes:
[0037] If the target test interface is a non-full-scale test interface, the target test interface is called, and the target class to be tested is determined according to the method name to be tested in the target test information and the test index data, and all methods in the target class are tested.
[0038] In order to solve the above technical problems, the embodiment of the present application also provides a code testing device, which adopts the following technical solution:
[0039] A code testing device, comprising:
[0040] A first execution instruction receiving module, used to receive a first execution instruction, wherein the first execution instruction is an instruction to start a preset integrated test tool;
[0041] An integrated testing tool starting module, used to start the integrated testing tool based on the first execution instruction;
[0042] A test screening module, used to call a preset screening component in the integrated test tool to screen out a target class to be tested;
[0043] A test index data generation module, used to traverse the methods in the target class and generate test index data of the target structure;
[0044] A second execution instruction receiving module, used for receiving a second execution instruction, wherein the second execution instruction is a target test interface selection calling instruction;
[0045] A test execution module is used to select a target test interface based on the second execution instruction, call the target test interface, and filter out a method to be tested from the test index data for testing.
[0046] In order to solve the above technical problems, the embodiment of the present application further provides a computer device, which adopts the following technical solution:
[0047] A computer device comprises a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the above-mentioned code testing method when executing the computer-readable instructions.
[0048] In order to solve the above technical problems, the embodiment of the present application further provides a computer-readable storage medium, which adopts the following technical solution:
[0049] A computer-readable storage medium stores computer-readable instructions, which implement the steps of the code testing method described above when executed by a processor.
[0050] Compared with the prior art, the embodiments of the present application have the following beneficial effects:
[0051] The code testing method described in the embodiment of the present application receives a first execution instruction; starts the integrated testing tool based on the first execution instruction; calls a preset screening component in the integrated testing tool to screen out the target class to be tested; traverses the methods in the target class and generates test index data for the target structure; receives a second execution instruction; selects a target test interface based on the second execution instruction, calls the target test interface, and screens out the method to be tested from the test index data for testing. The code testing method described in the present application first screens all target classes in the code through a screening component, and generates test index data for the target structure based on the relationship between the class and method names, and then judges the interface type of the target test interface, and uses different test methods combined with the test index data to test the target code, which is more scientific and comprehensive, avoids test omissions, and tries to ensure test coverage before going online. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] In order to more clearly illustrate the scheme in the present application, a brief introduction is given below to the drawings required for use in the description of the embodiments of the present application. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0053] Figure 1 is an exemplary system architecture diagram to which the present application may be applied;
[0054] Figure 2 is a flow chart of an embodiment of a code testing method according to the present application;
[0055] Figure 3 It is a flowchart of a specific embodiment of configuring and deploying the integrated testing tool in the code testing method described in this application;
[0056] Figure 4 yes Figure 2 A flowchart of a specific embodiment of step 203 is shown;
[0057] Figure 5 yes Figure 2 A flowchart of a specific embodiment of step 204 is shown;
[0058] Figure 6 yes Figure 2 A flowchart of a specific embodiment of step 206 is shown;
[0059] Figure 7 is a structural schematic diagram of an embodiment of a code testing device according to the present application;
[0060] Figure 8 It is a structural diagram of an embodiment of a computer device according to the present application. DETAILED DESCRIPTION
[0061] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by technicians in the technical field of the present application; the terms used in the specification of the application herein are only for the purpose of describing specific embodiments and are not intended to limit the present application; the terms "including" and "having" and any variations thereof in the specification and claims of the present application and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of the present application or the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order.
[0062] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0063] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings.
[0064] like Figure 1 As shown, the system architecture 100 may include a terminal device 101, a network 102 and a server 103. The terminal device 101 may be a laptop 1011, a tablet computer 1012 or a mobile phone 1013. The network 102 is used to provide a medium for a communication link between the terminal device 101 and the server 103. The network 102 may include various connection types, such as wired, wireless communication links or optical fiber cables.
[0065] The user can use the terminal device 101 to interact with the server 103 through the network 102 to receive or send messages, etc. Various communication client applications can be installed on the terminal device 101, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0066] The terminal device 101 can be any electronic device with a display screen and supporting web browsing. In addition to a laptop computer 1011, a tablet computer 1012 or a mobile phone 1013, the terminal device 101 can also be an e-book reader, an MP3 player (Moving Picture Experts Group Audio Layer III), an MP4 (Moving Picture Experts Group Audio Layer IV), a laptop computer, a desktop computer, etc.
[0067] The server 103 may be a server that provides various services, such as a background server that provides support for a web page displayed on the terminal device 101 .
[0068] It should be noted that the code testing method provided in the embodiment of the present application is generally executed by a terminal device, and accordingly, the code testing device is generally arranged in the terminal device.
[0069] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0070] Continue to refer Figure 2 , shows a flow chart of an embodiment of a code testing method according to the present application. The code testing method comprises the following steps:
[0071] Step 201, receiving a first execution instruction, wherein the first execution instruction is an instruction to start a preset integrated test tool;
[0072] Specifically, the first execution instruction is, for example, a test preparation instruction or a test start instruction sent by a tester before the code goes online.
[0073] Step 202: starting the integrated testing tool based on the first execution instruction;
[0074] Specifically, by adding test related information into an integrated testing tool, it is convenient to directly call the overall tool during the testing phase.
[0075] Step 203, calling a preset screening component in the integrated testing tool to screen out the target class to be tested;
[0076] By presetting a screening component in the integrated testing tool and screening out the target class to be tested, it is possible to screen out all the tool classes in the target code and test the code in the tool class separately.
[0077] Step 204, traverse the methods in the target class and generate test index data of the target structure;
[0078] By generating test index data of the target structure for the methods contained in all target classes respectively, its purpose is that if the tool method in the tool class is rewritten or a self-built tool method is newly added to the tool class during the development process, the usability test of the rewritten tool method or the self-built tool method can be performed by searching the class name and method name in the test index data, thereby avoiding test omissions.
[0079] Step 205, receiving a second execution instruction, wherein the second execution instruction is a target test interface selection call instruction;
[0080] Specifically, the second execution instruction includes an instruction for performing a test interface call selection.
[0081] Step 206: select a target test interface based on the second execution instruction, call the target test interface, and filter out a method to be tested from the test index data for testing.
[0082] In this embodiment, by receiving a first execution instruction; based on the first execution instruction, starting the integrated test tool; calling the preset screening component in the integrated test tool to screen out the target class to be tested; traversing the methods in the target class, and generating test index data for the target structure; receiving a second execution instruction; based on the second execution instruction, selecting the target test interface, calling the target test interface, and screening out the method to be tested from the test index data for testing. The code testing method described in the present application first screens all target classes in the code through a screening component, and generates test index data for the target structure based on the relationship between the class and method names, and then judges the interface type of the target test interface, and uses different test methods combined with the test index data to test the target code, which is more scientific and comprehensive, avoids test omissions, and tries to ensure the test coverage before going online.
[0083] After the step of receiving the first execution instruction, the method further includes: parsing the first execution instruction to start the integrated testing tool according to the parsing result. In this embodiment, the integrated testing tool includes a self-written integrated testing tool or an integrated testing tool improved from an existing testing tool.
[0084] Continue to refer Figure 3 In some optional implementations, before executing step 202, a step of configuring and deploying the integrated testing tool is also included. Figure 3 It is a flowchart of a specific embodiment of configuring and deploying the integrated testing tool in the code testing method described in the present application, comprising the following steps:
[0085] Step 301, obtaining a pre-built screening component;
[0086] After obtaining the pre-built screening component, the method further includes deploying the pre-built screening component into the integrated testing tool as a pre-screening component before the test starts.
[0087] Step 302, configuring the preset first screening condition and the second screening condition as screening identification parameters into the pre-built screening component to obtain the preset screening component, wherein the first screening condition includes identifying whether the class name of the class where the target code is located contains a target specified field, and the second screening condition includes identifying whether the class name of the class where the target code is located has a target specified annotation;
[0088] Step 303: pre-configure the interface name of a unique full-scale test interface and the interface names of other non-full-scale test interfaces in the integrated test tool.
[0089] Specifically, the first screening condition includes identifying whether the class name of the class where the target code is located contains the "util" field, and the second screening condition includes identifying whether the class name of the class where the target code is located has "@component" and "@resource" annotations.
[0090] By presetting a screening component in the integrated testing tool and screening out the target class to be tested, it is possible to screen out all the tool classes in the target code and test the code in the tool class separately.
[0091] Continue to refer Figure 4 , in some optional implementations, Figure 4 yes Figure 2 The flowchart of a specific embodiment of step 203 shown includes the following steps:
[0092] Step 401, obtaining a full test code as the target code;
[0093] Step 402, identifying the code class to which the target codes belong respectively;
[0094] Step 403, identifying the code classes containing the target specified field in all code classes according to the first screening condition, adding the class names of the code classes containing the target specified field to a preset first set, and adding the class names of the code classes not containing the target specified field to a preset second set;
[0095] Step 404, identifying the code classes that do not contain the target specified annotation among the code classes contained in the second set according to the second screening condition, and adding the class names of the code classes that do not contain the target specified annotation to the first set;
[0096] Step 405: taking the code classes corresponding to all elements in the first set as the target classes to be tested.
[0097] Specifically, first, obtain the full test code as the target code, identify the code classes to which the target code belongs, identify the code classes containing the "util" field and the code classes not containing the "util" field in all code classes through the first screening condition, identify the code classes not having the "@component" or / and "@resource" annotation from the code classes not containing the "util" field according to the second screening condition, add the code classes containing the "util" field and the code classes not having the "@component" or / and "@resource" annotation to the preset first set, and use the code classes corresponding to all the elements in the first set as the target classes to be tested. Since "@component" or / and "@resource" are annotations for non-tool classes, the code classes not having the "@component" or / and "@resource" annotations are also tool classes, that is, the target classes to be tested are all tool classes.
[0098] This processing method can be used to specifically test the tool classes in the full test code, avoiding the situation where the online code only tests one-sided business code but fails to fully test the code in the tool class, thereby improving the test coverage and code confidence when testing online.
[0099] Continue to refer Figure 5 , in some optional implementations, Figure 5 yes Figure 2 The flowchart of a specific embodiment of step 204 shown includes the following steps:
[0100] Step 501, traverse the methods contained in all target classes respectively by code traversal;
[0101] Step 502: Generate a <key:value>The test index data of the structure, where key and value represent the class name and method name respectively;
[0102] or,
[0103] Step 503: Generate test index data of a JSON array structure according to the correspondence between the class name and the method name, wherein the class name is the JSON array name in the JSON array structure, and the method name is the array element in the JSON array structure.
[0104] Specifically, according to the correspondence between class name and method name, generate <key:value>For example, if the name of a tool class is Autils, and the Autils class contains 5 methods, a, b, c, d, and e, then the test index data is <autils:a> 、 <autils:b> 、 <autils:c> 、 <autils:d> 、 <autils:e>Or the test index data is <a:autils> 、 <b:autils> 、 <c:autils> 、 <d:autils> 、 <e:autils>;
[0105] Alternatively, test index data of a JSON array structure is generated according to the correspondence between the class name and the method name. Similarly, for example, the class name of a tool class is Autils, and the Autils class contains a total of 5 methods, namely a, b, c, d and e, then the test index data is: {Autils:[a,b,c,d,e]}.
[0106] The above method is used to generate test index data of the target structure for the methods contained in all target classes. The purpose is that if the tool method in the tool class is rewritten or a new self-built tool method is added to the tool class during the development process, the rewritten tool method or the self-built tool method can be used to perform usability testing on the test index data to avoid test omissions.
[0107] In some optional implementations, the following steps are also included after step 205: parsing the second execution instruction to obtain the target test information contained in the second execution instruction; identifying the test interface type of the target test interface based on the target test information, wherein the test interface type includes a full test interface and a non-full test interface, the full test interface refers to testing all methods in all target classes, and the non-full test interface refers to testing only the tool class corresponding to the method to be tested in the target test information.
[0108] By setting up full test interfaces and other non-full test interfaces, it is convenient to use automated testing tools to perform automated testing on all methods involved in the tool class in the target code, which can be achieved by simply calling the full test interface. It is also convenient for specialized testers to freely call non-full test interfaces to perform non-full testing according to test requirements, which is more scientific, humane and reasonable.
[0109] Specifically, the target test information includes the interface name of the target test interface, and the step of identifying the test interface type of the target test interface based on the target test information specifically includes: if the interface name of the target test interface is the interface name of the full-type test interface, then the target test interface is a full-type test interface; if the interface name of the target test interface is not the interface name of the full-type test interface, then the target test interface is a non-full-type test interface.
[0110] By identifying whether the target test interface is a full-scale test interface or other non-full-scale test interfaces, different test methods can be used for subsequent testing.
[0111] Specifically, the target test information also includes the name of the method to be tested, and the name of the method to be tested can be set or selected by the tester. Accordingly, the name of the method to be tested can be an empty value when the called target test interface is a full test interface; however, when the called target test interface is a non-full test interface, the name of the method to be tested cannot be an empty value, that is, it should contain at least one method name.
[0112] Continue to refer Figure 6 , in some optional implementations, Figure 6 yes Figure 2 The flowchart of a specific embodiment of step 206 shown includes the following steps:
[0113] Step 601: If the target test interface is a full-scale test interface, call the preset full-scale test interface, and identify all classes to be tested and all methods to be tested corresponding to all classes to be tested by parsing all test index data, and test all methods to be tested corresponding to all classes to be tested;
[0114] Step 602: If the target test interface is a non-full-scale test interface, the target test interface is called, and the target class to be tested is determined according to the method name to be tested in the target test information and the test index data, and all methods in the target class are tested.
[0115] Specifically, by determining the interface type of the target test interface, different test methods are used in combination with the test index data to test the target code, which is more scientific and comprehensive, avoids test omissions, and tries to ensure the test coverage before going online.
[0116] The present application receives a first execution instruction; starts the integrated test tool based on the first execution instruction; calls a preset screening component in the integrated test tool to screen out the target class to be tested; traverses the methods in the target class and generates test index data for the target structure; receives a second execution instruction; selects a target test interface based on the second execution instruction, calls the target test interface, and screens out the method to be tested from the test index data for testing. The code testing method described in the present application first screens all target classes in the code through a screening component, and generates test index data for the target structure based on the relationship between the class and method names, and then determines the interface type of the target test interface, and uses different test methods combined with the test index data to test the target code, which is more scientific and comprehensive, avoids test omissions, and tries to ensure test coverage before going online.
[0117] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0118] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0119] In an embodiment of the present application, a first execution instruction is received; based on the first execution instruction, the integrated test tool is started; a preset screening component in the integrated test tool is called to screen out the target class to be tested; the methods in the target class are traversed, and test index data of the target structure is generated; a second execution instruction is received; based on the second execution instruction, a target test interface is selected, the target test interface is called, and the method to be tested is screened out from the test index data for testing. The code testing method described in the present application first screens all target classes in the code through a screening component, and generates test index data of the target structure according to the relationship between the class and method names, and then the interface type of the target test interface is judged, and different test methods are used in combination with the test index data to test the target code, which is more scientific and comprehensive, avoids test omissions, and tries to ensure the test coverage before going online.
[0120] Further references Figure 7 , as a response to the above Figure 2 In order to realize the method shown in the figure, the present application provides an embodiment of a code testing device, and the device embodiment is Figure 2 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0121] like Figure 7 As shown, the code testing device 700 described in this embodiment includes: a first execution instruction receiving module 701, an integrated test tool starting module 702, a test screening module 703, a test index data generating module 704, a second execution instruction receiving module 705 and a test execution module 706. Among them:
[0122] A first execution instruction receiving module 701 is used to receive a first execution instruction, wherein the first execution instruction is an instruction to start a preset integrated test tool;
[0123] An integrated testing tool starting module 702, configured to start the integrated testing tool based on the first execution instruction;
[0124] A test screening module 703 is used to call a preset screening component in the integrated test tool to screen out a target class to be tested;
[0125] A test index data generating module 704 is used to traverse the methods in the target class and generate test index data of the target structure;
[0126] A second execution instruction receiving module 705 is used to receive a second execution instruction, wherein the second execution instruction is a target test interface selection calling instruction;
[0127] The test execution module 706 is used to select a target test interface based on the second execution instruction, call the target test interface, and filter out a method to be tested from the test index data for testing.
[0128] The code testing device 700 described in this embodiment also includes a test interface type identification module, which is used to parse the second execution instruction and obtain the target test information contained in the second execution instruction; according to the target test information, identify the test interface type of the target test interface, specifically, if the interface name of the target test interface is the interface name of the full test interface, then the target test interface is a full test interface; if the interface name of the target test interface is not the interface name of the full test interface, then the target test interface is a non-full test interface.
[0129] The present application receives a first execution instruction; starts the integrated test tool based on the first execution instruction; calls a preset screening component in the integrated test tool to screen out the target class to be tested; traverses the methods in the target class and generates test index data for the target structure; receives a second execution instruction; selects a target test interface based on the second execution instruction, calls the target test interface, and screens out the method to be tested from the test index data for testing. The code testing method described in the present application first screens all target classes in the code through a screening component, and generates test index data for the target structure based on the relationship between the class and method names, and then determines the interface type of the target test interface, and uses different test methods combined with the test index data to test the target code, which is more scientific and comprehensive, avoids test omissions, and tries to ensure test coverage before going online.
[0130] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through computer-readable instructions, and the 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-mentioned methods. Among them, the aforementioned storage medium can be a non-volatile storage medium such as a disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0131] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0132] To solve the above technical problems, the present application also provides a computer device. Figure 8 , Figure 8 This is a basic structural block diagram of the computer device in this embodiment.
[0133] The computer device 8 includes a memory 8a, a processor 8b, and a network interface 8c which are interconnected through a system bus. It should be noted that: Figure 8 Only a computer device 8 having a component memory 8a, a processor 8b, and a network interface 8c is shown, but it should be understood that it is not required to implement all the components shown, and more or fewer components may be implemented instead. Among them, those skilled in the art 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 a microprocessor, an application specific integrated circuit (ASIC), a field programmable gate array (FPGA), a digital processor (DSP), an embedded device, etc.
[0134] The computer device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The computer device may interact with a user through a keyboard, a mouse, a remote controller, a touch pad, or a voice control device.
[0135] The memory 8a includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 8a can be an internal storage unit of the computer device 8, such as a hard disk or memory of the computer device 8. In other embodiments, the memory 8a can also be an external storage device of the computer device 8, such as a plug-in hard disk equipped on the computer device 8, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (FlashCard), etc. Of course, the memory 8a can also include both the internal storage unit of the computer device 8 and its external storage device. In this embodiment, the memory 8a is generally used to store the operating system and various application software installed on the computer device 8, such as a computer-readable instruction of a code testing method, etc. In addition, the memory 8a can also be used to temporarily store various types of data that have been output or are to be output.
[0136] The processor 8b may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips in some embodiments. The processor 8b is generally used to control the overall operation of the computer device 8. In this embodiment, the processor 8b is used to run computer-readable instructions stored in the memory 8a or process data, such as computer-readable instructions for running the code testing method.
[0137] The network interface 8c may include a wireless network interface or a wired network interface. The network interface 8c is generally used to establish a communication connection between the computer device 8 and other electronic devices.
[0138] The computer device proposed in this embodiment belongs to the field of research and development design technology and is applied in code testing scenarios. This application receives a first execution instruction; starts the integrated test tool based on the first execution instruction; calls the preset screening component in the integrated test tool to screen out the target class to be tested; traverses the methods in the target class and generates test index data for the target structure; receives a second execution instruction; selects the target test interface based on the second execution instruction, calls the target test interface, and screens out the method to be tested from the test index data for testing. The code testing method described in this application first screens all target classes in the code through the screening component, and generates test index data for the target structure based on the relationship between the class and method names, and then judges the interface type of the target test interface, and uses different test methods combined with the test index data to test the target code, which is more scientific and comprehensive, avoids test omissions, and tries to ensure the test coverage before going online.
[0139] The present application also provides another implementation, namely, providing a computer-readable storage medium, wherein the computer-readable storage medium stores computer-readable instructions, and the computer-readable instructions can be executed by a processor to enable the processor to perform the steps of the code testing method as described above.
[0140] The computer-readable storage medium proposed in this embodiment belongs to the field of research and development design technology and is applied to code testing scenarios. This application receives a first execution instruction; starts the integrated testing tool based on the first execution instruction; calls the preset screening component in the integrated testing tool to screen out the target class to be tested; traverses the methods in the target class, and generates test index data for the target structure; receives a second execution instruction; selects the target test interface based on the second execution instruction, calls the target test interface, and screens out the method to be tested from the test index data for testing. The code testing method described in this application first screens all target classes in the code through a screening component, and generates test index data for the target structure based on the relationship between the class and method names, and then judges the interface type of the target test interface, and uses different test methods combined with the test index data to test the target code, which is more scientific and comprehensive, avoids test omissions, and tries to ensure the test coverage before going online.
[0141] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course 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, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0142] Obviously, the embodiments described above are only some embodiments of the present application, rather than all embodiments. The preferred embodiments of the present application are given in the accompanying drawings, but they 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 disclosure of the present application more thorough and comprehensive. Although the present application is described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions recorded in the aforementioned specific implementation methods, or to perform equivalent replacement of some of the technical features therein. Any equivalent structure made using the contents of the specification and drawings of this application, directly or indirectly used in other related technical fields, is similarly within the scope of patent protection of this application.< / e:autils> < / d:autils> < / c:autils> < / b:autils> < / a:autils> < / autils:e> < / autils:d> < / autils:c> < / autils:b> < / autils:a> < / key:value> < / key:value> < / key:value>
Claims
1. A code testing method, characterized in that: The steps include: Receiving a first execution instruction, wherein the first execution instruction is an instruction to start a preset integrated testing tool; Starting the integrated testing tool based on the first execution instruction; Calling a preset screening component in the integrated testing tool to screen out the target class to be tested; Traverse the methods in the target class and generate test index data of the target structure; Receiving a second execution instruction, wherein the second execution instruction is a target test interface selection calling instruction; A target test interface is selected based on the second execution instruction, the target test interface is called, and a method to be tested is screened out from the test index data for testing.
2. The code testing method according to claim 1, characterized in that: Before executing the step of starting the integrated testing tool based on the first execution instruction, the method further includes: Get pre-built filter components; The preset first screening condition and the second screening condition are configured as screening identification parameters into the pre-built screening component to obtain the preset screening component, wherein the first screening condition includes identifying whether the class name of the class where the target code is located contains a target specified field, and the second screening condition includes identifying whether the class name of the class where the target code is located has a target specified annotation; The interface name of a unique full-scale test interface and the interface names of other non-full-scale test interfaces are pre-configured in the integrated test tool.
3. The code testing method according to claim 2, characterized in that: The step of calling a preset screening component in the integrated testing tool to screen out the target class to be tested specifically includes: Obtaining the full test code as the target code; Identify the code classes to which the target codes belong respectively; Identify, according to the first screening condition, the code class containing the target specified field in all code classes, add the class name of the code class containing the target specified field to a preset first set, and add the class name of the code class not containing the target specified field to a preset second set; Identify, according to the second screening condition, code classes in the second set that do not contain the target specified annotation, and add the class names of the code classes that do not contain the target specified annotation to the first set; The code classes corresponding to all the elements in the first set are used as the target classes to be tested.
4. The code testing method according to claim 1, characterized in that: The step of traversing the methods in the target class and generating test index data of the target structure specifically includes: Traverse the methods contained in all target classes through code traversal; Generate according to the correspondence between class name and method name <key:value> The test index data of the structure, where key and value represent the class name and method name respectively;< / key:value> or, According to the correspondence between the class name and the method name, test index data of the JSON array structure is generated, wherein the class name is the JSON array name in the JSON array structure, and the method name is the array element in the JSON array structure.
5. The code testing method according to claim 1, characterized in that: After executing the step of receiving the second execution instruction, the method further includes: Parsing the second execution instruction to obtain target test information contained in the second execution instruction; According to the target test information, the test interface type of the target test interface is identified, wherein the test interface type includes a full test interface and a non-full test interface. The full test interface refers to testing all methods in all target classes, and the non-full test interface refers to testing only the tool class corresponding to the method to be tested in the target test information.
6. The code testing method according to claim 5, characterized in that: The target test information includes the interface name of the target test interface, and the step of identifying the test interface type of the target test interface according to the target test information specifically includes: If the interface name of the target test interface is the interface name of the full-scale test interface, then the target test interface is a full-scale test interface; If the interface name of the target test interface is not the interface name of the full-type test interface, then the target test interface is a non-full-type test interface.
7. The code testing method according to claim 6, characterized in that: The step of selecting a target test interface based on the second execution instruction, calling the target test interface, and screening out a method to be tested from the test index data for testing includes: If the target test interface is a full test interface, the preset full test interface is called, and by parsing all test index data, all classes to be tested and all methods to be tested corresponding to all classes to be tested are identified, and all methods to be tested corresponding to all classes to be tested are tested.
8. The code testing method according to claim 6, characterized in that: The target test information also includes the name of the method to be tested. The step of selecting a target test interface based on the second execution instruction, calling the target test interface, and filtering the method to be tested from the test index data for testing also includes: If the target test interface is a non-full-scale test interface, the target test interface is called, and the target class to be tested is determined according to the method name to be tested in the target test information and the test index data, and all methods in the target class are tested.
9. A code testing device, characterized in that: include: A first execution instruction receiving module, used to receive a first execution instruction, wherein the first execution instruction is an instruction to start a preset integrated test tool; An integrated testing tool starting module, used to start the integrated testing tool based on the first execution instruction; A test screening module, used to call a preset screening component in the integrated test tool to screen out a target class to be tested; A test index data generation module, used to traverse the methods in the target class and generate test index data of the target structure; A second execution instruction receiving module, used for receiving a second execution instruction, wherein the second execution instruction is a target test interface selection calling instruction; A test execution module is used to select a target test interface based on the second execution instruction, call the target test interface, and filter out a method to be tested from the test index data for testing.
10. A computer device, characterized in that: The method comprises a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the code testing method according to any one of claims 1 to 8 when executing the computer-readable instructions.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by a processor, the steps of the code testing method according to any one of claims 1 to 8 are implemented.