WO2023217118A1 - 一种代码测试、测试用例生成的方法及装置 - Google Patents

一种代码测试、测试用例生成的方法及装置 Download PDF

Info

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
Application number
PCT/CN2023/092939
Other languages
English (en)
French (fr)
Inventor
张剑飞
周海莲
周智泉
赵红兵
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Alipay Hangzhou Information Technology Co Ltd
Original Assignee
Alipay Hangzhou Information Technology Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Alipay Hangzhou Information Technology Co Ltd filed Critical Alipay Hangzhou Information Technology Co Ltd
Publication of WO2023217118A1 publication Critical patent/WO2023217118A1/zh
Anticipated expiration legal-status Critical
Ceased legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Prevention of errors by analysis, debugging or testing of software
    • G06F11/3668Testing of software
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Prevention of errors by analysis, debugging or testing of software
    • G06F11/3668Testing of software
    • G06F11/3672Test management
    • G06F11/3676Test management for coverage analysis
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Prevention of errors by analysis, debugging or testing of software
    • G06F11/3668Testing of software
    • G06F11/3672Test management
    • G06F11/3692Test 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

一种代码测试、测试用例生成的方法及装置 技术领域
本说明书涉及计算机技术领域,尤其涉及一种代码测试、测试用例生成的方法及装置。
背景技术
在软件测试的过程中,由于待测试方法可能会与其他方法之间存在较高的依赖,从而会导致测试人员不能单独针对待测试方法进行测试,进而影响了测试工作的进行,因此,为了解决这个问题,软件的测试人员通常会通过Mock服务(即,依赖服务替身),用来代替与待测试方法相关联的其他方法,来进行待测试方法的测试工作。
但是,由于在使用Mock服务时,需要确定待测试方法所调用的方法的返回值类型,对于普通的方法来说,可以直接确定出方法的返回值类型,而对于一些返回值需要在根据实际运行时,才能确定出具体类型的方法而言,往往会随机确定一个类型作为该方法的返回值类型,这样就降低了生成的测试用例的准确性,影响了测试用例的覆盖率。
因此,如何能够在进行软件的测试工作时,有效的确定出待测试方法的返回值类型,进而提升待测试方法的测试结果的准确性,则是一个亟待解决的问题。
发明内容
本说明书提供一种代码测试、测试用例生成的方法及装置,以部分的解决相关技术存在的返回错误类型的返回值而导致的测试结果准确性较低的问题。
本说明书采用下述技术方案:本说明书提供了一种代码测试的方法,包括:获取待测试代码;根据所述待测试代码所调用的方法所需参数的类型,和/或对所述待测试代码对应的字节码进行分析后得到的分析结果,确定在所述待测试代码测试时所调用的方法对应的实际返回值类型,所述待测试代码测试时所调用的方法的方法类型包括:泛型方法以及强制类型转换中的至少一种;根据所述实际返回值类型,得到针对所述待测试代码的测试结果。
可选地,根据所述待测试代码所调用的方法所需参数的类型,和/或对所述待测试代码对应的字节码进行分析后得到的分析结果,确定在所述待测试代码测试时所调用的方 法对应的实际返回值类型,具体包括:获取所述待测试代码所调用的方法的代码;根据获取到的所述待测试代码所调用的方法的代码,确定所述在所述待测试代码测试时所调用的方法的实际返回值,与所述待测试代码所调用的方法所需参数类型的关联关系;根据所述关联关系,以及所述待测试代码所调用的方法所需参数的类型,确定在所述待测试代码测试时所调用的方法对应的实际返回值类型。
可选地,根据所述实际返回值类型,得到针对所述待测试代码的测试结果,具体包括:根据所述关联关系,创建方法数据结构MethodDescripter结构,所述MethodDescripter结构包括:调用方法的实际返回值类型、MethodDescripter结构被调用的次数、调用方法的方法名、调用方法的所属类名、调用方法的传入参数;根据所述MethodDescripter结构,以及所述实际返回值类型,生成所述待测试代码所调用的方法对应的mock方法;通过所述mock方法,得到针对所述待测试代码的测试结果。
可选地,根据所述待测试代码所调用的方法所需参数的类型,和/或对所述待测试代码对应的字节码进行分析后得到的分析结果,确定在所述待测试代码测试时所调用的方法对应的实际返回值类型,具体包括:通过对所述待测试代码对应的字节码的分析,确定从所述待测试代码所调用的方法中确定出方法类型为强制类型转换的方法,作为目标方法;在对所述待测试代码进行测试时,根据所述目标方法,确定出在所述待测试代码所调用的方法对应的实际返回值类型。
可选地,在对所述待测试代码进行测试时,根据所述目标方法,确定出在所述待测试代码所调用的方法对应的实际返回值类型之前,所述方法还包括:将所述目标方法在所述待测试代码中对应的代码行号,与所述目标方法的返回值经强制类型转换后的实际返回值类型的对应关系进行保存;在对所述待测试代码进行测试时,根据所述目标方法,确定出在所述待测试代码所调用的方法对应的实际返回值类型,具体包括:若在所述待测试代码的测试过程中,确定所述待测试代码所调用的方法为强制类型转换的方法的代码行号,作为目标行号;根据所述目标行号,从预先保存的对应关系中查询出所述待测试代码所调用的方法对应的实际返回值类型。
可选地,根据所述实际返回值类型,得到针对所述待测试代码的测试结果,具体包括:根据从预先保存的对应关系中查询出所述待测试代码所调用的方法对应的实际返回值类型,生成所述待测试代码所调用的方法对应的mock方法;通过所述mock方法,得到针对所述待测试代码的测试结果。
本说明书提供了一种测试用例生成的方法,包括:获取各测试用例;针对每个测试 用例,通过上述代码测试的方法,对设定代码进行测试,得到该测试用例对应的测试结果;根据每个测试用例对应的测试结果,确定是否满足预设的测试条件;若确定不满足所述测试条件,重新生成各测试用例,并根据重新生成的各测试用例,对所述设定代码进行测试,直到满足所述测试条件为止,得到满足所述测试条件时生成的测试用例。
可选地,重新生成各测试用例,具体包括:从各测试用例中选取至少部分测试用例进行两两组合,得到各测试用例组合;针对每个测试用例组合,将该测试用例组合中包含的两个测试用例内的同类型参数进行加权,得到重新生成的测试用例。
可选地,重新生成各测试用例,具体包括:从各测试用例中选取至少部分测试用例;针对选取出的每个测试用例,将该测试用例中包含的至少部分参数进行数值调整,和/或将该测试用例中包含的待测试代码进行调整,得到重新生成的测试用例。
本说明书提供了一种代码测试的装置,包括:获取模块,用于获取待测试代码;确定模块,用于根据所述待测试代码所调用的方法所需参数的类型,和/或对所述待测试代码对应的字节码进行分析后得到的分析结果,确定在所述待测试代码测试时所调用的方法对应的实际返回值类型,所述待测试代码测试时所调用的方法的方法类型包括:泛型方法以及强制类型转换中的至少一种;测试模块,用于根据所述实际返回值类型,得到针对所述待测试代码的测试结果。
可选地,所述确定模块具体用于,获取所述待测试代码所调用的方法的代码;根据获取到的所述待测试代码所调用的方法的代码,确定所述在所述待测试代码测试时所调用的方法的实际返回值,与所述待测试代码所调用的方法所需参数类型的关联关系;根据所述关联关系,以及所述待测试代码所调用的方法所需参数的类型,确定在所述待测试代码测试时所调用的方法对应的实际返回值类型。
可选地,所述测试模块具体用于,根据所述关联关系,创建方法数据结构MethodDescripter结构,所述MethodDescripter结构包括:调用方法的实际返回值类型、MethodDescripter结构被调用的次数、调用方法的方法名、调用方法的所属类名、调用方法的传入参数;根据所述MethodDescripter结构,以及所述实际返回值类型,生成所述待测试代码所调用的方法对应的mock方法;通过所述mock方法,得到针对所述待测试代码的测试结果。
可选地,所述确定模块具体用于,通过对所述待测试代码对应的字节码的分析,确定从所述待测试代码所调用的方法中确定出方法类型为强制类型转换的方法,作为目标 方法;在对所述待测试代码进行测试时,根据所述目标方法,确定出在所述待测试代码所调用的方法对应的实际返回值类型。
可选地,所述装置还包括:分析模块,用于将所述目标方法在所述待测试代码中对应的代码行号,与所述目标方法的返回值经强制类型转换后的实际返回值类型的对应关系进行保存;所述确定模块具体用于,若在所述待测试代码的测试过程中,确定所述待测试代码所调用的方法为强制类型转换的方法的代码行号,作为目标行号;根据所述目标行号,从预先保存的对应关系中查询出所述待测试代码所调用的方法对应的实际返回值类型。
可选地,所述测试模块具体用于,根据从预先保存的对应关系中查询出所述待测试代码所调用的方法对应的实际返回值类型,生成所述待测试代码所调用的方法对应的mock方法;通过所述mock方法,得到针对所述待测试代码的测试结果。
本说明书提供了一种测试用例生成的装置,包括:用例获取模块,用于获取各测试用例;用例测试模块,用于针对每个测试用例,通过上述代码测试的方法,对设定代码进行测试,得到该测试用例对应的测试结果;判断模块,用于根据每个测试用例对应的测试结果,确定是否满足预设的测试条件;生成模块,用于在确定不满足所述测试条件时,重新生成各测试用例,并根据重新生成的各测试用例,对所述设定代码进行测试,直到满足所述测试条件为止,得到满足所述测试条件时生成的测试用例。
可选地,所述生成模块具体用于,从各测试用例中选取至少部分测试用例进行两两组合,得到各测试用例组合;针对每个测试用例组合,将该测试用例组合中包含的两个测试用例内的同类型参数进行加权,得到重新生成的测试用例。
可选地,所述生成模块具体用于,从各测试用例中选取至少部分测试用例;针对选取出的每个测试用例,将该测试用例中包含的至少部分参数进行数值调整,和/或将该测试用例中包含的待测试代码进行调整,得到重新生成的测试用例。
本说明书提供了一种计算机可读存储介质,所述存储介质存储有计算机程序,所述计算机程序被处理器执行时实现上述代码测试、测试用例生成的方法。
本说明书提供了一种电子设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,所述处理器执行所述程序时实现上述代码测试、测试用例生成的方法。
本说明书采用的上述至少一个技术方案能够达到以下有益效果:在本说明书提供的 代码测试的方法,首选获取待测试代码,进而根据待测试代码所调用的方法所需参数的类型,和/或对待测试代码对应的字节码进行分析后得到的分析结果,确定在待测试代码测试时所调用的方法对应的实际返回值类型,待测试代码测试时所调用的方法的方法类型包括:调用泛型方法以及强制类型转换中的至少一种,并根据实际返回值类型,得到针对待测试代码的测试结果。
从上述方法中可以看出,可以在待测试代码测试时,准确的确定出在待测试代码在运行过程中所调用的泛型方法和发生强制类型转换的方法的实际返回值类型,从而可以基于确定出的实际返回值类型,对待测试代码进行测试,进而提升了测试结果的准确性。
附图说明
此处所说明的附图用来提供对本说明书的进一步理解,构成本说明书的一部分,本说明书的示意性实施例及其说明用于解释本说明书,并不构成对本说明书的不当限定。在附图中:
图1为本说明书中提供的一种代码测试的方法的流程示意图;
图2为本说明书中提供的泛型方法的实际返回值类型的确定方法的示意图;
图3为本说明书提供的一种测试用例生成的方法的流程示意图;
图4为本说明书提供的一种代码测试的装置的示意图;
图5为本说明书提供的一种测试用例生成的装置的示意图;
图6为本说明书提供的一种对应于图1的电子设备的示意图。
具体实施方式
为使本说明书的目的、技术方案和优点更加清楚,下面将结合本说明书具体实施例及相应的附图对本说明书技术方案进行清楚、完整地描述。显然,所描述的实施例仅是本说明书一部分实施例,而不是全部的实施例。基于本说明书中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本说明书保护的范围。
以下结合附图,详细说明本说明书各实施例提供的技术方案。
图1为本说明书中提供的一种代码测试的方法的流程示意图,包括以下步骤S101 至S103。
S101:获取待测试代码。
在本说明书中,测试人员可以基于测试需求,对待测试软件的代码进行测试,具体地,测试人员可以先从待测试软件的代码中,确定出一部分代码,作为待测试代码,进而可以对待测试代码进行测试,以得到针对待测试代码的进行测试的测试结果。
其中,待测试代码可以是指作为待测试软件的代码中一部分代码的集合,例如:待测试代码可以是待测试软件的代码中包含的一个或多个待测试类(这里的类是指一种自定义的引用数据类型,类中封装了若干个属性和方法)对应的代码,再例如:待测试代码还可以是待测试软件的代码中包含的一个或多个方法(即,代码语句的集合,这些代码语句一起执行了一个功能,方法包含于类或类的对象中)对应的代码。
在本说明书中,用于实现代码测试的方法的执行主体,可以是指终端设备等设置于业务平台的指定设备,也可以是指诸如台式电脑、笔记本电脑等终端设备,为了便于描述,下面仅以终端设备是执行主体为例,对本说明书提供的代码测试的方法进行说明。
所以,终端设备在接收到测试人员发送的测试指令后,可以先获取待测试代码,进而针对待测试代码进行测试,以得到待测试代码的测试结果。
S102:根据所述待测试代码所调用的方法所需参数的类型,和/或对所述待测试代码对应的字节码进行分析后得到的分析结果,确定在所述待测试代码测试时所调用的方法对应的实际返回值类型,所述待测试代码测试时所调用的方法的方法类型包括:泛型方法以及强制类型转换中的至少一种。
在待测试代码运行时,终端设备可以拦截待测试代码在运行过程中调用方法的调用指令,根据拦截的调用指令,确定待测试代码在运行过程中调用方法的方法类型。
其中,待测试代码在运行过程中调用方法的方法类型可以是泛型方法(即,方法的传入参数的类型不确定的方法)以及强制类型转换(即,在调用过程中发生强制类型转换的方法,其中,发生强制类型转换是将方法原本的返回值的类型,转换成了另一种数据类型)中的至少一种。
需要说明的是,上述内容中的拦截并不是字面意义上的拦截,而是在待测试代码的运行过程中,监听待测试代码在运行过程中调用方法的调用指令,通过动态代理的方式,实现的一种类似于拦截效果的方法。
基于对上述方法类型的介绍,本说明书中主要是对上述两种方法类型的方法,即对泛型方法和强制类型转换的实际返回值类型进行确定,所以,下面将针对如何确定两种方法类型的方法的实际返回值类型,进行详细说明。
对于泛型方法来说,终端设备可以在拦截到的待测试代码中对泛型方法的调用指令后,可以获取待测试代码中调用的泛型方法的代码,从而根据获取到的待测试代码所调用的泛型方法的代码,确定在待测试代码测试时所调用的方法的实际返回值类型,与待测试代码所调用的方法所需参数类型的关联关系,进而可以基于确定出的关联关系,确定在待测试代码测试时所调用的泛型方法对应的实际返回值类型,如图2所示。
图2为本说明书中提供的泛型方法的实际返回值类型的确定方法的示意图。
结合图2可以看出,终端设备可以在待测试代码运行的过程中,监听到待测试代码在运行过程中调用方法的调用指令,进而可以在被调用的方法执行之前,可以获取待测试代码中调用的泛型方法的代码,从而对获取到的待测试代码所调用的泛型方法的代码进行泛型分析,确定在待测试代码测试时所调用的泛型方法的各种实际返回值类型,与待测试代码所调用的泛型方法所需的各种参数类型(即,待测试代码调用该方法时所需要传入的参数类型)之间的关联关系。
进一步地,终端设备可以根据确定出的关联关系,创建各方法数据结构MethodDescripter结构(针对泛型方法的每种传入的参数类型,该传入的参数类型与该传入的参数类型对应的实际返回值类型的组合,对应一个MethodDescripter结构),进而可以根据拦截的调用指令,确定待测试代码调用泛型方法时的实际传入的参数,并根据传入的参数,在各MethodDescripter结构中,查询与该传入的参数相匹配的MethodDescripter结构,进而可以确定出待测试代码测试时所调用的泛型方法的实际返回值类型。
其中,MethodDescripter结构包括:调用方法的实际返回值类型、MethodDescripter结构被调用的次数、调用方法的方法名、调用方法的所属类名、调用方法的传入参数、MethodDescripter结构的唯一标识ID。
进一步地,终端设备可以基于与该传入的参数相匹配的MethodDescripter结构,生成待测试代码所调用的方法对应的mock方法,进而可以通过mock方法,模拟生成待测试代码调用的方法的返回值,以得到针对待测试代码的测试结果。
需要说明的是,由于在同一个泛型方法在待测试代码中可能被多次调用,因此,在 生成该泛型方法对应的mock方法时,需要根据MethodDescripter结构的被调用次数,按照调用MethodDescripter结构的顺序组装mock语句,生成mock方法。
对于发生强制类型转换的方法来说,终端设备可以在对待测试代码进行测试之前,预先通过对待测试代码对应的字节码的分析,确定从待测试代码所调用的方法中确定出方法类型为强制类型转换的方法,作为目标方法,并将目标方法在待测试代码中对应的代码行号,与目标方法的返回值经强制类型转换后的实际返回值类型的对应关系进行保存(考虑到保存到哈希表的数据易读取的特点,可以将这里的对应关系保存到哈希表中)。
完成上述对应关系的存储后,终端设备即可在代码测试过程中,基于上述对应关系,确定出实际返回值类型。具体的,可以在拦截到待测试代码中调用的强制类型转换的方法的调用指令后,获取调用方法的方法信息,这里的方法信息包括:调用方法的代码,以及调用方法的上下文信息,其中,调用方法的上下文信息包括:调用方法定义的变量对象、调用方法的作用域链(即,调用方法中查找变量的顺序链表)、调用者的调用代码(即,待测试代码中调用泛型方法或发生强制转换的方法的代码)等。
进一步地,终端设备可以根据获取的调用方法的方法信息,确定待测试代码所调用的发生强制类型转换的方法的代码行号,作为目标行号,进而根据目标行号,从预先保存的发生强制类型转换的方法在待测试代码中对应的代码行号,与发生强制类型转换的方法的返回值经强制类型转换后的实际返回值类型的对应关系中,查询出待测试代码所调用的发生强制类型转换的方法对应的实际返回值类型。
由于在实际应用中,可能会在对待测试代码进行字节码分析时,没有将待测试代码中包含的全部发生强制转换的方法识别出来,这样将导致在实际的代码测试过程中,可能无法根据待测试代码中的发生强制转换的方法的代码行号,从预先保存的对应关系中,查询出待测试代码所调用的发生强制类型转换的方法对应的实际返回值类型。
对于这种情况,在本说明书中,终端设备可以从预设的类型池中,任意选取一个数据类型,作为候选返回值类型,进而可以将该候选返回值类型,作为待测试代码测试时所调用的发生强制类型转换的方法的实际返回值类型,并得到基于候选返回值类型的测试结果,而后,可以根据测试结果,判断该候选返回值类型是否为待测试代码测试时所调用的发生强制类型转换的方法的实际返回值类型;若否,则再次从类型池中选取一个返回值类型,作为候选返回值类型,直到确定该候选返回值类型为待测试代码测试时所调用的发生强制类型转换的方法的实际返回值类型为止。
其中,上述内容中的类型池中的数据类型,可以是终端设备在待测试代码运行前预先确定出的。具体的,终端设备可以通过对待测试代码对应的字节码进行分析,确定的待测试代码中包含的所有数据类型,之后,可以将确定出的在待测试代码中包含的数据类型,保存到预设的类型池中的。
从上述内容可以看出,终端设备可以在待测试代码测试时,准确的确定出在待测试代码在运行过程中所调用的泛型方法和发生强制类型转换的方法的实际返回值类型,从而可以基于确定出的实际返回值类型,对待测试代码进行测试,进而提升了测试结果的准确性。
在实际应用中,上述的代码测试方法不仅可以用于对待测试代码进行测试,也可以用于生成测试用例,即,通过上述代码测试方法,来构建出能够实现多种测试目标(这里的目标可以是指,对待测试代码的各类覆盖率达到预设的阈值)的一些优选测试用例,下面详细描述测试用例生成的方法,如图3所示。
图3为本说明书中提供的一种测试用例生成的方法的流程示意图,包括以下步骤S301至S304。
S301:获取各测试用例。
在本说明书中,终端设备可以在针对待测试代码进行测试前,获取待测试代码的代码关联信息,进而根据待测试代码,以及待测试代码的关联信息,生成各测试用例,其中,代码关联信息可以是诸如:待测试代码的文档信息、待测试代码的上下文信息等。
S302:针对每个测试用例,通过上述代码测试的方法,对待测试代码进行测试,得到该测试用例对应的测试结果。
针对每个测试用例,终端设备可以通过上述的代码测试的方法,运行该测试用例,以对该测试用例中包含的设定代码进行测试,得到该测试用例对应的测试结果,其中,设定代码可以是指待测试代码,也可以是指任意的一段代码(例如:已经测试过的代码,也可以作为设定代码,进而通过使用对设定代码进行测试的手段,最终得到一些优选测试用例。)这里的测试结果是指待测试代码的测试效果,诸如:待测试代码的行覆盖率、待测试代码的方法覆盖率、待测试代码的异常覆盖率等。
终端设备生成的初始的测试用例,通常不能很好的实现预先设置的多个测试目标,因此,还需要基于这些初始的测试用例进行迭代,以对各初始的测试用例进行优化,最终达成对待测试代码的测试目标,其中,针对各测试用例进行迭代的具体过程,由以下 步骤实现。
S303:根据每个测试用例对应的测试结果,确定是否满足预设的测试条件。
S304:若确定不满足所述测试条件,重新生成各测试用例,并根据重新生成的各测试用例,对所述待测试代码进行测试,直到满足所述测试条件为止,得到满足所述测试条件时生成的测试用例。
终端设备根据每个测试用例的测试结果,确定是否满足预设的测试条件,若确定不满足测试条件,重新生成各测试用例,并根据重新生成的各测试用例,对待测试代码进行测试,直到满足测试条件为止,得到满足测试条件时生成的测试用例。
其中,预设的测试条件可以根据测试需求制定,例如:待测试代码的行覆盖率达到预设阈值,再例如:迭代的次数达到预设阈值等。
上述内容中,重新生成各测试用例的方法可以是根据各测试用例的测试结果,对各测试用例进行排序(例如:按照待测试代码的行覆盖率大小进行排序),根据排序后的各测试用例,筛选得到各基础测试用例。
进一步地,终端设备可以从各基础测试用例中选取至少部分基础测试用例进行两两组合,得到各测试用例组合,并针对每个测试用例组合,根据该测试用例组合中,两个基础测试用例中包含的同类型参数进行加权,得到重新生成的测试用例。
除此之外,终端设备还可以从各基础测试用例中选取至少部分基础测试用例,针对选取出的每个基础测试用例,将该基础测试用例中包含的参数进行数值调整,和/或将该基础测试用例中包含的待测试代码进行调整,以重新生成各测试用例。
另外,由于在测试用例运行的过程中,针对待测试代码所调用的泛型方法通常会有多个可以传入的参数的类型,因此,终端设备还可以根据该测试用例在运行过程中生成的MethodDescripter结构中包含的:调用方法的实际返回值类型、MethodDescripter结构被调用的次数、调用方法的方法名、调用方法的所属类名、调用方法传入参数的类型,重新生成各测试用例,以对待测试代码所调用的泛型方法的各个传入参数类型,以及实际返回值类型进行测试。
需要说明的是,上述的三种方法可以单独使用,以重新生成各测试用例,也可以一起使用,以重新生成测试用例。
通过上述内容可以看出,终端设备可以针对设定代码生成初始的测试用例,并在通 过各初始的测试用例对设定代码进行测试的过程中,根据各初始的测试用例的测试结果,通过迭代的方式对各初始的测试用例进行优化,以使最终生成的测试用例能够对设定代码,进行全面的测试,从而提升了测试效果。
以上为本说明书的一个或多个实施例提供的代码测试的方法,基于同样的思路,本说明书还提供了相应的代码测试的装置以及测试用例生成的装置,如图4、图5所示。
图4为本说明书提供的一种代码测试的装置的示意图,包括:获取模块401,用于获取待测试代码;确定模块402,用于根据所述待测试代码所调用的方法所需参数的类型,和/或对所述待测试代码对应的字节码进行分析后得到的分析结果,确定在所述待测试代码测试时所调用的方法对应的实际返回值类型,所述待测试代码测试时所调用的方法的方法类型包括:泛型方法以及强制类型转换中的至少一种;测试模块403,用于根据所述实际返回值类型,得到针对所述待测试代码的测试结果。
可选地,所述确定模块402具体用于,获取所述待测试代码所调用的方法的代码;根据获取到的所述待测试代码所调用的方法的代码,确定所述在所述待测试代码测试时所调用的方法的实际返回值,与所述待测试代码所调用的方法所需参数类型的关联关系;根据所述关联关系,以及所述待测试代码所调用的方法所需参数的类型,确定在所述待测试代码测试时所调用的方法对应的实际返回值类型。
可选地,所述测试模块403具体用于根据所述关联关系,创建方法数据结构MethodDescripter结构,所述MethodDescripter结构包括:调用方法的实际返回值类型、MethodDescripter结构被调用的次数、调用方法的方法名、调用方法的所属类名、调用方法的传入参数;根据所述MethodDescripter结构,以及所述实际返回值类型,生成所述待测试代码所调用的方法对应的mock方法;通过所述mock方法,得到针对所述待测试代码的测试结果。
可选地,所述确定模块402具体用于,通过对所述待测试代码对应的字节码的分析,确定从所述待测试代码所调用的方法中确定出方法类型为强制类型转换的方法,作为目标方法;在对所述待测试代码进行测试时,根据所述目标方法,确定出在所述待测试代码所调用的方法对应的实际返回值类型。
可选地,所述装置还包括:分析模块404,用于将所述目标方法在所述待测试代码中对应的代码行号,与所述目标方法的返回值经强制类型转换后的实际返回值类型的对应关系进行保存;所述确定模块402具体用于,若在所述待测试代码的测试过程中,确 定所述待测试代码所调用的方法为强制类型转换的方法的代码行号,作为目标行号;根据所述目标行号,从预先保存的对应关系中查询出所述待测试代码所调用的方法对应的实际返回值类型。
可选地,所述测试模块403具体用于,根据从预先保存的对应关系中查询出所述待测试代码所调用的方法对应的实际返回值类型,生成所述待测试代码所调用的方法对应的mock方法;通过所述mock方法,得到针对所述待测试代码的测试结果。
图5为本说明书提供的一种测试用例生成的装置的示意图,包括:用例获取模块501,用于获取各测试用例;用例测试模块502,用于针对每个测试用例,通过上述代码测试的方法,对设定代码进行测试,得到该测试用例对应的测试结果;判断模块503,用于根据每个测试用例对应的测试结果,确定是否满足预设的测试条件;生成模块504,用于在确定不满足所述测试条件时,重新生成各测试用例,并根据重新生成的各测试用例,对所述设定代码进行测试,直到满足所述测试条件为止,得到满足所述测试条件时生成的测试用例。
可选地,所述生成模块504具体用于,从各测试用例中选取至少部分测试用例进行两两组合,得到各测试用例组合;针对每个测试用例组合,将该测试用例组合中包含的两个测试用例内的同类型参数进行加权,得到重新生成的测试用例。
可选地,所述生成模块504具体用于,从各测试用例中选取至少部分测试用例;针对选取出的每个测试用例,将该测试用例中包含的至少部分参数进行数值调整,和/或将该测试用例中包含的待测试代码进行调整,得到重新生成的测试用例。
本说明书还提供了一种计算机可读存储介质,该存储介质存储有计算机程序,计算机程序可用于执行上述图1提供的一种代码测试、测试用例生成的方法。
本说明书还提供了图6所示的一种对应于图1的电子设备的示意结构图。如图6所述,在硬件层面,该电子设备包括处理器、内部总线、网络接口、内存以及非易失性存储器,当然还可能包括其他业务所需要的硬件。处理器从非易失性存储器中读取对应的计算机程序到内存中然后运行,以实现上述图1所述的代码测试、测试用例生成的方法。当然,除了软件实现方式之外,本说明书并不排除其他实现方式,比如逻辑器件抑或软硬件结合的方式等等,也就是说以下处理流程的执行主体并不限定于各个逻辑单元,也可以是硬件或逻辑器件。
在20世纪90年代,对于一个技术的改进可以很明显地区分是硬件上的改进(例如, 对二极管、晶体管、开关等电路结构的改进)还是软件上的改进(对于方法流程的改进)。然而,随着技术的发展,当今的很多方法流程的改进已经可以视为硬件电路结构的直接改进。设计人员几乎都通过将改进的方法流程编程到硬件电路中来得到相应的硬件电路结构。因此,不能说一个方法流程的改进就不能用硬件实体模块来实现。例如,可编程逻辑器件(Programmable Logic Device,PLD)(例如现场可编程门阵列(Field Programmable Gate Array,FPGA))就是这样一种集成电路,其逻辑功能由用户对器件编程来确定。由设计人员自行编程来把一个数字系统“集成”在一片PLD上,而不需要请芯片制造厂商来设计和制作专用的集成电路芯片。而且,如今,取代手工地制作集成电路芯片,这种编程也多半改用“逻辑编译器(logic compiler)”软件来实现,它与程序开发撰写时所用的软件编译器相类似,而要编译之前的原始代码也得用特定的编程语言来撰写,此称之为硬件描述语言(Hardware Description Language,HDL),而HDL也并非仅有一种,而是有许多种,如ABEL(Advanced Boolean Expression Language)、AHDL(Altera Hardware Description Language)、Confluence、CUPL(Cornell University Programming Language)、HDCal、JHDL(Java Hardware Description Language)、Lava、Lola、MyHDL、PALASM、RHDL(Ruby Hardware Description Language)等,目前最普遍使用的是VHDL(Very-High-Speed Integrated Circuit Hardware Description Language)与Verilog。本领域技术人员也应该清楚,只需要将方法流程用上述几种硬件描述语言稍作逻辑编程并编程到集成电路中,就可以很容易得到实现该逻辑方法流程的硬件电路。
控制器可以按任何适当的方式实现,例如,控制器可以采取例如微处理器或处理器以及存储可由该(微)处理器执行的计算机可读程序代码(例如软件或固件)的计算机可读介质、逻辑门、开关、专用集成电路(Application Specific Integrated Circuit,ASIC)、可编程逻辑控制器和嵌入微控制器的形式,控制器的例子包括但不限于以下微控制器:ARC 625D、Atmel AT91SAM、Microchip PIC18F26K20以及Silicone Labs C8051F320,存储器控制器还可以被实现为存储器的控制逻辑的一部分。本领域技术人员也知道,除了以纯计算机可读程序代码方式实现控制器以外,完全可以通过将方法步骤进行逻辑编程来使得控制器以逻辑门、开关、专用集成电路、可编程逻辑控制器和嵌入微控制器等的形式来实现相同功能。因此这种控制器可以被认为是一种硬件部件,而对其内包括的用于实现各种功能的装置也可以视为硬件部件内的结构。或者甚至,可以将用于实现各种功能的装置视为既可以是实现方法的软件模块又可以是硬件部件内的结构。
上述实施例阐明的系统、装置、模块或单元,具体可以由计算机芯片或实体实现,或者由具有某种功能的产品来实现。一种典型的实现设备为计算机。具体的,计算机例 如可以为个人计算机、膝上型计算机、蜂窝电话、相机电话、智能电话、个人数字助理、媒体播放器、导航设备、电子邮件设备、游戏控制台、平板计算机、可穿戴设备或者这些设备中的任何设备的组合。
为了描述的方便,描述以上装置时以功能分为各种单元分别描述。当然,在实施本说明书时可以把各单元的功能在同一个或多个软件和/或硬件中实现。
本领域内的技术人员应明白,本说明书的实施例可提供为方法、系统、或计算机程序产品。因此,本说明书可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本说明书可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。
本说明书是参照根据本说明书实施例的方法、设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。
这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。
这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。
在一个典型的配置中,计算设备包括一个或多个处理器(CPU)、输入/输出接口、网络接口和内存。
内存可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和/或非易失性内存等形式,如只读存储器(ROM)或闪存(flash RAM)。内存是计算机可读介 质的示例。
计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带,磁带磁磁盘存储或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括暂存电脑可读媒体(transitory media),如调制的数据信号和载波。
还需要说明的是,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、商品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、商品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、商品或者设备中还存在另外的相同要素。
本领域技术人员应明白,本说明书的实施例可提供为方法、系统或计算机程序产品。因此,本说明书可采用完全硬件实施例、完全软件实施例或结合软件和硬件方面的实施例的形式。而且,本说明书可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。
本说明书可以在由计算机执行的计算机可执行指令的一般上下文中描述,例如程序模块。一般地,程序模块包括执行特定任务或实现特定抽象数据类型的例程、程序、对象、组件、数据结构等等。也可以在分布式计算环境中实践本说明书,在这些分布式计算环境中,由通过通信网络而被连接的远程处理设备来执行任务。在分布式计算环境中,程序模块可以位于包括存储设备在内的本地和远程计算机存储介质中。
本说明书中的各个实施例均采用递进的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于系统实施例而言,由于其基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。
以上所述仅为本说明书的实施例而已,并不用于限制本说明书。对于本领域技术人员来说,本说明书可以有各种更改和变化。凡在本说明书的精神和原理之内所作的任何修改、等同替换、改进等,均应包含在本说明书的权利要求范围之内。

Claims (20)

  1. 一种代码测试的方法,包括:
    获取待测试代码;
    根据所述待测试代码所调用的方法所需参数的类型,和/或对所述待测试代码对应的字节码进行分析后得到的分析结果,确定在所述待测试代码测试时所调用的方法对应的实际返回值类型,所述待测试代码测试时所调用的方法的方法类型包括:泛型方法以及强制类型转换中的至少一种;
    根据所述实际返回值类型,得到针对所述待测试代码的测试结果。
  2. 如权利要求1所述的方法,根据所述待测试代码所调用的方法所需参数的类型,和/或对所述待测试代码对应的字节码进行分析后得到的分析结果,确定在所述待测试代码测试时所调用的方法对应的实际返回值类型,具体包括:
    获取所述待测试代码所调用的方法的代码;
    根据获取到的所述待测试代码所调用的方法的代码,确定在所述待测试代码测试时所调用的方法的实际返回值类型,与所述待测试代码所调用的方法所需参数类型的关联关系;
    根据所述关联关系,以及所述待测试代码所调用的方法所需参数的类型,确定在所述待测试代码测试时所调用的方法对应的实际返回值类型。
  3. 如权利要求2所述的方法,根据所述实际返回值类型,得到针对所述待测试代码的测试结果,具体包括:
    根据所述关联关系,创建方法数据结构MethodDescripter结构,所述MethodDescripter结构包括:调用方法的实际返回值类型、MethodDescripter结构被调用的次数、调用方法的方法名、调用方法的所属类名、调用方法的传入参数;
    根据所述MethodDescripter结构,以及所述实际返回值类型,生成所述待测试代码所调用的方法对应的mock方法;
    通过所述mock方法,得到针对所述待测试代码的测试结果。
  4. 如权利要求1所述的方法,根据所述待测试代码所调用的方法所需参数的类型,和/或对所述待测试代码对应的字节码进行分析后得到的分析结果,确定在所述待测试代码测试时所调用的方法对应的实际返回值类型,具体包括:
    通过对所述待测试代码对应的字节码的分析,确定从所述待测试代码所调用的方法中确定出方法类型为强制类型转换的方法,作为目标方法;
    在对所述待测试代码进行测试时,根据所述目标方法,确定出在所述待测试代码所 调用的方法对应的实际返回值类型。
  5. 如权利要求4所述的方法,在对所述待测试代码进行测试时,根据所述目标方法,确定出在所述待测试代码所调用的方法对应的实际返回值类型之前,所述方法还包括:
    将所述目标方法在所述待测试代码中对应的代码行号,与所述目标方法的返回值经强制类型转换后的实际返回值类型的对应关系进行保存;
    在对所述待测试代码进行测试时,根据所述目标方法,确定出在所述待测试代码所调用的方法对应的实际返回值类型,具体包括:
    在所述待测试代码的测试过程中,确定所述待测试代码所调用的方法为强制类型转换的方法的代码行号,作为目标行号;
    根据所述目标行号,从预先保存的对应关系中查询出所述待测试代码所调用的方法对应的实际返回值类型。
  6. 如权利要求5所述的方法,根据所述实际返回值类型,得到针对所述待测试代码的测试结果,具体包括:
    根据从预先保存的对应关系中查询出所述待测试代码所调用的方法对应的实际返回值类型,生成所述待测试代码所调用的方法对应的mock方法;
    通过所述mock方法,得到针对所述待测试代码的测试结果。
  7. 一种测试用例生成的方法,包括:
    获取各测试用例;
    针对每个测试用例,通过上述权利要求1~6任一项所述的方法,对设定代码进行测试,得到该测试用例对应的测试结果;
    根据每个测试用例对应的测试结果,确定是否满足预设的测试条件;
    若确定不满足所述测试条件,重新生成各测试用例,并根据重新生成的各测试用例,对所述设定代码进行测试,直到满足所述测试条件为止,得到满足所述测试条件时生成的测试用例。
  8. 如权利要求7所述的方法,重新生成各测试用例,具体包括:
    从各测试用例中选取至少部分测试用例进行两两组合,得到各测试用例组合;
    针对每个测试用例组合,将该测试用例组合中包含的两个测试用例内的同类型参数进行加权,得到重新生成的测试用例。
  9. 如权利要求7所述的方法,重新生成各测试用例,具体包括:
    从各测试用例中选取至少部分测试用例;
    针对选取出的每个测试用例,将该测试用例中包含的至少部分参数进行数值调整,和/或将该测试用例中包含的待测试代码进行调整,得到重新生成的测试用例。
  10. 一种代码测试的装置,包括:
    获取模块,用于获取待测试代码;
    确定模块,用于根据所述待测试代码所调用的方法所需参数的类型,和/或对所述待测试代码对应的字节码进行分析后得到的分析结果,确定在所述待测试代码测试时所调用的方法对应的实际返回值类型,所述待测试代码测试时所调用的方法的方法类型包括:泛型方法以及强制类型转换中的至少一种;
    测试模块,用于根据所述实际返回值类型,得到针对所述待测试代码的测试结果。
  11. 如权利要求10所述的装置,所述确定模块具体用于,获取所述待测试代码所调用的方法的代码;根据获取到的所述待测试代码所调用的方法的代码,确定所述在所述待测试代码测试时所调用的方法的实际返回值,与所述待测试代码所调用的方法所需参数类型的关联关系;根据所述关联关系,以及所述待测试代码所调用的方法所需参数的类型,确定在所述待测试代码测试时所调用的方法对应的实际返回值类型。
  12. 如权利要求11所述的装置,所述测试模块具体用于,根据所述关联关系,创建方法数据结构MethodDescripter结构,所述MethodDescripter结构包括:调用方法的实际返回值类型、MethodDescripter结构被调用的次数、调用方法的方法名、调用方法的所属类名、调用方法的传入参数;根据所述MethodDescripter结构,以及所述实际返回值类型,生成所述待测试代码所调用的方法对应的mock方法;通过所述mock方法,得到针对所述待测试代码的测试结果。
  13. 如权利要求10所述的装置,所述确定模块具体用于,通过对所述待测试代码对应的字节码的分析,确定从所述待测试代码所调用的方法中确定出方法类型为强制类型转换的方法,作为目标方法;在对所述待测试代码进行测试时,根据所述目标方法,确定出在所述待测试代码所调用的方法对应的实际返回值类型。
  14. 如权利要求13所述的装置,所述装置还包括:
    分析模块,用于将所述目标方法在所述待测试代码中对应的代码行号,与所述目标方法的返回值经强制类型转换后的实际返回值类型的对应关系进行保存;
    所述确定模块具体用于,在所述待测试代码的测试过程中,确定所述待测试代码所调用的方法为强制类型转换的方法的代码行号,作为目标行号;根据所述目标行号,从预先保存的对应关系中查询出所述待测试代码所调用的方法对应的实际返回值类型。
  15. 如权利要求14所述的装置,所述测试模块具体用于,根据从预先保存的对应 关系中查询出所述待测试代码所调用的方法对应的实际返回值类型,生成所述待测试代码所调用的方法对应的mock方法;通过所述mock方法,得到针对所述待测试代码的测试结果。
  16. 一种测试用例生成的装置,包括:
    用例获取模块,用于获取各测试用例;
    用例测试模块,用于针对每个测试用例,通过上述权利要求1~6任一项所述的方法,对设定代码进行测试,得到该测试用例对应的测试结果;
    判断模块,用于根据每个测试用例对应的测试结果,确定是否满足预设的测试条件;
    生成模块,用于在确定不满足所述测试条件时,重新生成各测试用例,并根据重新生成的各测试用例,对所述设定代码进行测试,直到满足所述测试条件为止,得到满足所述测试条件时生成的测试用例。
  17. 如权利要求16所述的装置,所述生成模块具体用于,从各测试用例中选取至少部分测试用例进行两两组合,得到各测试用例组合;针对每个测试用例组合,将该测试用例组合中包含的两个测试用例内的同类型参数进行加权,得到重新生成的测试用例。
  18. 如权利要求16所述的装置,所述生成模块具体用于,从各测试用例中选取至少部分测试用例;针对选取出的每个测试用例,将该测试用例中包含的至少部分参数进行数值调整,和/或将该测试用例中包含的待测试代码进行调整,得到重新生成的测试用例。
  19. 一种计算机可读存储介质,所述存储介质存储有计算机程序,所述计算机程序被处理器执行时实现上述权利要求1~9任一项所述的方法。
  20. 一种电子设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,所述处理器执行所述程序时实现上述权利要求1~9任一项所述的方法。
PCT/CN2023/092939 2022-05-10 2023-05-09 一种代码测试、测试用例生成的方法及装置 Ceased WO2023217118A1 (zh)

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)

* Cited by examiner, † Cited by third party
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)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114840427B (zh) * 2022-05-10 2025-09-19 支付宝(杭州)信息技术有限公司 一种代码测试、测试用例生成的方法及装置

Citations (4)

* Cited by examiner, † Cited by third party
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)

* Cited by examiner, † Cited by third party
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点自动识别方法、装置以及设备

Patent Citations (4)

* Cited by examiner, † Cited by third party
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)

* Cited by examiner, † Cited by third party
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