Movatterモバイル変換


[0]ホーム

URL:


CN114168466A - A unit testing method, device, system and storage medium - Google Patents

A unit testing method, device, system and storage medium
Download PDF

Info

Publication number
CN114168466A
CN114168466ACN202111482479.3ACN202111482479ACN114168466ACN 114168466 ACN114168466 ACN 114168466ACN 202111482479 ACN202111482479 ACN 202111482479ACN 114168466 ACN114168466 ACN 114168466A
Authority
CN
China
Prior art keywords
type
test
source code
class file
parameter list
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.)
Granted
Application number
CN202111482479.3A
Other languages
Chinese (zh)
Other versions
CN114168466B (en
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.)
China Construction Bank Corp
Original Assignee
China Construction Bank Corp
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 China Construction Bank CorpfiledCriticalChina Construction Bank Corp
Priority to CN202111482479.3ApriorityCriticalpatent/CN114168466B/en
Publication of CN114168466ApublicationCriticalpatent/CN114168466A/en
Application grantedgrantedCritical
Publication of CN114168466BpublicationCriticalpatent/CN114168466B/en
Activelegal-statusCriticalCurrent
Anticipated expirationlegal-statusCritical

Links

Images

Classifications

Landscapes

Abstract

Translated fromChinese

本申请提供一种单元测试方法、装置、系统及存储介质。该方法包括:对待测试的源代码进行基于字节码的代码解析处理,确定所述源代码对应的类文件以及所述类文件对应的执行指令,根据所述类文件的文件名和所述执行指令,构建所述源代码的至少一个测试线程,根据所述源代码中的类文件为每个测试线程创建实例化对象和相应的参数列表;根据所述实例化对象和相应的参数列表在所述源代码上执行各测试线程,得到测试结果。本申请的方法,提高了单元测试的效率。

Figure 202111482479

The present application provides a unit testing method, device, system and storage medium. The method includes: performing bytecode-based code parsing processing on the source code to be tested, determining a class file corresponding to the source code and an execution instruction corresponding to the class file, according to the file name of the class file and the execution instruction , construct at least one test thread of the source code, create an instantiated object and a corresponding parameter list for each test thread according to the class file in the source code; according to the instantiated object and the corresponding parameter list in the Execute each test thread on the source code to get the test result. The method of the present application improves the efficiency of unit testing.

Figure 202111482479

Description

Unit testing method, device, system and storage medium
Technical Field
The present application relates to the field of software program testing technologies, and in particular, to a unit testing method, apparatus, system, and storage medium.
Background
With the development of computer technology and the popularization of informatization, the dependence of people on computer technology is increasingly enhanced in aspects of life. In order to meet the requirements of users, the updating iteration speed of application software is faster and faster, and unit testing in software development becomes an important link.
In the prior art, unit testing usually involves manually writing a test case corresponding to a functional module for a certain module in a software development process, and evaluating the development effect of the module according to the test case result.
However, in the prior art, the software developed by testing is tested by manually compiling the corresponding test case, so that the testing efficiency is reduced, and a large amount of manpower is wasted.
Disclosure of Invention
The application provides a unit testing method, a device, a system and a storage medium, which are used for solving the problem of low efficiency of manual testing software.
In one aspect, the present application provides a unit testing method, including:
acquiring original log data of a terminal in a data source;
performing code analysis processing based on byte codes on a source code to be tested, and determining a class file corresponding to the source code and an execution instruction corresponding to the class file;
constructing at least one test thread of the source code according to the file name of the class file and the execution instruction;
creating an instantiation object and a corresponding parameter list for each test thread according to the class file in the source code;
and executing each test thread on the source code according to the instantiation object and the corresponding parameter list to obtain a test result.
In yet another aspect, the present application provides a unit testing apparatus comprising:
the analysis module is used for carrying out byte code-based code analysis processing on a source code to be tested and determining a class file corresponding to the source code and an execution instruction corresponding to the class file;
the construction module is used for constructing at least one test thread of the source code according to the file name of the class file and the execution instruction;
the creating module is used for creating an instantiation object and a corresponding parameter list for each testing thread according to the class file in the source code;
and the testing module is used for executing each testing thread on the source code according to the instantiation object and the corresponding parameter list to obtain a testing result.
In yet another aspect, the present application provides a unit testing system comprising: the unit testing device and a source code to be tested;
the unit testing device is used for testing a source code to be tested, testing the source code to be tested according to the unit testing method as claimed in any one of the preceding claims, and storing a testing result in a disk.
In yet another aspect, the present application provides an electronic device comprising:
a processor, and a memory communicatively coupled to the processor;
the memory stores computer-executable instructions;
the processor executes computer-executable instructions stored by the memory to implement the method of any of the preceding claims.
In still another aspect, the present application provides a computer-readable storage medium, including computer executable instructions stored therein, which when executed by a processor, are used to implement the configuration method of the optical transmission ring network according to any one of the preceding claims.
In a final aspect, the application provides a computer program product comprising a computer program which, when executed by a processor, performs the method as in any of the previous claims.
The application provides a unit testing method, a device, a system and a storage medium. The method comprises the following steps: performing bytecode-based code analysis processing on a source code to be tested, determining a class file corresponding to the source code and an execution instruction corresponding to the class file, constructing at least one testing thread of the source code according to the file name of the class file and the execution instruction, and creating an instantiation object and a corresponding parameter list for each testing thread according to the class file in the source code; and executing each test thread on the source code according to the instantiation object and the corresponding parameter list to obtain a test result. The method improves the efficiency of unit testing.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and together with the description, serve to explain the principles of the application.
FIG. 1 is a schematic diagram of a network architecture on which the present application is based;
FIG. 2 is a schematic flow chart of a unit testing method provided herein;
FIG. 3 is a schematic structural diagram of a unit testing apparatus provided herein;
FIG. 4 is a schematic diagram of a unit testing system provided herein;
fig. 5 is a schematic diagram of a hardware structure of an electronic device provided in the present application.
With the above figures, there are shown specific embodiments of the present application, which will be described in more detail below. These drawings and written description are not intended to limit the scope of the inventive concepts in any manner, but rather to illustrate the inventive concepts to those skilled in the art by reference to specific embodiments.
Detailed Description
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present application, as detailed in the appended claims.
With the development of computer technology and the popularization of informatization, the dependence of people on computer technology is increasingly enhanced in aspects of life. In order to meet the requirements of users, the updating iteration speed of application software is faster and faster, unit testing becomes an important link in the whole life cycle of software development, the unit testing is the basis and premise of the whole software testing process, and the method can help developers to improve the code quality and discover software errors in advance.
In the prior art, unit testing usually artificially writes a test case corresponding to a functional module for a certain module in a software development process, and evaluates the development effect of the module according to the test result of the test case, that is, a source program to be tested includes a plurality of unit modules, and writes a test case corresponding to each unit module, and the success or failure of software development can be known only after all the test cases are executed.
However, in the prior art, extra test codes need to be written, so that development of developers is often doubled, and if a problem occurs in testing, more time is often consumed for manually writing corresponding test cases to test developed software; meanwhile, the situation of incomplete consideration exists in manual writing test, so that the test result has deviation, the test efficiency is reduced, and a large amount of manpower is wasted.
Aiming at the technical problems, the method for automatically testing the source program to be tested is realized on the basis of the JavaAgent technology without additionally writing codes. Connecting the unit test program with a source code to be tested by a JavaAgent technology, and obtaining a class file of the source program to be tested by loading the code of the source program to be tested; acquiring byte codes of class files based on a Retransformclass method provided by a JavaAgent technology; and then all methods for acquiring the class files by using a byte code analysis technology, judging the method to be executed by the unit test program according to the method name rule, adding the method to be executed into a thread pool for waiting execution, and acquiring a test result.
Specifically, the present application provides a unit testing method. The method comprises the following steps: performing bytecode-based code analysis processing on a source code to be tested, determining a class file corresponding to the source code and an execution instruction corresponding to the class file, constructing at least one testing thread of the source code according to the file name of the class file and the execution instruction, and creating an instantiation object and a corresponding parameter list for each testing thread according to the class file in the source code; and executing each test thread on the source code according to the instantiation object and the corresponding parameter list to obtain a test result. The method improves the efficiency of unit testing.
The following describes technical solutions of embodiments of the present application and how to solve the above technical problems with specific embodiments. The following several specific embodiments may be combined with each other, and details of the same or similar concepts or processes may not be repeated in some embodiments. Embodiments of the present application will be described below with reference to the accompanying drawings.
Referring to fig. 1, fig. 1 is a schematic diagram of a network architecture on which the present application is based, and as shown in fig. 1, the network architecture includes aserver 1.
Theserver 1 is specifically a server cluster capable of processing mass data, and a unit testing device provided by the present application may be integrated or installed therein, wherein the unit testing device may process a source program to be tested based on the unit testing method provided by the present application.
Example one
Fig. 2 is a schematic flow chart of a unit testing method provided in the present application, as shown in fig. 2, the method includes:
step 201, performing byte code-based code analysis processing on a source code to be tested, and determining a class file corresponding to the source code and an execution instruction corresponding to the class file;
step 202, constructing at least one test thread of the source code according to the file name of the class file and the execution instruction;
step 203, creating an instantiation object and a corresponding parameter list for each test thread according to the class file in the source code;
and 204, executing each test thread on the source code according to the instantiation object and the corresponding parameter list to obtain a test result.
Specifically, the execution subject of the unit testing method provided by the present application is the aforementioned unit testing apparatus, and as mentioned above, the unit testing apparatus may be specifically installed or carried in theaforementioned server 1.
It should be noted that the unit testing method provided in the present application is executed on the premise of being based on a spring environment.
Instep 201, when the unit testing device executes the source code to be tested, it needs to perform byte code-based parsing on the source code to be tested, and determine a class file corresponding to the source code and an execution instruction corresponding to the class file.
Specifically, the unit testing device associates a unit testing program with a source program to be tested based on the JavaAgent technology, namely, a source code to be tested is input into the unit testing method; according to the JavaAgent technology, a source code to be tested is loaded to obtain a class file in the source code, then a retransFormClass method provided by the JavaAgent technology is used for obtaining byte codes of the class, and then an execution instruction corresponding to the class file is obtained by using a byte code analyzing technology in the Java technology. The execution instruction refers to an operation instruction of the computer, which can be divided into an operation instruction, a data transmission instruction, a program control instruction, and an input/output instruction.
The bytecode is a binary file comprising an executive program, a sequence of operation codes, namely, numerical constants, references, instructions and the like, or a data pair, and is an intermediate code, so that the applicability of the unit test method to the application environment is enhanced. The byte code analysis refers to the escape of the byte code of the binary system, so that the virtual machine required by the unit test method can identify the byte code and execute corresponding processing. The virtual machine instruction refers to an abstracted computer instruction, which corresponds to a virtualized computer, i.e., a virtual machine.
After the unit test obtains the class file and the execution instruction corresponding to the class file, the unit test apparatus performsstep 202 to obtain a test thread that the unit test program needs to be executed, that is, the unit test apparatus constructs at least one test thread of the source code according to the file name of the class file and the execution instruction. Wherein the test thread refers to one of all functional functions provided by the unit test.
In particular, at least one test thread building the source code may originate from two different test units, a first test unit and a second test unit. The first test unit represents a set of unit test methods which can carry out corresponding calling operation according to the class file name, and at least one test line which is called as a first test thread and used for constructing the source code by calling the first unit test method by a unit test device corresponding to the first test unit; the second test unit represents a set of unit test methods capable of performing corresponding calling operations according to the instruction type, and at least one test line called a second test thread, in which the unit test device corresponding to the second test unit calls the second unit test method to construct the source code.
Further, the first test thread and the second test thread constitute at least one test thread of the source code, and it is understood that the test thread constructing the source code may be one or more, and the test thread is composed of the first test thread and the second test thread.
Step 202 may also be said to include, according to the file name of the class file, calling a first unit test method corresponding to the file name to construct a first test thread corresponding to the first unit test method; calling a second unit test method corresponding to the instruction type according to the instruction type of the execution instruction to construct a second test thread corresponding to the second unit test method; the first test thread and the second test thread constitute at least one test thread of the source code.
And after the unit testing device constructs the testing thread of the source code to be tested, putting the testing thread into a thread pool to wait for execution.
Before the unit testing device executes the testing thread, an instantiation object and a corresponding parameter list are required to be created for the testing thread to be executed. Instep 203, the unit test device will create an instantiation object and a corresponding parameter list for each test thread according to the class file in the source code.
Specifically, the unit testing device determines an instantiation object corresponding to the class file according to the interface type of the class file in the source code and/or the file name of the class file, and then constructs a parameter list of the instantiation object according to the parameter type in the instantiation object.
The interface type of the class file is an API provided by Java technology, and the interface types assigned to each class file in the source code to be tested are different, so that the unit testing device can obtain an instantiation object of the class file according to the interface type of the class file.
The instantiated object corresponding to the class file is determined according to the name of the class file, and can be understood as the class file and the instantiated object corresponding to the class file, and the class file and the instantiated object are associated together through similar names, for example, the class file is a student class, and the instantiated object is student A, that is, the instantiated object corresponding to the class file can be obtained through names of students.
After the unit testing device obtains the instantiation object, a parameter list of the instantiation object is constructed according to the parameter type in the instantiation object, the parameter type field value corresponding to the parameter type field in the instantiation object is determined, and the parameter list of the instantiation object is constructed according to the parameter list type represented by the parameter type field value.
The parameter type field in the instantiation object is composed of a data type and a field name, that is, is composed of a "data type field name" and is used to describe attribute information of the instantiation object, such as the instantiation object student1, and the parameter type field in the instantiation object includes: a character type name field, an integer age field, etc., and the parameter type field value corresponding to the parameter type field value of student1 may be "zhang san, 23".
Specifically, the parameter list types include a Java data type list and a Java complex data type list, and the unit testing device constructs the parameter list of the instantiated object according to the parameter list type represented by the parameter type field value.
If the parameter type field value indicates that the parameter list type is a Java data type list, traversing an instantiation object according to a preset basic field type to obtain the field value of the instantiation object under each basic field type; and generating a parameter list of the instantiation object according to the basic field type and the field value of the basic field type.
If the parameter type field value indicates that the parameter list type is a Java complex data type list, traversing an instantiation object according to basic field types to obtain the field value of the instantiation object under each basic field type; assigning values to field values of the instantiation objects under the complex field types according to the relation of the field values of the instantiation objects under the basic field types; and generating a parameter list of the instantiation object according to the basic field type, the field value of the basic field type, the complex field type and the field value under the complex field type.
The Java data types comprise integer int, character string, Boolean bolean and the like; the Java complex data type means that an instantiation object is also contained in a parameter type field of the instantiation object, for example, a parameter type field of thestub 2 includes: "character type name", "integer age", "class address", wherein "class address" indicates another class, which includes parameter type fields of "character type province", "character type, city", "character type, cell unit, and house number".
As shown in table 1, table 1 shows a parameter list in which an instantiation object is a Java data type.
TABLE 1
Type (B)Value of
int0
String“0”
booleanfalse
Datenew Date()
TimestampNew Timestamp(System.currentTimeMillis())
Mapnew HashMap()
Further, when the unit testing device detects that the parameter list type represented by the parameter type field value of the parameter list of the instantiated object is a Java data type, the instantiated object is traversed according to a preset basic field type, for example, the field of the character type name in thestudent 2 is traversed, and the field value of the instantiated object under the character type name type is obtained to be 0, and then, the unit testing device stores all the basic field types and the field values of the basic field types into a data list according to the sequence of the type name field values, so as to generate the parameter list of the instantiated object.
And when the unit testing device detects that the parameter list type is a Java complex data type, instantiating the parameter list of the basic field type according to the above, and acquiring the field value of the parameter of the basic field type.
Then, the unit testing device traverses the parameter type fields in sequence from top to bottom and gives corresponding field values to the parameter type fields according to the relationship of the field values of the instantiated objects under the types of the basic fields, wherein the relationship of the field values means that at least one of the type parameter fields of the instantiated objects is another instantiated object, and the other instantiated object also has corresponding type parameter fields.
Finally, the unit testing device sorts the parameter field types and the field values according to the sequence of the type name field values of the basic field types, the complex field types and the field values under the complex field types, and generates a parameter list of the instantiation object in a sorted result storage data list.
After the unit testing device finishes processing the parameter list of the instantiation objects of the threads to be tested, the unit testing device executes the test threads in sequence according to the waiting sequence of the test threads in the thread pool.
Specifically, the unit testing device generates a test log according to a test result obtained by performing a plurality of unit tests on the source code to be tested, and performs statistical analysis on the test log to obtain a test report.
Further, the unit testing device executes the testing thread of the source code to be tested according to the Java reflection mechanism, and then generates the testing result as a testing log, where the testing log includes information on whether the testing is successful or not, and if the testing is unsuccessful, the unit testing device stores the testing log in the disk according to data accumulated in the testing log or according to a certain time interval, so as to analyze the source code to be tested at a later time.
The Java reflection execution mechanism refers to finding out more corresponding test threads of the class files according to the class files.
The application provides a unit testing method. The method comprises the following steps: performing bytecode-based code analysis processing on a source code to be tested, determining a class file corresponding to the source code and an execution instruction corresponding to the class file, constructing at least one testing thread of the source code according to the file name of the class file and the execution instruction, and creating an instantiation object and a corresponding parameter list for each testing thread according to the class file in the source code; and executing each test thread on the source code according to the instantiation object and the corresponding parameter list to obtain a test result. The method improves the efficiency of unit testing.
Example two
Fig. 3 is a schematic structural diagram of a unit testing apparatus according to the present application, corresponding to the unit testing method of the present application. For ease of illustration, only the portions relevant to the present application are shown.
Referring to fig. 3, the unit testing apparatus includes:
theanalysis module 10 is configured to perform bytecode-based code analysis processing on a source code to be tested, and determine a class file corresponding to the source code and an execution instruction corresponding to the class file;
abuilding module 20, configured to build at least one test thread of the source code according to the file name of the class file and the execution instruction;
a creatingmodule 30, configured to create an instantiation object and a corresponding parameter list for each test thread according to the class file in the source code;
and thetest module 40 is configured to execute each test thread on the source code according to the instantiation object and the corresponding parameter list to obtain a test result.
Thebuilding block 20 is specifically configured to:
calling a first unit test method corresponding to the file name according to the file name of the class file to construct a first test thread corresponding to the first unit test method;
calling a second unit test method corresponding to the instruction type according to the instruction type of the execution instruction to construct a second test thread corresponding to the second unit test method;
the first test thread and the second test thread constitute at least one test thread of the source code.
The creatingmodule 30 is specifically configured to:
determining an instantiation object corresponding to the class file according to the interface type of the class file in the source code and/or the file name of the class file;
and constructing a parameter list of the instantiation object according to the parameter type in the instantiation object.
The creatingmodule 30 is specifically further configured to:
determining a parameter type field value corresponding to a parameter type field in the instantiation object;
and constructing a parameter list of the instantiation object according to the parameter list type represented by the parameter type field value.
The creatingmodule 30 is specifically further configured to:
if the parameter type field value indicates that the parameter list type is a Java data type list, traversing an instantiation object according to a preset basic field type to obtain the field value of the instantiation object under each basic field type; generating a parameter list of the instantiation object according to the basic field type and the field value of the basic field type;
if the parameter type field value indicates that the parameter list type is a Java complex data type list, traversing an instantiation object according to basic field types to obtain the field value of the instantiation object under each basic field type; assigning values to field values of the instantiation objects under the complex field types according to the relation of the field values of the instantiation objects under the basic field types; and generating a parameter list of the instantiation object according to the basic field type, the field value of the basic field type, the complex field type and the field value under the complex field type.
Thetest module 40 is specifically configured to:
performing a plurality of unit tests according to the source code to be tested to obtain a test result, and generating a test log;
and carrying out statistical analysis on the test logs to obtain a test report.
The implementation principle of the unit testing device provided by the present application is similar to that in any of the above embodiments, and is not described herein again.
The application provides a unit testing device. The method comprises the following steps: performing bytecode-based code analysis processing on a source code to be tested, determining a class file corresponding to the source code and an execution instruction corresponding to the class file, constructing at least one testing thread of the source code according to the file name of the class file and the execution instruction, and creating an instantiation object and a corresponding parameter list for each testing thread according to the class file in the source code; and executing each test thread on the source code according to the instantiation object and the corresponding parameter list to obtain a test result. The method improves the efficiency of unit testing.
EXAMPLE III
Fig. 4 is a schematic diagram of a unit testing system provided in the present application, corresponding to the unit testing method provided in the present application, and only the relevant parts are shown for convenience of explanation.
Referring to fig. 4, the unit test system includes:unit testing device 101, source code file to be tested 2.
The unit testing device is used for testing a source code to be tested, testing the source code to be tested by the unit testing method, and storing a testing result in a disk.
Example four
Fig. 5 is a schematic diagram of a hardware structure of the electronic device provided in the present application, and for convenience of description, only a part related to the present application is shown.
Referring to fig. 5, a schematic structural diagram of an electronic device 1000 suitable for implementing an embodiment of the present application is shown, where the electronic device 1000 may be a terminal device. Among them, the terminal Device may include, but is not limited to, a mobile terminal such as a mobile phone, a notebook computer, a Digital broadcast receiver, a Personal Digital Assistant (PDA), a tablet computer (PAD), a Portable Multimedia Player (PMP), a car mounted Device (e.g., car navigation terminal), etc., and a fixed terminal such as a Digital TV, a desktop computer, etc. The electronic device shown in fig. 5 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present application.
As shown in fig. 5, the electronic device 1000 may include an output device (e.g., a central processing unit, a graphics processor, etc.) 1007 that may perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM) 1002 or a program loaded from astorage device 1008 into a Random Access Memory (RAM) 1003. In theRAM 1003, various programs and data necessary for the operation of the electronic apparatus 1000 are also stored. Theprocessing device 1001, the ROM1002, and theRAM 1003 are connected to each other by abus 1004. An input/output (I/O)interface 1005 is also connected tobus 1004.
Generally, the following devices may be connected to the I/O interface 1005:input devices 1006 including, for example, a touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; anoutput device 1007 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like;storage devices 1008 including, for example, magnetic tape, hard disk, and the like; and acommunication device 1009. Thecommunication device 1009 may allow the electronic device 1000 to communicate with other devices wirelessly or by wire to exchange data. While fig. 5 illustrates an electronic device 1000 having various means, it is to be understood that not all illustrated means are required to be implemented or provided. More or fewer devices may alternatively be implemented or provided.
In particular, according to embodiments of the application, the processes described above with reference to the flow diagrams may be implemented as computer software programs. For example, embodiments of the present application include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated by the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication means 1009, or installed from the storage means 1008, or installed from theROM 1002. When executed by theprocessing device 1001, the computer program performs the above-described functions defined in the method of the embodiment of the present application.
It should be noted that the computer readable medium mentioned above in the present application may be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
In the present application, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In this application, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, optical cables, RF (radio frequency), etc., or any suitable combination of the foregoing.
The computer readable medium may be embodied in the electronic device; or may exist separately without being assembled into the electronic device.
The computer readable medium carries one or more programs which, when executed by the electronic device, cause the electronic device to perform the methods shown in the above embodiments.
A computer program product is provided for carrying out the operations of the present disclosure and may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + +, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or media library. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of Network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present application may be implemented by software or hardware. Where the name of a unit does not in some cases constitute a limitation of the unit itself, for example, the first retrieving unit may also be described as a "unit for retrieving at least two internet protocol addresses".
The functions described herein above may be performed, at least in part, by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field Programmable Gate Arrays (FPGAs), Application Specific Integrated Circuits (ASICs), Application Specific Standard Products (ASSPs), systems on a chip (SOCs), Complex Programmable Logic Devices (CPLDs), and the like.
In the context of this application, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
Other embodiments of the present application will be apparent to those skilled in the art from consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the invention following, in general, the principles of the application and including such departures from the present disclosure as come within known or customary practice within the art to which the invention pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the application being indicated by the following claims.
It will be understood that the present application is not limited to the precise arrangements described above and shown in the drawings and that various modifications and changes may be made without departing from the scope thereof. The scope of the application is limited only by the appended claims.

Claims (11)

Translated fromChinese
1.一种单元测试方法,包括:1. A unit testing method, comprising:对待测试的源代码进行基于字节码的代码解析处理,确定所述源代码对应的类文件以及所述类文件对应的执行指令;Perform bytecode-based code parsing processing on the source code to be tested, and determine a class file corresponding to the source code and an execution instruction corresponding to the class file;根据所述类文件的文件名和所述执行指令,构建所述源代码的至少一个测试线程;According to the file name of the class file and the execution instruction, construct at least one test thread of the source code;根据所述源代码中的类文件为每个测试线程创建实例化对象和相应的参数列表;Create an instantiated object and a corresponding parameter list for each test thread according to the class file in the source code;根据所述实例化对象和相应的参数列表在所述源代码上执行各测试线程,得到测试结果。Execute each test thread on the source code according to the instantiated object and the corresponding parameter list to obtain a test result.2.根据权利要求1所述的单元测试方法,其特征在于,所述根据所述类文件的文件名和所述执行指令,构建所述源代码的至少一个测试线程,包括:2. The unit testing method according to claim 1, wherein the building at least one test thread of the source code according to the file name of the class file and the execution instruction, comprises:根据所述类文件的文件名,调用与所述文件名相应的第一单元测试方法以构建所述第一单元测试方法相应的第一测试线程;According to the file name of the class file, a first unit test method corresponding to the file name is called to construct a first test thread corresponding to the first unit test method;根据所述执行指令的指令类型,调用与所述指令类型相应的第二单元测试方法以构建所述第二单元测试方法相应的第二测试线程;According to the instruction type of the execution instruction, a second unit test method corresponding to the instruction type is called to construct a second test thread corresponding to the second unit test method;所述第一测试线程和所述第二测试线程构成所述源代码的至少一个测试线程。The first test thread and the second test thread constitute at least one test thread of the source code.3.根据权利要求1所述的单元测试方法,其特征在于,根据所述源代码中的类文件为每个测试线程创建实例化对象和相应的参数列表,包括:3. unit testing method according to claim 1 is characterized in that, according to the class file in described source code, create instantiation object and corresponding parameter list for each test thread, comprising:根据所述源代码中的类文件的接口类型,和/或,类文件的文件名确定所述类文件对应的实例化对象;Determine the instantiated object corresponding to the class file according to the interface type of the class file in the source code, and/or the file name of the class file;根据所述实例化对象中的参数类型,构建实例化对象的参数列表。A parameter list of the instantiated object is constructed according to the parameter types in the instantiated object.4.根据权利要求3所述的单元测试方法,其特征在于,所述根据所述实例化对象中的参数类型,构建实例化对象的参数列表,包括:4. The unit testing method according to claim 3, wherein, constructing a parameter list of the instantiated object according to the parameter type in the instantiated object, comprising:确定所述实例化对象中参数类型字段对应的参数类型字段值;determining the parameter type field value corresponding to the parameter type field in the instantiated object;根据所述参数类型字段值所表征的参数列表类型,构建所述实例化对象的参数列表。The parameter list of the instantiated object is constructed according to the parameter list type represented by the parameter type field value.5.根据权利要求4所述的单元测试方法,其特征在于,参数列表类型包括Java数据类型列表和Java复杂数据类型列表;5. unit testing method according to claim 4 is characterized in that, parameter list type comprises Java data type list and Java complex data type list;所述根据所述参数类型字段值所表征的参数列表类型,构建所述实例化对象的参数列表,包括:The parameter list of the instantiated object is constructed according to the parameter list type represented by the parameter type field value, including:若所述参数类型字段值表征所述参数列表类型为Java数据类型列表,则按照预设的基础字段类型对实例化对象进行遍历,得到所述实例化对象在各基础字段类型下的字段值;根据所述基础字段类型和所述基础字段类型的字段值,生成所述实例化对象的参数列表;If the parameter type field value indicates that the parameter list type is a Java data type list, the instantiated object is traversed according to the preset basic field type, and the field value of the instantiated object under each basic field type is obtained; generating a parameter list of the instantiated object according to the basic field type and the field value of the basic field type;若所述参数类型字段值表征所述参数列表类型为Java复杂数据类型列表,则按照基础字段类型对实例化对象进行遍历,得到所述实例化对象在各所述基础字段类型下的字段值;根据所述实例化对象在各所述基础字段类型下的字段值的关系,对所述实例化对象在复杂字段类型下的字段值进行赋值;根据所述基础字段类型、所述基础字段类型的字段值、所述复杂字段类型和所述复杂字段类型下的字段值,生成所述实例化对象的参数列表。If the parameter type field value indicates that the parameter list type is a Java complex data type list, the instantiated object is traversed according to the basic field type to obtain the field value of the instantiated object under each of the basic field types; According to the relationship between the field values of the instantiated object under each of the basic field types, assign values to the field values of the instantiated object under the complex field type; according to the basic field type, the basic field type The field value, the complex field type, and the field value under the complex field type generate a parameter list of the instantiated object.6.根据权利要求1-5任一所述的单元测试方法,其特征在于,还包括:6. The unit testing method according to any one of claims 1-5, further comprising:根据所述待测试的源代码进行多次单元测试得到的测试结果,生成测试日志;Generate a test log according to the test results obtained by performing multiple unit tests on the source code to be tested;对所述测试日志进行统计分析,得到测试报告。Statistical analysis is performed on the test log to obtain a test report.7.一种单元测试装置,其特征在于,包括:7. A unit testing device, comprising:解析模块,用于对待测试的源代码进行基于字节码的代码解析处理,确定所述源代码对应的类文件以及所述类文件对应的执行指令;A parsing module, configured to perform bytecode-based code parsing processing on the source code to be tested, and determine a class file corresponding to the source code and an execution instruction corresponding to the class file;构建模块,用于根据所述类文件的文件名和所述执行指令,构建所述源代码的至少一个测试线程;a building module for building at least one test thread of the source code according to the file name of the class file and the execution instruction;创建模块,用于根据所述源代码中的类文件为每个测试线程创建实例化对象和相应的参数列表;Create a module for creating an instantiated object and a corresponding parameter list for each test thread according to the class file in the source code;测试模块,用于根据所述实例化对象和相应的参数列表在所述源代码上执行各测试线程,得到测试结果。A test module, configured to execute each test thread on the source code according to the instantiated object and the corresponding parameter list to obtain test results.8.一种单元测试系统,其特征在于,包括:所述单元测试装置、待测试源代码文件;8. A unit testing system, comprising: the unit testing device, a source code file to be tested;所述单元测试装置用于测试待测试源代码,并根据权利要求1-6任一项所述的单元测试方法对所述所述待测试源代码进行测试,并将测试结果存储于磁盘中。The unit testing device is used for testing the source code to be tested, and tests the source code to be tested according to the unit testing method of any one of claims 1-6, and stores the test result in a disk.9.一种电子设备,包括:处理器,以及与所述处理器通信连接的存储器;9. An electronic device comprising: a processor, and a memory communicatively connected to the processor;所述存储器存储计算机执行指令;the memory stores computer-executable instructions;所述处理器执行所述存储器存储的计算机执行指令,以实现如权利要求1-5中任一项所述的方法。The processor executes computer-implemented instructions stored in the memory to implement the method of any of claims 1-5.10.一种计算机可读存储介质,其特征在于,所述计算机可读存储介质中存储有计算机执行指令,所述计算机执行指令被处理器执行时用于实现如权利要求1-6任一项所述的光传输环路网的配置方法。10. A computer-readable storage medium, characterized in that, computer-executable instructions are stored in the computer-readable storage medium, and when the computer-executable instructions are executed by a processor, are used to implement any one of claims 1-6 The configuration method of the optical transmission ring network.11.一种计算机程序产品,包括计算机程序,该计算机程序被处理器执行时实现权利要求1-6中任一项所述的方法。11. A computer program product comprising a computer program which, when executed by a processor, implements the method of any of claims 1-6.
CN202111482479.3A2021-12-062021-12-06 Unit testing method, device, system and storage mediumActiveCN114168466B (en)

Priority Applications (1)

Application NumberPriority DateFiling DateTitle
CN202111482479.3ACN114168466B (en)2021-12-062021-12-06 Unit testing method, device, system and storage medium

Applications Claiming Priority (1)

Application NumberPriority DateFiling DateTitle
CN202111482479.3ACN114168466B (en)2021-12-062021-12-06 Unit testing method, device, system and storage medium

Publications (2)

Publication NumberPublication Date
CN114168466Atrue CN114168466A (en)2022-03-11
CN114168466B CN114168466B (en)2025-10-03

Family

ID=80483688

Family Applications (1)

Application NumberTitlePriority DateFiling Date
CN202111482479.3AActiveCN114168466B (en)2021-12-062021-12-06 Unit testing method, device, system and storage medium

Country Status (1)

CountryLink
CN (1)CN114168466B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN114840411A (en)*2022-03-172022-08-02阿里巴巴(中国)有限公司 Unit testing method, device and storage medium
CN116155350A (en)*2023-01-102023-05-23北京微纳星空科技有限公司Method and system for generating instructions of satellite in batches, storage medium and electronic equipment

Citations (6)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN102736980A (en)*2012-06-292012-10-17南京大学Random test case generation method facing Java program
CN108595342A (en)*2018-05-142018-09-28杭州有赞科技有限公司Unit test method and device
CN108984393A (en)*2018-06-122018-12-11苏宁易购集团股份有限公司A kind of unit testing code automatic generation method and device
CN109710539A (en)*2019-01-172019-05-03南京大学 An Android software enhancement testing method based on bytecode operation
CN111008153A (en)*2019-12-292020-04-14合肥工大高科信息科技股份有限公司Unit testing method and system
CN113076253A (en)*2021-04-162021-07-06北京京东拓先科技有限公司Test method and test device

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN102736980A (en)*2012-06-292012-10-17南京大学Random test case generation method facing Java program
CN108595342A (en)*2018-05-142018-09-28杭州有赞科技有限公司Unit test method and device
CN108984393A (en)*2018-06-122018-12-11苏宁易购集团股份有限公司A kind of unit testing code automatic generation method and device
CN109710539A (en)*2019-01-172019-05-03南京大学 An Android software enhancement testing method based on bytecode operation
CN111008153A (en)*2019-12-292020-04-14合肥工大高科信息科技股份有限公司Unit testing method and system
CN113076253A (en)*2021-04-162021-07-06北京京东拓先科技有限公司Test method and test device

Cited By (4)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN114840411A (en)*2022-03-172022-08-02阿里巴巴(中国)有限公司 Unit testing method, device and storage medium
CN114840411B (en)*2022-03-172025-02-11阿里巴巴(中国)有限公司 Unit testing method, device and storage medium
CN116155350A (en)*2023-01-102023-05-23北京微纳星空科技有限公司Method and system for generating instructions of satellite in batches, storage medium and electronic equipment
CN116155350B (en)*2023-01-102025-06-24北京微纳星空科技股份有限公司 Satellite command batch generation method, system, storage medium and electronic device

Also Published As

Publication numberPublication date
CN114168466B (en)2025-10-03

Similar Documents

PublicationPublication DateTitle
CN113762702A (en)Workflow deployment method, device, computer system and readable storage medium
CN113590327B (en) Project resource detection method, device, electronic equipment and storage medium
CN114168466B (en) Unit testing method, device, system and storage medium
CN114968817A (en)Method, device, equipment and storage medium for evaluating code change influence range
CN114168485A (en)Test method, device, equipment and medium
CN114610598A (en)Test method, test device, electronic equipment and computer readable storage medium
CN113254340B (en) A method and device for generating test cases
CN115167822A (en)Branch code merging method, device, equipment and storage medium
CN111797009B (en)Method and device for detecting code compatibility and electronic equipment
CN116225886A (en)Test case generation method, device, equipment, storage medium and program product
CN117725081A (en)Data analysis method and device
CN109901983B (en)Automatic testing method and device, storage medium and electronic equipment
CN118193353A (en) A method, device, electronic device and storage medium for determining difference information
CN115048107A (en)Code compiling method, system, electronic device and storage medium
CN114996152A (en)Unit testing method, device, equipment and medium
CN116149978A (en)Service interface testing method and device, electronic equipment and storage medium
CN114036053B (en) Test method, device, readable medium and electronic device
CN114780126B (en) Code update method, device, equipment and medium for vehicle controller software
CN116467178B (en)Database detection method, apparatus, electronic device and computer readable medium
CN111913737B (en) A method, device, equipment and storage medium for constructing a data service interface
CN116701159A (en)Test case generation method and device, electronic equipment and storage medium
CN115309622A (en) Software testing method, device, equipment and storage medium based on probability model
CN115904926A (en)Test case generation method and device, electronic equipment and storage medium
CN115878091A (en)Data processing method, device, equipment and storage medium
CN114328166A (en) Method, device and storage medium for acquiring performance information of AB test algorithm

Legal Events

DateCodeTitleDescription
PB01Publication
PB01Publication
SE01Entry into force of request for substantive examination
SE01Entry into force of request for substantive examination
GR01Patent grant

[8]ページ先頭

©2009-2025 Movatter.jp