WO2023217118A1 - 一种代码测试、测试用例生成的方法及装置 - Google Patents
一种代码测试、测试用例生成的方法及装置 Download PDFInfo
- Publication number
- WO2023217118A1 WO2023217118A1 PCT/CN2023/092939 CN2023092939W WO2023217118A1 WO 2023217118 A1 WO2023217118 A1 WO 2023217118A1 CN 2023092939 W CN2023092939 W CN 2023092939W WO 2023217118 A1 WO2023217118 A1 WO 2023217118A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- code
- tested
- test
- return value
- test case
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Ceased
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Prevention of errors by analysis, debugging or testing of software
- G06F11/3668—Testing of software
- G06F11/3672—Test management
- G06F11/3684—Test management for test design, e.g. generating new test cases
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Prevention of errors by analysis, debugging or testing of software
- G06F11/3668—Testing of software
- G06F11/3672—Test management
- G06F11/3676—Test management for coverage analysis
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Prevention of errors by analysis, debugging or testing of software
- G06F11/3668—Testing of software
- G06F11/3672—Test management
- G06F11/3692—Test management for test results analysis
Definitions
- This description relates to the field of computer technology, and in particular, to a method and device for code testing and test case generation.
- This specification provides a method and device for code testing and test case generation to partially solve the problem in related technologies of low accuracy of test results caused by returning error type return values.
- This manual adopts the following technical solution:
- This manual provides a code testing method, including: obtaining the code to be tested; according to the type of parameters required for the method called by the code to be tested, and/or testing the code to be tested.
- the analysis results obtained after analyzing the bytecode corresponding to the code determine the actual return value type corresponding to the method called when testing the code to be tested.
- the method types of the methods called when testing the code to be tested include: At least one of a generic method and forced type conversion; according to the actual return value type, the test result for the code to be tested is obtained.
- the code to be tested is method called when The actual return value type corresponding to the method specifically includes: obtaining the code of the method called by the code to be tested; and determining the code of the method called by the code to be tested according to the obtained code of the method called by the code to be tested.
- the actual return value of the method called, and the association relationship between the parameter type required by the method called by the code to be tested; according to the association relationship, and the type of parameters required by the method called by the code under test Determine the actual return value type corresponding to the method called when testing the code to be tested.
- the test result for the code to be tested which specifically includes: creating a method data structure MethodDescripter structure according to the association relationship, the MethodDescripter structure includes: the actual return of the calling method Value type, the number of times the MethodDescripter structure is called, the method name of the calling method, the class name of the calling method, and the incoming parameters of the calling method; generate the code to be tested based on the MethodDescripter structure and the actual return value type
- the mock method corresponding to the called method; through the mock method, the test results for the code to be tested are obtained.
- the code to be tested is The actual return value type corresponding to the method called, specifically includes: by analyzing the bytecode corresponding to the code to be tested, determining that the method type from the method called by the code to be tested is forced type conversion The method is used as the target method; when testing the code to be tested, the actual return value type corresponding to the method called by the code to be tested is determined according to the target method.
- the method further includes: converting the The corresponding relationship between the code line number corresponding to the target method in the code to be tested and the actual return value type after forced type conversion of the return value of the target method is saved; when testing the code to be tested, According to the target method, determine the actual return value type corresponding to the method called by the code to be tested, specifically including: if during the testing process of the code to be tested, determine the method called by the code to be tested The code line number of the forced type conversion method is used as the target line number; according to the target line number, the actual return value type corresponding to the method called by the code to be tested is queried from the pre-saved correspondence relationship.
- obtaining the test result for the code to be tested specifically includes: querying the actual return value corresponding to the method called by the code to be tested from the pre-saved correspondence relationship Type, generate a mock method corresponding to the method called by the code to be tested; use the mock method to obtain test results for the code to be tested.
- This manual provides a method for generating test cases, including: obtaining each test case; for each test Use case, through the above code testing method, test the set code to obtain the test results corresponding to the test case; according to the test results corresponding to each test case, determine whether the preset test conditions are met; if it is determined that the preset test conditions are not met, test conditions, regenerate each test case, and test the set code according to each regenerated test case until the test condition is met, and obtain the test case generated when the test condition is met.
- regenerating each test case specifically includes: selecting at least some test cases from each test case and combining them in pairs to obtain each test case combination; for each test case combination, combining the two test cases included in the test case combination. Parameters of the same type in each test case are weighted to obtain a regenerated test case.
- regenerating each test case specifically includes: selecting at least some test cases from each test case; for each selected test case, numerically adjusting at least some parameters included in the test case, and/or Adjust the code to be tested contained in the test case to obtain a regenerated test case.
- This specification provides a code testing device, including: an acquisition module, used to obtain the code to be tested; a determination module, used to determine the type of parameters required by the method called by the code to be tested, and/or to determine the The analysis results obtained after analyzing the bytecode corresponding to the code to be tested determine the actual return value type corresponding to the method called when the code to be tested is tested, and the method type of the method called when the code to be tested is tested. It includes: at least one of a generic method and forced type conversion; a test module, used to obtain test results for the code to be tested according to the actual return value type.
- the determination module is specifically configured to obtain the code of the method called by the code to be tested; and determine the code of the method called by the code to be tested according to the obtained code of the method called by the code to be tested.
- the relationship between the actual return value of the method called during testing and the type of parameters required by the method called by the code to be tested; according to the relationship, and the type of parameters required by the method called by the code under test determine the actual return value type corresponding to the method called when testing the code to be tested.
- the test module is specifically configured to create a method data structure MethodDescripter structure according to the association relationship.
- the MethodDescripter structure includes: the actual return value type of the calling method, the number of times the MethodDescripter structure is called, and the method of calling the method. name, the class name of the calling method, and the incoming parameters of the calling method; according to the MethodDescripter structure and the actual return value type, a mock method corresponding to the method called by the code to be tested is generated; through the mock method , to obtain the test results for the code to be tested.
- the determination module is specifically configured to determine, from the methods called by the code to be tested, that the method type is a forced type conversion method by analyzing the bytecode corresponding to the code to be tested, as target Method; when testing the code to be tested, determine the actual return value type corresponding to the method called by the code to be tested according to the target method.
- the device further includes: an analysis module, configured to compare the code line number corresponding to the target method in the code to be tested with the actual return value of the return value of the target method after forced type conversion.
- the corresponding relationship of the types is saved; the determination module is specifically used to determine, during the testing process of the code to be tested, that the method called by the code to be tested is the code line number of the forced type conversion method, as the target Line number; according to the target line number, query the actual return value type corresponding to the method called by the code to be tested from the pre-saved correspondence.
- the test module is specifically configured to generate the actual return value type corresponding to the method called by the code to be tested based on the query from the pre-saved correspondence relationship, and generate the return value type corresponding to the method called by the code to be tested. Mock method; through the mock method, test results for the code to be tested are obtained.
- This manual provides a device for generating test cases, including: a use case acquisition module, used to obtain each test case; a use case testing module, used to test the set code for each test case through the above code testing method , obtain the test results corresponding to the test case; the judgment module is used to determine whether the preset test conditions are met based on the test results corresponding to each test case; the generation module is used to re-run the test when it is determined that the test conditions are not met.
- a use case acquisition module used to obtain each test case
- a use case testing module used to test the set code for each test case through the above code testing method , obtain the test results corresponding to the test case
- the judgment module is used to determine whether the preset test conditions are met based on the test results corresponding to each test case
- the generation module is used to re-run the test when it is determined that the test conditions are not met.
- Each test case is generated, and the set code is tested according to each regenerated test case until the test condition is met, and the test case
- the generation module is specifically configured to select at least some test cases from each test case and combine them in pairs to obtain each test case combination; for each test case combination, combine the two test case combinations included in the test case combination. Parameters of the same type in the test case are weighted to obtain a regenerated test case.
- the generation module is specifically configured to select at least some test cases from each test case; for each selected test case, numerically adjust at least some parameters contained in the test case, and/or The code to be tested contained in the test case is adjusted to obtain a regenerated test case.
- the storage medium stores a computer program.
- the computer program is executed by a processor, the above code testing and test case generation methods are implemented.
- This specification provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor.
- the processor executes the program, the above code testing and test case generation methods are implemented.
- the first method of code testing is to obtain the code to be tested, and then determine the code to be tested based on the type of parameters required by the method called by the code to be tested and/or the analysis results obtained after analyzing the bytecode corresponding to the code to be tested.
- the method type of the method called when testing the code to be tested includes at least one of calling a generic method and forced type conversion, and based on the actual return value type, the specific return value type is obtained. Test results of the code under test.
- the actual return value type of the generic method called during the running process of the code to be tested and the method where forced type conversion occurs can be accurately determined, so that the actual return value type can be determined based on The determined actual return value type is used to test the code to be tested, thereby improving the accuracy of the test results.
- Figure 1 is a schematic flow chart of a code testing method provided in this manual
- Figure 2 is a schematic diagram of the method for determining the actual return value type of the generic method provided in this specification
- Figure 3 is a schematic flow chart of a test case generation method provided in this manual
- Figure 4 is a schematic diagram of a code testing device provided in this specification.
- Figure 5 is a schematic diagram of a device for generating test cases provided in this specification.
- FIG. 6 is a schematic diagram of an electronic device corresponding to FIG. 1 provided in this specification.
- Figure 1 is a schematic flow chart of a code testing method provided in this manual, including the following steps S101 Go to S103.
- the tester can test the code of the software to be tested based on the testing requirements. Specifically, the tester can first determine a part of the code from the code of the software to be tested as the code to be tested, and then the code to be tested can be Conduct tests to obtain test results for the code to be tested.
- the code to be tested may refer to a collection of codes that are part of the code of the software to be tested.
- the code to be tested may be one or more classes to be tested (a class here refers to a A custom reference data type, the class encapsulates the code corresponding to several attributes and methods).
- the code to be tested can also be one or more methods (i.e., a collection of code statements) contained in the code of the software to be tested. , these code statements together perform a function (the method is contained in the class or object of the class) corresponding code.
- the execution subject of the method for implementing code testing may refer to a designated device such as a terminal device installed on the business platform, or may refer to a terminal device such as a desktop computer, laptop computer, etc.
- a terminal device such as a desktop computer, laptop computer, etc.
- the terminal device can first obtain the code to be tested, and then test the code to be tested to obtain the test results of the code to be tested.
- S102 Based on the type of parameters required for the method called by the code to be tested and/or the analysis results obtained after analyzing the bytecode corresponding to the code to be tested, determine the parameters used when the code to be tested is tested.
- the method type of the method called when testing the code to be tested includes at least one of a generic method and forced type conversion.
- the terminal device can intercept the calling instructions of the method called by the code under test during running, and determine the method type of the method called by the code under test during running based on the intercepted calling instructions.
- the method type of the method called by the code under test during the running process can be a generic method (that is, a method whose incoming parameters are of uncertain type) and a forced type conversion (that is, a method where a forced type conversion occurs during the calling process).
- a generic method that is, a method whose incoming parameters are of uncertain type
- a forced type conversion that is, a method where a forced type conversion occurs during the calling process.
- interception in the above content is not interception in the literal sense, but monitoring the calling instructions of the method called by the code under test during the running process, through the method of dynamic proxy. A method similar to the interception effect.
- this manual mainly focuses on determining the actual return value types of the above two method types, that is, the generic method and the forced type conversion. Therefore, the following will focus on how to determine the two method types.
- the actual return value type of the method is explained in detail.
- the terminal device can obtain the code of the generic method called in the code to be tested after intercepting the calling instruction of the generic method in the code to be tested.
- the code of the generic method called determines the relationship between the actual return value type of the method called when the code to be tested is tested, and the required parameter type of the method called by the code to be tested, and then based on the determined relationship, Determine the actual return value type corresponding to the generic method called when testing the code to be tested, as shown in Figure 2.
- Figure 2 is a schematic diagram of a method for determining the actual return value type of a generic method provided in this specification.
- the terminal device can monitor the calling instructions of the method under test when the code under test is running, and then can obtain the calling instructions in the code under test before the called method is executed.
- the code of the generic method called so as to conduct a generic analysis of the code of the generic method called by the code to be tested, and determine the various actual return value types of the generic method called when the code to be tested is tested,
- the association between the various parameter types required by the generic method called by the code under test that is, the parameter types that need to be passed in when the code under test calls the method).
- the terminal device can create a MethodDescripter structure for each method data structure according to the determined association relationship (for each incoming parameter type of the generic method, the incoming parameter type corresponds to the actual The combination of return value types corresponds to a MethodDescripter structure), and then based on the intercepted calling instructions, the actual parameters passed in when the code under test calls the generic method can be determined, and based on the parameters passed in, the query can be performed in each MethodDescripter structure. The MethodDescripter structure that matches the passed-in parameter can then determine the actual return value type of the generic method called when testing the code to be tested.
- the MethodDescripter structure includes: the actual return value type of the calling method, the number of times the MethodDescripter structure is called, the method name of the calling method, the class name of the calling method, the incoming parameters of the calling method, and the unique identification ID of the MethodDescripter structure.
- the terminal device can generate a mock method corresponding to the method called by the code to be tested based on the MethodDescripter structure that matches the incoming parameter, and then can simulate and generate the return value of the method called by the code to be tested through the mock method. To get the test results for the code to be tested.
- the terminal device can determine that the method type from the method called by the code to be tested is mandatory by analyzing the bytecode corresponding to the code to be tested in advance.
- the method of type conversion is used as the target method, and the corresponding relationship between the code line number corresponding to the target method in the code to be tested and the actual return value type after forced type conversion of the return value of the target method is saved (taking into account that it is saved to The data in the hash table is easy to read, and the corresponding relationship here can be saved in the hash table).
- the terminal device can determine the actual return value type based on the above correspondence during the code testing process.
- the method information here includes: the code of the calling method, and the context information of the calling method, where,
- the context information of the calling method includes: the variable object defined by the calling method, the scope chain of the calling method (i.e., the sequence linked list for finding variables in the calling method), the caller's calling code (i.e., the calling code of the generic method or The code of the method where the cast occurs), etc.
- the terminal device can determine the code line number of the method called by the code to be tested where the forced type conversion occurs based on the obtained method information of the calling method, as the target line number, and then based on the target line number, from the pre-saved code where the forced type conversion occurs
- the type conversion method can query the corresponding code line number in the code to be tested and the actual return value type after the forced type conversion of the return value of the method where the forced type conversion occurs.
- the actual return value type corresponding to the type conversion method.
- the terminal device can arbitrarily select a data type from the preset type pool as a candidate return value type, and then use the candidate return value type as the code to be tested when testing.
- the actual return value type of the method where the forced type conversion occurs, and the test results based on the candidate return value type are obtained. Then, based on the test results, it can be judged whether the candidate return value type is the forced type called when testing the code to be tested.
- the actual return value type of the converted method if not, select a return value type from the type pool again as a candidate return value type until it is determined that the candidate return value type is the one called when testing the code to be tested. to the actual return value type of the method.
- the data types in the type pool in the above content may be predetermined by the terminal device before the code to be tested is run. Specifically, the terminal device can analyze the bytecode corresponding to the code to be tested and determine all the data types contained in the code to be tested. After that, the determined data types contained in the code to be tested can be saved to a predetermined data type. Set the type in the pool.
- the terminal device can accurately determine the actual return value type of the generic method called during the running of the code under test and the method where forced type conversion occurs, so that it can Based on the determined actual return value type, the code to be tested is tested, thereby improving the accuracy of the test results.
- the above code testing method can not only be used to test the code to be tested, but can also be used to generate test cases, that is, through the above code testing method, to build a test case that can achieve a variety of test goals (the goals here can be Refers to some preferred test cases (when the coverage of various types of code to be tested reaches a preset threshold).
- the method of generating test cases is described in detail below, as shown in Figure 3.
- FIG. 3 is a schematic flowchart of a test case generation method provided in this specification, including the following steps S301 to S304.
- the terminal device can obtain the code association information of the code to be tested before testing the code to be tested, and then generate each test case based on the code to be tested and the association information of the code to be tested, where the code association information It can be, for example, document information of the code to be tested, context information of the code to be tested, etc.
- the terminal device can run the test case through the above code testing method to test the setting code contained in the test case and obtain the test results corresponding to the test case, where the setting code It can refer to the code to be tested, or it can refer to any piece of code (for example, the code that has been tested, or it can be used as the setting code, and then by using the method of testing the setting code, some optimal test cases are finally obtained.
- the test results here refer to the testing effect of the code to be tested, such as: line coverage of the code to be tested, method coverage of the code to be tested, exception coverage of the code to be tested, etc.
- the initial test cases generated by the terminal device usually cannot achieve the multiple preset test goals well. Therefore, iteration based on these initial test cases is also needed to optimize each initial test case and finally achieve the target to be tested.
- the test goals of the code among which, the specific process of iterating on each test case is as follows: steps to achieve.
- S303 Determine whether the preset test conditions are met based on the test results corresponding to each test case.
- test conditions If it is determined that the test conditions are not met, regenerate each test case, and test the code to be tested based on each regenerated test case until the test conditions are met. When the test conditions are met, the test conditions are met. Generated test cases.
- the terminal device determines whether the preset test conditions are met based on the test results of each test case. If it is determined that the test conditions are not met, each test case is regenerated, and the code to be tested is tested based on the regenerated test cases until the test conditions are met. Until the test conditions are met, the test cases generated when the test conditions are met are obtained.
- the preset test conditions can be formulated according to the test requirements, for example: the line coverage of the code to be tested reaches the preset threshold, and another example: the number of iterations reaches the preset threshold, etc.
- the method of regenerating each test case can be to sort the test cases according to the test results of each test case (for example, sort according to the line coverage of the code to be tested), and according to the sorted test cases , filter out each basic test case.
- the terminal device can select at least some basic test cases from each basic test case and combine them in pairs to obtain each test case combination, and for each test case combination, according to the test case combination, among the two basic test cases
- the included parameters of the same type are weighted to obtain regenerated test cases.
- the terminal device can also select at least some basic test cases from each basic test case, and for each selected basic test case, numerically adjust the parameters included in the basic test case, and/or change the The code under test contained in the basic test case is adjusted to regenerate each test case.
- the MethodDescripter structure contains: the actual return value type of the calling method, the number of times the MethodDescripter structure is called, the method name of the calling method, the class name of the calling method, the type of parameters passed in by the calling method, and regenerates each test case to treat Test each incoming parameter type of the generic method called by the test code, as well as the actual return value type.
- the terminal device can generate initial test cases for the set code and pass them through In the process of testing the set code through each initial test case, each initial test case is optimized through iteration based on the test results of each initial test case, so that the final generated test case can test the set code. Code, conduct comprehensive testing, thereby improving testing results.
- Figure 4 is a schematic diagram of a code testing device provided in this specification, including: an acquisition module 401, used to obtain the code to be tested; a determination module 402, used to determine the type of parameters required by the method called by the code to be tested. , and/or the analysis results obtained after analyzing the bytecode corresponding to the code to be tested, determine the actual return value type corresponding to the method called when the code to be tested is tested, when the code to be tested is tested.
- the method type of the called method includes: at least one of a generic method and forced type conversion; the testing module 403 is used to obtain test results for the code to be tested according to the actual return value type.
- the determination module 402 is specifically configured to obtain the code of the method called by the code to be tested; and determine the code of the method called by the code to be tested according to the obtained code of the method called by the code to be tested.
- the actual return value of the method called during code testing is related to the parameter type required by the method called by the code to be tested; according to the related relationship, and the parameters required by the method called by the code to be tested.
- Type determine the actual return value type corresponding to the method called when testing the code to be tested.
- the test module 403 is specifically configured to create a method data structure MethodDescripter structure according to the association relationship.
- the MethodDescripter structure includes: the actual return value type of the calling method, the number of times the MethodDescripter structure is called, and the method of calling the method. name, the class name of the calling method, and the incoming parameters of the calling method; according to the MethodDescripter structure and the actual return value type, a mock method corresponding to the method called by the code to be tested is generated; through the mock method , to obtain the test results for the code to be tested.
- the determination module 402 is specifically configured to determine, from the methods called by the code to be tested, that the method type is a forced type conversion method by analyzing the bytecode corresponding to the code to be tested. , as the target method; when testing the code to be tested, determine the actual return value type corresponding to the method called by the code to be tested according to the target method.
- the device further includes: an analysis module 404, configured to compare the code line number corresponding to the target method in the code to be tested with the actual return value of the target method after forced type conversion.
- the corresponding relationship between the value types is saved; the determination module 402 is specifically used to determine if during the testing process of the code to be tested, The method called by the code to be tested is determined to be the code line number of the forced type conversion method as the target line number; according to the target line number, the code called by the code to be tested is queried from the pre-saved correspondence.
- the actual return value type corresponding to the method is performed by the code line number of the forced type conversion method.
- the testing module 403 is specifically configured to generate a response value corresponding to the method called by the code to be tested based on querying the actual return value type corresponding to the method called by the code to be tested from the pre-saved correspondence relationship.
- the mock method through the mock method, the test results for the code to be tested are obtained.
- Figure 5 is a schematic diagram of a test case generation device provided in this specification, including: a use case acquisition module 501, used to obtain each test case; a use case testing module 502, used for each test case, through the above code testing method , test the set code to obtain the test results corresponding to the test case; the judgment module 503 is used to determine whether the preset test conditions are met based on the test results corresponding to each test case; the generation module 504 is used to determine whether When the test conditions are not met, each test case is regenerated, and the set code is tested according to each regenerated test case until the test condition is met, and the test generated when the test condition is met is obtained.
- a use case acquisition module 501 used to obtain each test case
- a use case testing module 502 used for each test case, through the above code testing method , test the set code to obtain the test results corresponding to the test case
- the judgment module 503 is used to determine whether the preset test conditions are met based on the test results corresponding to each test case
- the generation module 504 is specifically configured to select at least some test cases from each test case and combine them in pairs to obtain each test case combination; for each test case combination, combine the two test case combinations included in the test case combination. Parameters of the same type in each test case are weighted to obtain a regenerated test case.
- the generation module 504 is specifically configured to select at least some test cases from each test case; for each selected test case, numerically adjust at least some parameters included in the test case, and/or Adjust the code to be tested contained in the test case to obtain a regenerated test case.
- This specification also provides a computer-readable storage medium that stores a computer program.
- the computer program can be used to execute the method of code testing and test case generation provided in Figure 1 above.
- FIG. 6 This specification also provides a schematic structural diagram of the electronic device shown in FIG. 6 corresponding to FIG. 1 .
- the electronic device includes a processor, internal bus, network interface, memory and non-volatile memory, and of course may also include other hardware required for business.
- the processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it to implement the method of code testing and test case generation described in Figure 1 above.
- this specification does not exclude other implementation methods, such as logic devices or a combination of software and hardware, etc. That is to say, the execution subject of the following processing flow is not limited to each logical unit, and may also be hardware or logic device.
- PLD Programmable Logic Device
- FPGA Field Programmable Gate Array
- HDL Hardware Description Language
- HDL High-Speed Integrated Circuit Hardware Description Language
- ABEL Advanced Boolean Expression Language
- AHDL Advanced Boolean Expression Language
- Confluence CUPL
- HDCal Component Description Language
- JHDL Java Hardware Description Language
- Lava Lava
- Lola MyHDL
- PALASM RHDL
- VHDL Very-High-Speed Integrated Circuit Hardware Description Language
- Verilog Verilog
- the controller may be implemented in any suitable manner, for example, the controller may take the form of, for example, a microprocessor or processor and a computer readable medium storing computer readable program code (eg, software or firmware) executable by the (micro)processor. , logic gates, switches, Application Specific Integrated Circuit (ASIC), programmable logic controllers and embedded microcontrollers.
- controllers include but are not limited to the following microcontrollers: ARC 625D, Atmel AT91SAM, For Microchip PIC18F26K20 and Silicone Labs C8051F320, the memory controller can also be implemented as part of the memory's control logic.
- the controller in addition to implementing the controller in the form of pure computer-readable program code, the controller can be completely programmed with logic gates, switches, application-specific integrated circuits, programmable logic controllers and embedded logic by logically programming the method steps. Microcontroller, etc. to achieve the same function. Therefore, this controller can be considered as a hardware component, and the devices included therein for implementing various functions can also be considered as structures within the hardware component. Or even, the means for implementing various functions can be considered as structures within hardware components as well as software modules implementing the methods.
- a typical implementation device is a computer.
- computer examples For example, it may be a personal computer, laptop computer, cellular phone, camera phone, smartphone, personal digital assistant, media player, navigation device, email device, game console, tablet computer, wearable device, or any of these devices. Any combination of equipment.
- embodiments of the present specification may be provided as methods, systems, or computer program products.
- the present description may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment that combines software and hardware aspects.
- the present description may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk memory, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein.
- These computer program instructions may also be stored in a computer-readable memory that causes a computer or other programmable data processing apparatus to operate in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including the instruction means, the instructions
- the device implements the functions specified in a process or processes of the flowchart and/or a block or blocks of the block diagram.
- These computer program instructions may also be loaded onto a computer or other programmable data processing device, causing a series of operating steps to be performed on the computer or other programmable device to produce computer-implemented processing, thereby executing on the computer or other programmable device.
- Instructions provide steps for implementing the functions specified in a process or processes of a flowchart diagram and/or a block or blocks of a block diagram.
- a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
- processors CPUs
- input/output interfaces network interfaces
- memory volatile and non-volatile memory
- Memory may include non-permanent storage in computer-readable media, random access memory (RAM), and/or non-volatile memory in the form of read-only memory (ROM) or flash memory (flash RAM).
- RAM random access memory
- ROM read-only memory
- flash RAM flash memory
- Computer-readable media includes both persistent and non-volatile, removable and non-removable media that can be implemented by any method or technology for storage of information.
- Information may be computer-readable instructions, data structures, modules of programs, or other data.
- Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), and read-only memory.
- PRAM phase change memory
- SRAM static random access memory
- DRAM dynamic random access memory
- RAM random access memory
- read-only memory read-only memory
- ROM read-only memory
- EEPROM electrically erasable programmable read-only memory
- flash memory or other memory technology
- compact disc read-only memory CD-ROM
- DVD digital versatile disc
- Magnetic tape cassettes tape magnetic disk storage or other magnetic storage devices or any other non-transmission medium can be used to store information that can be accessed by a computing device.
- computer-readable media does not include transitory media, such as modulated data signals and carrier waves.
- embodiments of the present specification may be provided as methods, systems, or computer program products.
- the present description may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment that combines software and hardware aspects.
- the present description may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk memory, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein.
- program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types.
- the present description may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through communications networks.
- program modules may be located in both local and remote computer storage media including storage devices.
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Computer Hardware Design (AREA)
- Quality & Reliability (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Debugging And Monitoring (AREA)
Abstract
Description
Claims (20)
- 一种代码测试的方法,包括:获取待测试代码;根据所述待测试代码所调用的方法所需参数的类型,和/或对所述待测试代码对应的字节码进行分析后得到的分析结果,确定在所述待测试代码测试时所调用的方法对应的实际返回值类型,所述待测试代码测试时所调用的方法的方法类型包括:泛型方法以及强制类型转换中的至少一种;根据所述实际返回值类型,得到针对所述待测试代码的测试结果。
- 如权利要求1所述的方法,根据所述待测试代码所调用的方法所需参数的类型,和/或对所述待测试代码对应的字节码进行分析后得到的分析结果,确定在所述待测试代码测试时所调用的方法对应的实际返回值类型,具体包括:获取所述待测试代码所调用的方法的代码;根据获取到的所述待测试代码所调用的方法的代码,确定在所述待测试代码测试时所调用的方法的实际返回值类型,与所述待测试代码所调用的方法所需参数类型的关联关系;根据所述关联关系,以及所述待测试代码所调用的方法所需参数的类型,确定在所述待测试代码测试时所调用的方法对应的实际返回值类型。
- 如权利要求2所述的方法,根据所述实际返回值类型,得到针对所述待测试代码的测试结果,具体包括:根据所述关联关系,创建方法数据结构MethodDescripter结构,所述MethodDescripter结构包括:调用方法的实际返回值类型、MethodDescripter结构被调用的次数、调用方法的方法名、调用方法的所属类名、调用方法的传入参数;根据所述MethodDescripter结构,以及所述实际返回值类型,生成所述待测试代码所调用的方法对应的mock方法;通过所述mock方法,得到针对所述待测试代码的测试结果。
- 如权利要求1所述的方法,根据所述待测试代码所调用的方法所需参数的类型,和/或对所述待测试代码对应的字节码进行分析后得到的分析结果,确定在所述待测试代码测试时所调用的方法对应的实际返回值类型,具体包括:通过对所述待测试代码对应的字节码的分析,确定从所述待测试代码所调用的方法中确定出方法类型为强制类型转换的方法,作为目标方法;在对所述待测试代码进行测试时,根据所述目标方法,确定出在所述待测试代码所 调用的方法对应的实际返回值类型。
- 如权利要求4所述的方法,在对所述待测试代码进行测试时,根据所述目标方法,确定出在所述待测试代码所调用的方法对应的实际返回值类型之前,所述方法还包括:将所述目标方法在所述待测试代码中对应的代码行号,与所述目标方法的返回值经强制类型转换后的实际返回值类型的对应关系进行保存;在对所述待测试代码进行测试时,根据所述目标方法,确定出在所述待测试代码所调用的方法对应的实际返回值类型,具体包括:在所述待测试代码的测试过程中,确定所述待测试代码所调用的方法为强制类型转换的方法的代码行号,作为目标行号;根据所述目标行号,从预先保存的对应关系中查询出所述待测试代码所调用的方法对应的实际返回值类型。
- 如权利要求5所述的方法,根据所述实际返回值类型,得到针对所述待测试代码的测试结果,具体包括:根据从预先保存的对应关系中查询出所述待测试代码所调用的方法对应的实际返回值类型,生成所述待测试代码所调用的方法对应的mock方法;通过所述mock方法,得到针对所述待测试代码的测试结果。
- 一种测试用例生成的方法,包括:获取各测试用例;针对每个测试用例,通过上述权利要求1~6任一项所述的方法,对设定代码进行测试,得到该测试用例对应的测试结果;根据每个测试用例对应的测试结果,确定是否满足预设的测试条件;若确定不满足所述测试条件,重新生成各测试用例,并根据重新生成的各测试用例,对所述设定代码进行测试,直到满足所述测试条件为止,得到满足所述测试条件时生成的测试用例。
- 如权利要求7所述的方法,重新生成各测试用例,具体包括:从各测试用例中选取至少部分测试用例进行两两组合,得到各测试用例组合;针对每个测试用例组合,将该测试用例组合中包含的两个测试用例内的同类型参数进行加权,得到重新生成的测试用例。
- 如权利要求7所述的方法,重新生成各测试用例,具体包括:从各测试用例中选取至少部分测试用例;针对选取出的每个测试用例,将该测试用例中包含的至少部分参数进行数值调整,和/或将该测试用例中包含的待测试代码进行调整,得到重新生成的测试用例。
- 一种代码测试的装置,包括:获取模块,用于获取待测试代码;确定模块,用于根据所述待测试代码所调用的方法所需参数的类型,和/或对所述待测试代码对应的字节码进行分析后得到的分析结果,确定在所述待测试代码测试时所调用的方法对应的实际返回值类型,所述待测试代码测试时所调用的方法的方法类型包括:泛型方法以及强制类型转换中的至少一种;测试模块,用于根据所述实际返回值类型,得到针对所述待测试代码的测试结果。
- 如权利要求10所述的装置,所述确定模块具体用于,获取所述待测试代码所调用的方法的代码;根据获取到的所述待测试代码所调用的方法的代码,确定所述在所述待测试代码测试时所调用的方法的实际返回值,与所述待测试代码所调用的方法所需参数类型的关联关系;根据所述关联关系,以及所述待测试代码所调用的方法所需参数的类型,确定在所述待测试代码测试时所调用的方法对应的实际返回值类型。
- 如权利要求11所述的装置,所述测试模块具体用于,根据所述关联关系,创建方法数据结构MethodDescripter结构,所述MethodDescripter结构包括:调用方法的实际返回值类型、MethodDescripter结构被调用的次数、调用方法的方法名、调用方法的所属类名、调用方法的传入参数;根据所述MethodDescripter结构,以及所述实际返回值类型,生成所述待测试代码所调用的方法对应的mock方法;通过所述mock方法,得到针对所述待测试代码的测试结果。
- 如权利要求10所述的装置,所述确定模块具体用于,通过对所述待测试代码对应的字节码的分析,确定从所述待测试代码所调用的方法中确定出方法类型为强制类型转换的方法,作为目标方法;在对所述待测试代码进行测试时,根据所述目标方法,确定出在所述待测试代码所调用的方法对应的实际返回值类型。
- 如权利要求13所述的装置,所述装置还包括:分析模块,用于将所述目标方法在所述待测试代码中对应的代码行号,与所述目标方法的返回值经强制类型转换后的实际返回值类型的对应关系进行保存;所述确定模块具体用于,在所述待测试代码的测试过程中,确定所述待测试代码所调用的方法为强制类型转换的方法的代码行号,作为目标行号;根据所述目标行号,从预先保存的对应关系中查询出所述待测试代码所调用的方法对应的实际返回值类型。
- 如权利要求14所述的装置,所述测试模块具体用于,根据从预先保存的对应 关系中查询出所述待测试代码所调用的方法对应的实际返回值类型,生成所述待测试代码所调用的方法对应的mock方法;通过所述mock方法,得到针对所述待测试代码的测试结果。
- 一种测试用例生成的装置,包括:用例获取模块,用于获取各测试用例;用例测试模块,用于针对每个测试用例,通过上述权利要求1~6任一项所述的方法,对设定代码进行测试,得到该测试用例对应的测试结果;判断模块,用于根据每个测试用例对应的测试结果,确定是否满足预设的测试条件;生成模块,用于在确定不满足所述测试条件时,重新生成各测试用例,并根据重新生成的各测试用例,对所述设定代码进行测试,直到满足所述测试条件为止,得到满足所述测试条件时生成的测试用例。
- 如权利要求16所述的装置,所述生成模块具体用于,从各测试用例中选取至少部分测试用例进行两两组合,得到各测试用例组合;针对每个测试用例组合,将该测试用例组合中包含的两个测试用例内的同类型参数进行加权,得到重新生成的测试用例。
- 如权利要求16所述的装置,所述生成模块具体用于,从各测试用例中选取至少部分测试用例;针对选取出的每个测试用例,将该测试用例中包含的至少部分参数进行数值调整,和/或将该测试用例中包含的待测试代码进行调整,得到重新生成的测试用例。
- 一种计算机可读存储介质,所述存储介质存储有计算机程序,所述计算机程序被处理器执行时实现上述权利要求1~9任一项所述的方法。
- 一种电子设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,所述处理器执行所述程序时实现上述权利要求1~9任一项所述的方法。
Applications Claiming Priority (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202210508851.1A CN114840427B (zh) | 2022-05-10 | 2022-05-10 | 一种代码测试、测试用例生成的方法及装置 |
| CN202210508851.1 | 2022-05-10 |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| WO2023217118A1 true WO2023217118A1 (zh) | 2023-11-16 |
Family
ID=82569467
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| PCT/CN2023/092939 Ceased WO2023217118A1 (zh) | 2022-05-10 | 2023-05-09 | 一种代码测试、测试用例生成的方法及装置 |
Country Status (2)
| Country | Link |
|---|---|
| CN (1) | CN114840427B (zh) |
| WO (1) | WO2023217118A1 (zh) |
Cited By (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN118170692A (zh) * | 2024-05-15 | 2024-06-11 | 阿里云计算有限公司 | 代码测试方法 |
| CN118916280A (zh) * | 2024-07-19 | 2024-11-08 | 建信金融科技有限责任公司 | 测试代码生成方法、装置、设备及存储介质 |
| CN119848874A (zh) * | 2024-12-31 | 2025-04-18 | 浙江大学 | 一种数据处理方法、装置及设备 |
| CN120892355A (zh) * | 2025-09-30 | 2025-11-04 | 重庆长安汽车股份有限公司 | 一种测试用例的生成方法、系统、设备及介质 |
Families Citing this family (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN114840427B (zh) * | 2022-05-10 | 2025-09-19 | 支付宝(杭州)信息技术有限公司 | 一种代码测试、测试用例生成的方法及装置 |
Citations (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN107133174A (zh) * | 2017-05-04 | 2017-09-05 | 浙江路港互通信息技术有限公司 | 测试用例代码自动生成装置与方法 |
| CN113778849A (zh) * | 2021-03-15 | 2021-12-10 | 北京沃东天骏信息技术有限公司 | 用于测试代码的方法、装置、设备以及存储介质 |
| US20210390038A1 (en) * | 2020-06-10 | 2021-12-16 | Sap Se | Automatic evaluation of test code quality |
| CN114840427A (zh) * | 2022-05-10 | 2022-08-02 | 支付宝(杭州)信息技术有限公司 | 一种代码测试、测试用例生成的方法及装置 |
Family Cites Families (7)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN105335281B (zh) * | 2014-07-30 | 2018-03-20 | 阿里巴巴集团控股有限公司 | 一种自动mock外部依赖的方法及装置 |
| CN109992498B (zh) * | 2017-12-29 | 2022-12-02 | 北京京东尚科信息技术有限公司 | 测试用例的生成方法及系统、计算机系统 |
| CN110795168B (zh) * | 2018-08-02 | 2022-11-11 | 武汉斗鱼网络科技有限公司 | 一种获取数据的方法及相关装置 |
| CN112286784B (zh) * | 2019-07-23 | 2024-05-10 | 腾讯科技(深圳)有限公司 | 一种测试用例生成方法、装置、服务器及存储介质 |
| CN111723382A (zh) * | 2020-07-24 | 2020-09-29 | 江西师范大学 | 动态Android程序漏洞验证方法和装置 |
| CN112100059B (zh) * | 2020-08-20 | 2021-09-14 | 浙江大学 | 一种c语言的指针类型分析方法 |
| CN113656290B (zh) * | 2021-08-04 | 2024-07-05 | 支付宝(杭州)信息技术有限公司 | 一种mock点自动识别方法、装置以及设备 |
-
2022
- 2022-05-10 CN CN202210508851.1A patent/CN114840427B/zh active Active
-
2023
- 2023-05-09 WO PCT/CN2023/092939 patent/WO2023217118A1/zh not_active Ceased
Patent Citations (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN107133174A (zh) * | 2017-05-04 | 2017-09-05 | 浙江路港互通信息技术有限公司 | 测试用例代码自动生成装置与方法 |
| US20210390038A1 (en) * | 2020-06-10 | 2021-12-16 | Sap Se | Automatic evaluation of test code quality |
| CN113778849A (zh) * | 2021-03-15 | 2021-12-10 | 北京沃东天骏信息技术有限公司 | 用于测试代码的方法、装置、设备以及存储介质 |
| CN114840427A (zh) * | 2022-05-10 | 2022-08-02 | 支付宝(杭州)信息技术有限公司 | 一种代码测试、测试用例生成的方法及装置 |
Cited By (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN118170692A (zh) * | 2024-05-15 | 2024-06-11 | 阿里云计算有限公司 | 代码测试方法 |
| CN118916280A (zh) * | 2024-07-19 | 2024-11-08 | 建信金融科技有限责任公司 | 测试代码生成方法、装置、设备及存储介质 |
| CN118916280B (zh) * | 2024-07-19 | 2025-12-05 | 建信金融科技有限责任公司 | 测试代码生成方法、装置、设备及存储介质 |
| CN119848874A (zh) * | 2024-12-31 | 2025-04-18 | 浙江大学 | 一种数据处理方法、装置及设备 |
| CN120892355A (zh) * | 2025-09-30 | 2025-11-04 | 重庆长安汽车股份有限公司 | 一种测试用例的生成方法、系统、设备及介质 |
Also Published As
| Publication number | Publication date |
|---|---|
| CN114840427B (zh) | 2025-09-19 |
| CN114840427A (zh) | 2022-08-02 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| WO2023217118A1 (zh) | 一种代码测试、测试用例生成的方法及装置 | |
| CN107832231A (zh) | 一种系统测试方法、装置及介质 | |
| CN106201850B (zh) | 一种兼容性测试方法及装置 | |
| CN110046088A (zh) | 一种接口测试方法、装置及设备 | |
| CN110879781A (zh) | 程序调试方法、装置、电子设备及计算机可读存储介质 | |
| WO2020237508A1 (zh) | 一种断言验证代码绑定方法及装置 | |
| CN108304313B (zh) | 一种用于数据测试的装置、客户端及方法 | |
| CN112559346A (zh) | 一种业务测试的方法及装置 | |
| CN115061928A (zh) | 微服务自动化测试方法、装置、电子设备及存储介质 | |
| CN116402165B (zh) | 一种算子检测的方法、装置、存储介质以及电子设备 | |
| CN109144715A (zh) | 一种资源优化与更新的方法、服务器及设备 | |
| US20230367701A1 (en) | Code testing method and apparatus | |
| WO2017171708A1 (en) | Code coverage thresholds for code segments based on usage frequency and change frequency | |
| WO2026017186A1 (zh) | Ios应用程序开发的调试和性能监控方法及系统 | |
| CN108733564B (zh) | 一种浏览器性能测试方法、装置及设备 | |
| US20230367936A1 (en) | Verification method, electronic device and storage medium | |
| CN118860788A (zh) | 一种异常监测方法、装置、存储介质及电子设备 | |
| CN110674495A (zh) | 一种数组越界访问的检测方法、装置及设备 | |
| CN105868092B (zh) | 一种日志文件的处理方法及装置 | |
| CN116048977A (zh) | 一种基于数据还原的测试方法及装置 | |
| CN107239270B (zh) | 代码处理方法和装置 | |
| CN111737109B (zh) | 一种集群文件系统测试方法及装置 | |
| CN116302968A (zh) | 一种性能测试方法、装置、电子设备及存储介质 | |
| CN116126707A (zh) | 测试数据生成方法、装置及设备 | |
| CN115344855A (zh) | 基于内核的故障注入方法、系统、电子设备和存储介质 |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| 121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 23802888 Country of ref document: EP Kind code of ref document: A1 |
|
| NENP | Non-entry into the national phase |
Ref country code: DE |
|
| 122 | Ep: pct application non-entry in european phase |
Ref document number: 23802888 Country of ref document: EP Kind code of ref document: A1 |
|
| 32PN | Ep: public notification in the ep bulletin as address of the adressee cannot be established |
Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 30.04.2025) |
|
| 122 | Ep: pct application non-entry in european phase |
Ref document number: 23802888 Country of ref document: EP Kind code of ref document: A1 |