Test case generation method and device, medium and equipment

By obtaining the control flow structure of complex language programs to generate initial test code, the problem of difficulty in analyzing and traversing complex language programs is solved, and the code coverage guarantee and testing efficiency are improved.

CN119166489APending Publication Date: 2024-12-20WUHAN UNIV +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310740523.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-06-20
Publication Date
2024-12-20

AI Technical Summary

Technical Problem

When facing programming languages ​​with high complexity, it is difficult for the existing technology to directly analyze and generate test cases that meet code coverage, resulting in difficult to ensure testing efficiency and quality.

Method used

By obtaining the control flow structure of the tested program, generating the initial test code, and obtaining the encoding results through encoding, and then generating the target test cases, avoiding the direct processing of complex tested programs, thereby solving the problem that complex language programs are difficult to analyze and traverse.

Benefits of technology

It realizes the generation of target test cases in complex language environments, ensures code coverage, and improves test efficiency and quality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119166489A_ABST
    Figure CN119166489A_ABST
Patent Text Reader

Abstract

The invention provides a test case generation method, a test case generation device, a computer readable storage medium and electronic equipment, and relates to the technical field of software testing, and the method can obtain a control flow structure which corresponds to a tested program and is used for representing program grammar, and generate an initial test code according to the control flow structure; by encoding the initial test code, the encoding result can be obtained, the tested program with high complexity does not need to be directly processed, then the target test case can be generated according to the encoding result, the problem that it is difficult to directly analyze and traverse programs with complex languages is solved, and the code coverage rate can be guaranteed when the target test case is applied to the test process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of software testing technology, and in particular to a test case generation method, a test case generation device, a computer-readable storage medium, and an electronic device. Background Art

[0002] Code coverage is a method to indirectly measure software quality by calculating the proportion of source code executed during the test to the total source code. It can potentially ensure the quality of the actual product while ensuring the quality of the test. Based on this, you can find parts in the program that have not been tested by test cases and further create new test cases to increase coverage.

[0003] When conducting software testing, it is usually necessary to generate test cases, prepare test data, run the program with test data, and compare the results with the test cases. Testing the program with test cases can identify problems in the program and correct them in a timely manner.

[0004] Generally speaking, the test case acquisition methods include: random generation, optimal search in the problem space, etc. However, there are differences between programs, such as programming language differences. When facing languages ​​with lower complexity, applying relevant technologies to obtain test cases for software testing can meet the required code coverage. However, when facing languages ​​with higher complexity, relevant technologies are difficult to meet the required code coverage.

[0005] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present application, and therefore may include information that does not constitute relevant technology known to ordinary technicians in the field. Summary of the invention

[0006] The purpose of the present application is to provide a test case generation method, a test case generation device, a computer-readable storage medium and an electronic device. When faced with a language with higher complexity (such as Kotlin language), the control flow structure corresponding to the tested program for characterizing the program syntax can be obtained, and the initial test code can be generated according to the control flow structure. By encoding the initial test code, the encoding result can be obtained without directly processing the tested program with higher complexity. Furthermore, a target test case can be generated according to the encoding result, which solves the problem that programs in complex languages ​​are difficult to directly analyze and traverse. The target test case can ensure code coverage when applied to the test process.

[0007] Other features and advantages of the present application will become apparent from the following detailed description, or may be learned in part by the practice of the present application.

[0008] According to one aspect of the present application, a test case generation method is provided, the method comprising:

[0009] Obtaining the control flow structure corresponding to the tested program for characterizing the program syntax;

[0010] Generate initial test code based on control flow structure;

[0011] Encode the initial test code to obtain the encoding result;

[0012] Generate target test cases based on the encoding results.

[0013] According to one aspect of the present application, a test case generating device is provided, the device comprising:

[0014] A control flow structure acquisition unit, used to acquire a control flow structure corresponding to the tested program and used to characterize the program syntax;

[0015] An initial test code generation unit, used for generating initial test code according to a control flow structure;

[0016] An encoding unit, used for encoding the initial test code to obtain an encoding result;

[0017] The target test case generating unit is used to generate the target test case according to the encoding result.

[0018] According to one aspect of the present application, a computer program product or a computer program is provided, the computer program product or the computer program comprising computer instructions, the computer instructions being stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the methods provided in the above-mentioned various optional implementations.

[0019] According to one aspect of the present application, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, any one of the above methods is implemented.

[0020] According to one aspect of the present application, an electronic device is provided, comprising: a processor; and a memory for storing executable instructions of the processor; wherein the processor is configured to perform any one of the above methods by executing the executable instructions.

[0021] The exemplary embodiments of the present application may have some or all of the following beneficial effects:

[0022] In the test case generation method provided in an example embodiment of the present application, when faced with a language with higher complexity (such as the Kotlin language), the control flow structure corresponding to the program under test for characterizing the program syntax can be obtained, and the initial test code can be generated based on the control flow structure. By encoding the initial test code, the encoding result can be obtained without directly processing the program under test with higher complexity. Furthermore, the target test case can be generated based on the encoding result, which solves the problem that programs in complex languages ​​are difficult to directly analyze and traverse. The target test case can ensure code coverage when applied to the testing process.

[0023] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] The drawings herein are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the present application, and together with the specification are used to explain the principles of the present application. Obviously, the drawings described below are only some embodiments of the present application, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0025] Figure 1 A flowchart of a test case generation method according to an embodiment of the present application is schematically shown;

[0026] Figure 2 A schematic diagram of a system architecture for implementing a test case generation method according to an embodiment of the present application is shown;

[0027] Figure 3 A flowchart of a test case generation method according to another embodiment of the present application is schematically shown;

[0028] Figure 4 A schematic diagram of the structure of a test case generating device according to an embodiment of the present application is shown;

[0029] Figure 5 The structure diagram of a computer system suitable for implementing an electronic device of an embodiment of the present application is schematically shown. DETAILED DESCRIPTION

[0030] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as being limited to the examples set forth herein; on the contrary, these embodiments are provided so that the present application will be more comprehensive and complete, and the concept of the example embodiments will be fully conveyed to those skilled in the art. The described features, structures, or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present application. However, those skilled in the art will appreciate that the technical solutions of the present application may be practiced while omitting one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known technical solutions are not shown or described in detail to avoid obscuring various aspects of the present application.

[0031] See also Figure 1 , Figure 1 The following schematically shows a flow chart of a test case generation method according to an embodiment of the present application. Figure 1 As shown, the method includes the following steps.

[0032] Step S110: Obtain a control flow structure corresponding to the program under test and used to characterize the program syntax.

[0033] Step S120: Generate initial test code according to the control flow structure.

[0034] Step S130: Encode the initial test code to obtain an encoding result.

[0035] Step S140: Generate a target test case according to the encoding result.

[0036] Implementation Figure 1 The method shown, when facing a language with higher complexity (such as Kotlin language), can obtain the control flow structure corresponding to the tested program for characterizing the program syntax, and generate initial test code based on the control flow structure. By encoding the initial test code, the encoding result can be obtained without directly processing the more complex tested program. Furthermore, the target test case can be generated based on the encoding result, which solves the problem that programs in complex languages ​​are difficult to directly analyze and traverse. The target test case can ensure code coverage when applied to the testing process.

[0037] Next, the above steps of this exemplary embodiment are described in more detail.

[0038] In step S110, a control flow structure corresponding to the tested program and used to characterize the program syntax is obtained.

[0039] Specifically, when it is necessary to test the program under test, in order to improve the code coverage and improve the test effect, it is necessary to generate targeted test code. Based on this demand, the present application can first obtain the control flow structure corresponding to the program under test for characterizing the program syntax, wherein the program under test can be written in a language with higher complexity or in a language with lower complexity. When applied to a language scenario with higher complexity, the test code encoding of the present application for the program under test can avoid the problem of difficulty in test analysis caused by high language complexity, and for scenarios with low language complexity, effective test code can be generated more efficiently. In addition, control flow refers to the execution process of controlling the program under test, and the control flow structure can include a sequential structure, a loop structure, a branch structure, etc., which are not limited in the embodiments of the present application.

[0040] As an optional embodiment, obtaining the control flow structure corresponding to the program under test includes: converting the source code of the program under test into a bytecode file; extracting the syntax structure in the bytecode file; and parsing the syntax structure into the control flow structure. In this way, the source code can be converted into a unified bytecode file, which is conducive to improving the parsing efficiency of the syntax structure.

[0041] Specifically, the source code of the program under test can be Java code, Kotlin code, bytecode Class file, etc., which is not limited in the embodiments of the present application. Wherein. Kotlin is a modern programming language that can be used to develop various applications, such as Android applications and server-side applications. In addition, the grammatical structure is an abstract expression of a programming language under a specific grammar, and different methods / functions have different grammatical structures. In order to improve the intuitiveness of the method / function for the source code, the grammatical structure can be parsed into a control flow structure. The parsing for Kotlin can be implemented using the PSI (Program Structure Interface) interface or other similar types of application programming interfaces (Application Programming Interface, API), wherein the API is a set of definitions, programs and protocols, and mutual communication between computer software can be achieved based on the API interface. In a project managed by an integrated development environment (IDE, Integrated Development Environment), each directory, source code and resource file will be abstracted into a corresponding PSI object, wherein the IDE is an application for providing a program development environment, generally including tools such as a code editor, a compiler, a debugger and a graphical user interface.

[0042] As an optional embodiment, the method further includes: inserting a stub to the bytecode file to dynamically analyze, test and debug the bytecode file. In this way, automatic control of the bytecode file can be achieved through inserting a stub, saving labor costs, and obtaining code coverage.

[0043] Specifically, instrumentation refers to the use of automated tools or frameworks to implement the instrumentation process instead of manually editing bytecode files, so that applications can be dynamically analyzed, tested, and debugged without manually modifying the code. By using automated instrumentation technology, developers can collect code execution information, track method calls, measure code coverage, or detect potential errors and performance issues at runtime.

[0044] In step S120, initial test code is generated according to the control flow structure.

[0045] Specifically, the initial test code can be used as a reference for generating the final test code.

[0046] As an optional embodiment, generating initial test code according to the control flow structure includes: parsing the program dependency of the program under test; wherein the program dependency includes at least one of the following: inter-class dependency, inter-method dependency, and third-party library dependency; generating initial test code according to the program dependency and the control flow structure. In this way, initial test code generation based on program dependency and control flow structure can be achieved, and the coverage rate of the initial test code can be improved.

[0047] Specifically, inter-class dependency refers to the dependency between classes. A class is an abstract concept of an object, and an object is an instance created by a class. Inter-method dependency refers to the dependency between functions. Third-party library dependency refers to the dependency with a third-party database.

[0048] In step S130, the initial test code is encoded to obtain an encoding result.

[0049] Specifically, the method of encoding the initial test code may rely on an encoding method such as ASCII encoding, which is not limited in the embodiment of the present application.

[0050] In step S140, a target test case is generated according to the encoding result.

[0051] As an optional embodiment, generating a target test case according to the encoding result includes: generating the encoding result into a program sequence based on a heuristic optimization algorithm; generating a test case population based on the program sequence; evolving the test case population to obtain a target test case. In this way, the target test case can be obtained through an automated evolution process, saving the test case writing cost and improving the test case acquisition efficiency.

[0052] Specifically, a heuristic optimization algorithm is proposed relative to an optimization algorithm, and is used to obtain the optimal solution for each instance of a problem through an optimal algorithm for the problem, such as an ant colony algorithm, a simulated annealing method, a neural network, etc. Based on the heuristic optimization algorithm, the encoding result can be generated as a program sequence, and the program sequence can also be understood as a test code segment. Among them, for the fitness function in the heuristic optimization algorithm, it can be a quantization function of a preset coverage criterion and a specific diversity quantization function, etc., which is not limited in the embodiments of the present application. Furthermore, based on the program sequence and the encoding result, a test case population can be generated, and a plurality of test cases are included in the test case population to implement testing of different functions of the program under test.

[0053] As an optional embodiment, evolving the test case population to obtain the target test case includes: constructing a genetic algorithm model according to the test case population; evolving the test case population based on the fitness function in the genetic algorithm model until no new test case can be formed to obtain the target test case. In this way, the test case evolution process can be implemented based on the genetic algorithm model, which can improve the effectiveness and code coverage of the target test case.

[0054] Specifically, a personalized genetic algorithm model can be constructed based on the test case population to evolve the test case population based on the fitness function therein to achieve the screening of use cases. Specifically, the use cases corresponding to functions that are difficult to cover can be screened out until the iterative evolution reaches the point where no new test code segments can be formed. The final evolution result is the target test case.

[0055] As an optional embodiment, the method further includes: encoding the target test case to obtain an encoding result; constructing an index relationship between the control flow structure and the encoding result; and storing the index relationship in a test reuse database. In this way, by storing the index relationship between the control flow structure and the encoding result, it is convenient to call the required target test case at any time according to the index relationship, so as to realize the reuse of the test case, save test case generation resources, and improve the subsequent test efficiency.

[0056] Specifically, encoding the target test case can obtain a more concise encoding result, and storing the index relationship between the control flow structure and the encoding result can save storage costs.

[0057] In addition, optionally, an index relationship between the control flow structure and the encoding result is constructed, including: generalizing the variables in the program under test to avoid the problem of incorrect index results caused by different variable names, and then extracting the control flow structure therefrom, using the control flow structure as the key and the encoding result as the value, and then performing key-value (KV) storage.

[0058] As an optional embodiment, it also includes: formatting the target test case to obtain test code corresponding to the specified coding language; executing the test code to obtain the test result. In this way, the target test case can be converted into the specified coding language, improving the readability of the test code.

[0059] Specifically, the designated coding language may be the coding language corresponding to the tested program, and the designated coding language may be easy for relevant personnel to read, thereby improving the readability of the code. In addition, if the test result fails to achieve the preset effect, the test code is output for relevant personnel to debug.

[0060] See also Figure 2 , Figure 2 The following schematically shows a system architecture diagram for implementing a test case generation method according to an embodiment of the present application. Figure 2 As shown, the system architecture includes: system platform 210, Java code 221, Kotlin code 222, Class file 223, front-end code analysis module 230, test code generation module 240, and test case evaluation module 250. The front-end code analysis module 230 includes: tested code syntax analysis submodule 231, program dependency analysis submodule 232. The test code generation module 240 includes: unit test code heuristic generation submodule 241, test code evolution generation submodule 242 for coverage, and historical test case reuse submodule 243. The test case evaluation module 250 includes: test case evaluation submodule 251, test case generation submodule 252.

[0061] Among them, the system platform 210 can input the tested program based on Java code 221, Kotlin code 222 or Class file 223 into the front-end code analysis module 230.

[0062] The tested code syntax analysis submodule 231 is used to convert the source code of the tested program into a bytecode file, extract the syntax structure in the bytecode file, and then parse the syntax structure into a control flow structure.

[0063] The program dependency analysis submodule 232 is used to analyze the program dependency of the program under test; wherein the program dependency includes at least one of the following: inter-class dependency, inter-method dependency, and third-party library dependency.

[0064] Furthermore, the front-end code analysis module 230 can also generate initial test code based on program dependencies and control flow structure, and encode the initial test code to obtain the encoding result as an intermediate representation module (IR) input into the test code generation module 240, and the intermediate representation module (IR) includes a control flow structure and program dependencies.

[0065] The unit test code heuristic generation submodule 241 is used to generate the encoding result into a program sequence based on a heuristic optimization algorithm, and generate a test case population based on the program sequence.

[0066] The test code evolution generation submodule 242 for coverage is used to construct a genetic algorithm model according to the test case population, and evolve the test case population based on the fitness function in the genetic algorithm model until no new test case can be formed, so as to obtain a target test case.

[0067] The historical test case reuse submodule 243 is used to encode the target test case, obtain the encoding result, construct the index relationship between the control flow structure and the encoding result, and store the index relationship in the test reuse database.

[0068] The test case evaluation submodule 251 is used to evaluate the code coverage of the target test case.

[0069] The test case generation submodule 252 is used to format the target test case to obtain the test code corresponding to the specified coding language.

[0070] It can be seen that the implementation Figure 2 The system structure shown in the figure can obtain the control flow structure corresponding to the tested program for characterizing the program syntax when facing a language with higher complexity (such as Kotlin language), and generate initial test code based on the control flow structure. By encoding the initial test code, the encoding result can be obtained without directly processing the tested program with higher complexity. Furthermore, the target test case can be generated according to the encoding result, which solves the problem that programs in complex languages ​​are difficult to directly analyze and traverse. The target test case can ensure code coverage when applied to the testing process.

[0071] See also Figure 3 , Figure 3 The flowchart of the test case generation method according to another embodiment of the present application is schematically shown. Figure 3 As shown, the test case generation method may include: steps S300 to S380.

[0072] Step S300: converting the source code of the program under test into a bytecode file, extracting the grammatical structure in the bytecode file, and then parsing the grammatical structure into a control flow structure.

[0073] Step S310: Performing instrumentation processing on the bytecode file to dynamically analyze, test and debug the bytecode file.

[0074] Step S320: parsing the program dependency of the program under test; wherein the program dependency includes at least one of the following: inter-class dependency, inter-method dependency, and third-party library dependency.

[0075] Step S330: Generate initial test code according to program dependency and control flow structure.

[0076] Step S340: Encode the initial test code to obtain an encoding result.

[0077] Step S350: Generate the encoding result into a program sequence based on the heuristic optimization algorithm, and generate a test case population based on the program sequence.

[0078] Step S360: construct a genetic algorithm model according to the test case population, and evolve the test case population based on the fitness function in the genetic algorithm model until no new test case can be formed, so as to obtain a target test case.

[0079] Step S370: Encode the target test case to obtain an encoding result, construct an index relationship between the control flow structure and the encoding result, and store the index relationship in a test reuse database.

[0080] Step S380: Format the target test case to obtain test code corresponding to the specified coding language, and execute the test code to obtain the test result.

[0081] It should be noted that steps S300 to S380 are Figure 1 The steps and their embodiments shown correspond to each other. For the specific implementation of steps S300 to S380, please refer to Figure 1 The steps and embodiments shown are not described in detail here.

[0082] It can be seen that the implementation Figure 3 The method shown, when facing a language with higher complexity (such as Kotlin language), can obtain the control flow structure corresponding to the tested program for characterizing the program syntax, and generate initial test code based on the control flow structure. By encoding the initial test code, the encoding result can be obtained without directly processing the more complex tested program. Furthermore, the target test case can be generated based on the encoding result, which solves the problem that programs in complex languages ​​are difficult to directly analyze and traverse. The target test case can ensure code coverage when applied to the testing process.

[0083] See also Figure 4 , Figure 4 The structure block diagram of the test case generation device according to one embodiment of the present application is schematically shown. Figure 4 As shown, the test case generating device 400 may include the following units.

[0084] A control flow structure acquisition unit 401 is used to acquire a control flow structure corresponding to the program under test and used to characterize the program syntax;

[0085] An initial test code generating unit 402, used to generate initial test code according to the control flow structure;

[0086] The encoding unit 403 is used to encode the initial test code to obtain an encoding result;

[0087] The target test case generating unit 404 is used to generate a target test case according to the encoding result.

[0088] It can be seen that the implementation Figure 4 The device shown, when faced with a language with higher complexity (such as Kotlin language), can obtain the control flow structure corresponding to the tested program for characterizing the program syntax, and generate initial test code based on the control flow structure. By encoding the initial test code, the encoding result can be obtained without directly processing the tested program with higher complexity. Furthermore, the target test case can be generated based on the encoding result, which solves the problem that programs in complex languages ​​are difficult to directly analyze and traverse. The target test case can ensure code coverage when applied to the testing process.

[0089] As an optional embodiment, the control flow structure acquisition unit 401 acquires the control flow structure corresponding to the program under test, including:

[0090] Convert the source code of the program under test into a bytecode file;

[0091] Extract the syntax structure in the bytecode file;

[0092] Parse grammatical structures into control flow structures.

[0093] It can be seen that by implementing this optional embodiment, the source code can be converted into a unified bytecode file, which is beneficial to improving the parsing efficiency of the grammatical structure.

[0094] As an optional embodiment, it also includes:

[0095] The instrumentation unit is used to perform instrumentation processing on the bytecode file to dynamically analyze, test and debug the bytecode file.

[0096] It can be seen that by implementing this optional embodiment, automatic control of bytecode files can be achieved through plugging, which saves labor costs and can obtain code coverage.

[0097] As an optional embodiment, the initial test code generating unit 402 generates the initial test code according to the control flow structure, including:

[0098] Analyze the program dependencies of the program under test; wherein the program dependencies include at least one of the following: inter-class dependency, inter-method dependency, and third-party library dependency;

[0099] Generate initial test code based on program dependencies and control flow structure.

[0100] It can be seen that by implementing this optional embodiment, initial test code generation based on program dependencies and control flow structures can be achieved, and the coverage of the initial test code can be improved.

[0101] As an optional embodiment, the target test case generating unit 404 generates a target test case according to the encoding result, including:

[0102] Generate the encoding result into a program sequence based on a heuristic optimization algorithm;

[0103] Generate a population of test cases based on program sequences;

[0104] Evolve the test case population to obtain the target test case.

[0105] It can be seen that by implementing this optional embodiment, the target test case can be obtained through an automated evolution process, thereby saving the cost of writing the test case and improving the efficiency of obtaining the test case.

[0106] As an optional embodiment, the target test case generation unit 404 evolves the test case population to obtain the target test case, including:

[0107] Construct a genetic algorithm model based on the test case population;

[0108] The test case population is evolved based on the fitness function in the genetic algorithm model until no new test cases can be formed to obtain the target test cases.

[0109] It can be seen that by implementing this optional embodiment, the test case evolution process can be realized based on the genetic algorithm model, which can improve the effectiveness and code coverage of the target test cases.

[0110] As an optional embodiment, it also includes:

[0111] The encoding unit 403 is further used to encode the target test case to obtain an encoding result;

[0112] An index construction unit, used to construct an index relationship between a control flow structure and an encoding result;

[0113] The storage unit is used to store the index relationship in the test reuse database.

[0114] It can be seen that by implementing this optional embodiment, the index relationship between the control flow structure and the encoding result can be stored, so that the required target test cases can be called at any time according to the index relationship, so as to realize the reuse of test cases, save test case generation resources, and improve subsequent testing efficiency.

[0115] As an optional embodiment, it also includes:

[0116] A formatting unit, used to format the target test case to obtain a test code corresponding to a specified coding language;

[0117] The test execution unit is used to execute the test code and obtain the test results.

[0118] It can be seen that by implementing this optional embodiment, the target test case can be converted into a specified coding language, thereby improving the readability of the test code.

[0119] It should be noted that, although several modules or units of the equipment for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present application, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into being embodied by multiple modules or units.

[0120] Since the various functional modules of the test case generation device of the example embodiment of the present application correspond to the steps of the example embodiment of the test case generation device described above, for details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the test case generation device described above in the present application.

[0121] See also Figure 5 , Figure 5 A schematic diagram of the structure of a computer system suitable for implementing an electronic device of an embodiment of the present application is shown.

[0122] It should be noted that Figure 5 The computer system 500 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0123] like Figure 5 As shown, the computer system 500 includes a central processing unit (CPU) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage part 508 into a random access memory (RAM) 503. Various programs and data required for system operation are also stored in the RAM 503. The CPU 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.

[0124] The following components are connected to the I / O interface 505: an input section 506 including a keyboard, a mouse, etc.; an output section 507 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 508 including a hard disk, etc.; and a communication section 509 including a network interface card such as a LAN card, a modem, etc. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the I / O interface 505 as needed. A removable medium 511, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 510 as needed, so that a computer program read therefrom is installed into the storage section 508 as needed.

[0125] In particular, according to an embodiment of the present application, the process described below with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication section 509, and / or installed from a removable medium 511. When the computer program is executed by a central processing unit (CPU) 501, various functions defined in the method and apparatus of the present application are executed.

[0126] As another aspect, the present application also provides a computer-readable medium, which may be included in the electronic device described in the above embodiment; or may exist independently without being assembled into the electronic device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by an electronic device, the electronic device implements the method in the above embodiment.

[0127] It should be noted that the computer-readable medium shown in the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0128] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the above-mentioned module, program segment or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0129] The units involved in the embodiments described in this application may be implemented by software or hardware, and the units described may also be set in a processor. The names of these units do not, in some cases, constitute limitations on the units themselves.

[0130] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary technical means in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the claims.

Claims

1. A test case generation method, characterized in that: include: Obtaining the control flow structure corresponding to the tested program for characterizing the program syntax; Generate initial test code according to the control flow structure; Encoding the initial test code to obtain an encoding result; Generate a target test case according to the encoding result.

2. The method according to claim 1, characterized in that Get the control flow structure corresponding to the program under test, including: Convert the source code of the program under test into a bytecode file; Extracting the grammatical structure in the bytecode file; The grammatical structure is parsed into a control flow structure.

3. The method according to claim 2, characterized in that Also includes: The bytecode file is instrumented to dynamically analyze, test and debug the bytecode file.

4. The method according to claim 1, characterized in that: Generate initial test code according to the control flow structure, including: Parsing the program dependency of the program under test; wherein the program dependency includes at least one of the following: inter-class dependency, inter-method dependency, and third-party library dependency; Initial test code is generated according to the program dependency and the control flow structure.

5. The method according to claim 1, characterized in that Generating a target test case according to the encoding result includes: Generating the encoding result into a program sequence based on a heuristic optimization algorithm; generating a population of test cases based on the program sequence; Evolving the test case population to obtain target test cases.

6. The method according to claim 5, characterized in that Evolving the test case population to obtain a target test case includes: constructing a genetic algorithm model according to the test case population; The test case population is evolved based on the fitness function in the genetic algorithm model until no new test cases can be formed, so as to obtain target test cases.

7. The method according to claim 1, characterized in that Also includes: Encoding the target test case to obtain an encoding result; Constructing an index relationship between the control flow structure and the encoding result; The index relationship is stored in a test reuse database.

8. The method according to claim 1, characterized in that Also includes: Formatting the target test case to obtain a test code corresponding to a specified coding language; Execute the test code to obtain the test result.

9. A test case generating device, characterized in that: include: A control flow structure acquisition unit, used to acquire a control flow structure corresponding to the tested program and used to characterize the program syntax; An initial test code generating unit, used for generating an initial test code according to the control flow structure; An encoding unit, used for encoding the initial test code to obtain an encoding result; A target test case generating unit is used to generate a target test case according to the encoding result.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.

11. An electronic device, characterized in that: include: processor; as well as A memory, configured to store executable instructions of the processor; The processor is configured to perform the method of any one of claims 1-8 by executing the executable instructions.