CN113760731A - Test method and device - Google Patents

Test method and device Download PDF

Info

Publication number
CN113760731A
CN113760731A CN202110113640.3A CN202110113640A CN113760731A CN 113760731 A CN113760731 A CN 113760731A CN 202110113640 A CN202110113640 A CN 202110113640A CN 113760731 A CN113760731 A CN 113760731A
Authority
CN
China
Prior art keywords
source file
generating
file
method body
object information
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.)
Pending
Application number
CN202110113640.3A
Other languages
Chinese (zh)
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.)
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Century Trading Co Ltd, Beijing Wodong Tianjun Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN202110113640.3A priority Critical patent/CN113760731A/en
Publication of CN113760731A publication Critical patent/CN113760731A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/166Editing, e.g. inserting or deleting
    • G06F40/186Templates
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4488Object-oriented
    • G06F9/449Object-oriented method invocation or resolution

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Computational Linguistics (AREA)
  • General Health & Medical Sciences (AREA)
  • Health & Medical Sciences (AREA)
  • Artificial Intelligence (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention discloses a testing method and a testing device, and relates to the technical field of computers. One specific embodiment of the test method comprises: analyzing a source file to acquire structure object information related to the structure of the source file; and generating a test file of the source file according to the structure object information. The implementation method can finish unit test writing on the premise of modifying a small amount of codes, and greatly saves the time for writing the test method main body. Meanwhile, the template can be written according to the custom rules of different clients, and the custom single test requirement can be met.

Description

Test method and device
Technical Field
The invention relates to the technical field of computers, in particular to a testing method and a testing device.
Background
The unit test refers to a coding completion stage, and tests the test case codes to achieve a self-test effect and ensure the comprehensiveness and robustness of the program. A common plug-in tool is known as JUnitGenerator V2.0. The plug-in function is simple, only simple class and method names can be generated, and variable definitions, instance definitions, method calls and call results in a method body cannot be automatically generated.
Disclosure of Invention
In view of this, embodiments of the present invention provide a testing method and apparatus, which can solve the problems that the existing testing method can only generate simple class and method names, and cannot automatically generate variable definitions, instance definitions, method calls, and call results inside a method body.
To achieve the above object, according to an aspect of an embodiment of the present invention, a test method is provided.
The test method of the embodiment of the invention comprises the following steps:
analyzing a source file to acquire structure object information related to the structure of the source file;
and generating a test file of the source file according to the structure object information.
Optionally, the structure object information includes at least one or more of: file information, package-leading information, class name, member variable, method body, and internal attributes of the method body.
Optionally, generating the test file of the source file according to the structure object information includes:
generating class basic information for representing the attribute of the test file according to the structure object information;
generating a calling code and a verification result code for testing the source file according to the structure object information;
writing the class basic information, the calling code and the verification result code into a file to generate a test file of the source file.
Optionally, generating, according to the structure object information, an invocation code for testing the source file includes:
generating an instance object according to the structural object information;
judging whether the method body of the source file has input parameters and return values;
if the method body of the source file has input parameters and the method body does not return values, generating a calling code for testing the source file according to the instance object and the calling input parameters; the calling input parameter is generated according to the input parameter of the source file method body;
if the method body of the source file has input parameters and the method body has return values, generating a calling code according to the relevant information of the return values, the instance object and the calling input parameters;
if the method body of the source file has no input parameter and the method body has no return value, generating a calling code according to the instance object;
and if the method body of the source file has no input parameter and has a return value, generating a calling code according to the instance object and the related information of the return value.
Optionally, if the method body of the source file has no input parameter and the method body has no return value, the format of the calling code is: instance object method name ();
if the method body of the source file has no input parameter and the method body has a return value, the format of the calling code is as follows: the return value class return value variable name ═ instance object.
If the method body of the source file has input parameters and the method body does not return values, the format of the calling code is as follows: method name (call input parameter);
if the method body of the source file has input parameters and the method body has return values, the format of the calling code is as follows: the return value class return value variable name is the instance object.
Optionally, generating an instance object according to the structure object information includes:
and generating an instance object by adopting the structural object information in a reflection mode.
Optionally, the source file is a java file; parsing the source file includes:
and analyzing the source file by adopting a java analysis tool class.
To achieve the above object, according to another aspect of an embodiment of the present invention, there is provided a test apparatus.
The testing device of the embodiment of the invention comprises:
the analysis module is used for analyzing the source file to acquire structural object information related to the structure of the source file;
and the generating module is used for generating a test file of the source file according to the structural object information.
To achieve the above object, according to another aspect of an embodiment of the present invention, there is provided an electronic apparatus.
The electronic device of the embodiment of the invention comprises:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method as described above.
To achieve the above object, according to another aspect of an embodiment of the present invention, there is provided a computer-readable medium.
A computer-readable medium of an embodiment of the invention has stored thereon a computer program which, when executed by a processor, implements the method as described above.
One embodiment of the above invention has the following advantages or benefits:
in the embodiment of the present invention, a source file is first parsed to obtain structure object information related to the structure of the source file. And then generating a test file of the source file according to the structure object information. The implementation method can finish unit test writing on the premise of modifying a small amount of codes, and greatly saves the time for writing the test method main body. Meanwhile, the template can be written according to the custom rules of different clients, and the custom single test requirement can be met.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a schematic flow chart of a testing method according to a first embodiment of the present invention;
FIG. 2 is a schematic flow chart of a testing method according to a second embodiment of the present invention;
FIG. 3 is a second flowchart illustrating a testing method according to a second embodiment of the present invention;
FIG. 4 is a block diagram of a testing device according to an embodiment of the present invention;
FIG. 5 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
fig. 6 is a schematic block diagram of a computer system suitable for use in implementing a terminal device or server of an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
Generally, the existing implementation mode mainly has the problem that a complete code generation link is lacked. The existing implementation mode has the following difficulties: how to automatically generate the body part of the unit test includes: generating an instance object, generating an input parameter, generating a method call and verifying a call result.
In order to solve the above problem, an embodiment of the present invention provides a test method. Fig. 1 is a schematic flow chart of a testing method according to an embodiment of the present invention, and as shown in fig. 1, the testing method may include steps S101 to S102 as follows.
Step S101: the method includes parsing a source file to obtain structure object information related to a structure of the source file.
In step S101, the source file includes one or more method bodies, and each method body is correspondingly provided with input parameters corresponding to the method body. The structure object information is used for representing relevant information of a structure in the source file, and the structure of the source file is related to a method body included in the source file. The structure object information includes at least one or more of: file information, Package information (Package), Package information (Import), class name, member variable, method body, and internal attributes of the method body.
It should be noted that the source file has different formats and different parsing manners. When the source file is a java file, a java analysis tool class can be adopted to analyze the source file and store the structure object information obtained by analysis. For example: the source file can be parsed by java parser (java parser is a java parsing tool class).
Step S102: and generating a test file of the source file according to the structure object information.
In step S102, after the structure object information is acquired, a test file tested by the acquired structure object information generating unit may be used.
Specifically, the class basic information for representing the attribute of the test file may be first generated from the structure object information. And then generating a calling code and a verification result code for testing the source file according to the structure object information. And writing the class basic information, the calling code and the verification result code into a file to generate a test file of the source file.
It should be noted that, before generating the class basic information, a file for storing information required by the test may be generated, for example: java, and the path of the test file may be a path of a source file in the structure object information. The class basic information is used for representing the attribute of the test file, and the class basic information at least comprises one or more of the following items: test class name, packaging information, and package guide information. For example: and taking the Package of the source file from the Package of the test file. And taking the Import of the source file and the Import of the class from the Import of the test file, and then calling a shortcut key of the ide to remove useless imports. Testing the name of the class: class name + Test.
Before generating the calling code, an instance object needs to be generated according to the structure object information. Further, the structure object information may be reflected to generate an instance object, and a variable name of the instance object may be a lower case of a class name.
Because the generation process of the calling code is related to whether the method body of the source file has the input parameters and the return values, after the instance object is generated, whether the method body of the source file has the input parameters and the return values can be judged, and the generation process of the calling code can be divided into the following situations according to the judgment result:
the first situation is as follows: the method body of the source file has input parameters and the method body has no return values. At this time, a call code for testing the source file may be generated according to the instance object and the call input parameter.
The calling input parameter is an input parameter of a calling code and is generated according to the input parameter in the method body of the source file. If the method body of the source file has input parameters and the method body has return values, the format of the calling code is as follows: the method name (call input parameter 1, call input parameter 2.) does not limit the number of call input parameters, and may be one or more, specifically determined according to the result generated by the input parameters in the method body of the source file.
It should be noted that, whether there are input parameters in the method body of the source file may be checked through the structure object information, and if there is no input parameter, it is not necessary to generate a call input parameter. If the method body of the source file has the input parameters, the calling input parameters can be generated according to the input parameters of the method body in the source file before the calling codes are generated, and the calling input parameters refer to the input parameters of the calling codes. For example, the call input parameter may be generated according to the type of the input parameter. If one or more input parameters exist, random parameters need to be generated according to whether the input parameters are of a basic type or a reference type. If the reference type is the reference type, the random attribute needs to be generated by means of a reflection tool.
It will be appreciated that both case one and case two are situations where the source file has input parameters, i.e. in both case one and case two it is necessary to perform the step of generating call input parameters before generating call code.
Case two: the method body of the source file has input parameters and the method body has return values. At this time, a call code may be generated according to the information related to the return value, the instance object, and the call input parameter.
If the method body of the source file has input parameters and the method body does not return values, the format of the calling code is as follows: the method name (calling input parameter 1 and calling input parameter 2.) is not limited by the number of the calling input parameters, and can be one or more, and is specifically determined according to the input parameter generation result in the method body of the source file.
Case three: the method body of the source file has no input parameters and the method body has no return values. At this time, a calling code may be generated from the instance object.
If the method body of the source file has no input parameter and the method body has no return value, the format of the calling code is as follows: example object method name ().
Case four: the method body of the source file has no input parameters and the method body has a return value. At this time, a calling code may be generated according to the instance object and the related information of the return value.
If the method body of the source file has no input parameter and the method body has a return value, the format of the calling code is as follows: the return value class return value variable name is the instance object.
Similarly, since the generation process of the verification result code is related to whether the source file has a return value, the generation process of the verification result code can be divided into the following cases:
the first situation is as follows: the source file has no return value. The format of the authentication result code may be a alert.
Case two: the source file has a return value. The format of the verification result code is// ase rt. assertesquares (expected, return value).
It is emphasized that the above logic and algorithms may form an abstract template class that may retain the most basic algorithmic logic. It can be understood that different clients can package their own frames and codes according to their needs, and can expand on the templates, which can realize differentiation.
In the embodiment of the present invention, a source file is first parsed to obtain structure object information related to the structure of the source file. And then generating a test file of the source file according to the structure object information. The implementation method can finish unit test writing on the premise of modifying a small amount of codes, and greatly saves the time for writing the test method main body. Meanwhile, the template can be written according to the custom rules of different clients, and the custom single test requirement can be met.
Fig. 2 and 3 are schematic flowcharts of a testing method according to an embodiment of the present invention, and as shown in fig. 2 and 3, the testing method may include steps S201 to S205 as follows.
Step S201: analyzing the source file by adopting a java analysis tool class to acquire structural object information related to the structure of the source file.
In step S201, the source file includes one or more method bodies, and each method body is correspondingly provided with input parameters corresponding to the method body. The structure object information is used for representing relevant information of a structure in the source file, and the structure of the source file is related to a method body included in the source file. The structure object information includes at least one or more of: file information, Package information (Package), Package information (Import), class name, member variable, method body, and internal attributes of the method body. Wherein the source file can be parsed with javascript.
Step S202: and generating a file according to the structural object information.
In step S202, the file generation process refers to a process of generating attribute information such as a file name and a file path. For example: java, and the path of the test file may be a path of a source file in the structure object information.
Step S203: and generating class basic information for expressing the attribute of the test file according to the structure object information.
In step S203, the class basic information is used to represent the attribute of the test file, and the class basic information at least includes one or more of the following items: test class name, packaging information, and package guide information. For example: and taking the Package of the source file from the Package of the test file. And taking the Import of the source file and the Import of the class from the Import of the test file. And finally, calling a shortcut key of the ide to remove useless import. Testing the name of the class: class name + Test.
Step S204: and generating a calling code and a verification result code for testing the source file according to the structure object information.
In step S204, before generating the calling code, it is necessary to first generate an instance object according to the structure object information. Further, the structure object information may be reflected to generate an instance object, and a variable name of the instance object may be a lower case of a class name.
Because the generation process of the calling code is related to whether the method body of the source file has the input parameters and the return values, after the instance object is generated, whether the method body of the source file has the input parameters and the return values can be judged, and the generation process of the calling code can be divided into the following situations according to the judgment result:
the first situation is as follows: the method body of the source file has input parameters and the method body has no return values. At this time, a call code for testing the source file may be generated according to the instance object and the call input parameter.
The calling input parameter is an input parameter of a calling code and is generated according to the input parameter in the method body of the source file. If the method body of the source file has input parameters and the method body has return values, the format of the calling code is as follows: the return value class return value variable name is an instance object.
It should be noted that, whether there are input parameters in the method body of the source file may be checked through the structure object information, and if there is no input parameter, it is not necessary to generate a call input parameter. If the method body of the source file has the input parameters, the calling input parameters can be generated according to the input parameters of the method body in the source file before the calling codes are generated, and the calling input parameters refer to the input parameters of the calling codes. For example, the call input parameter may be generated according to the type of the input parameter. If one or more input parameters exist, random parameters need to be generated according to whether the input parameters are of a basic type or a reference type. If the reference type is the reference type, the random attribute needs to be generated by means of a reflection tool.
It will be appreciated that both case one and case two are situations where the source file has input parameters, i.e. in both case one and case two it is necessary to perform the step of generating call input parameters before generating call code.
Case two: the method body of the source file has input parameters and the method body has return values. At this time, a call code may be generated according to the information related to the return value, the instance object, and the call input parameter.
If the method body of the source file has input parameters and the method body does not return values, the format of the calling code is as follows: example object method name (call input parameter 1, call input parameter 2).
Case three: the method body of the source file has no input parameters and the method body has no return values. At this time, a calling code may be generated from the instance object.
If the method body of the source file has no input parameter and the method body has no return value, the format of the calling code is as follows: example object method name ().
Case four: the method body of the source file has no input parameters and the method body has a return value. At this time, a calling code may be generated according to the instance object and the related information of the return value.
If the method body of the source file has no input parameter and the method body has a return value, the format of the calling code is as follows: the return value class return value variable name is the instance object.
Similarly, since the generation process of the verification result code is related to whether the source file has a return value, the generation process of the verification result code can be divided into the following cases:
the first situation is as follows: the source file has no return value. The format of the authentication result code may be a alert.
Case two: the source file has a return value. The format of the verification result code is// ase rt. assertesquares (expected, return value).
It is emphasized that the above logic and algorithms may form an abstract template class that may retain the most basic algorithmic logic. It can be understood that different clients can package their own frames and codes according to their needs, and can expand on the templates, which can realize differentiation.
Step S205: writing the class basic information, the calling code and the verification result code into a file to generate a test file of the source file.
In the embodiment of the present invention, a source file is first parsed to obtain structure object information related to the structure of the source file. And then generating a test file of the source file according to the structure object information. The implementation method can finish unit test writing on the premise of modifying a small amount of codes, and greatly saves the time for writing the test method main body. Meanwhile, the template can be written according to the custom rules of different clients, and the custom single test requirement can be met.
Fig. 4 is a block diagram of a testing apparatus according to an embodiment of the present invention, and referring to fig. 4, the testing apparatus 400 may include the following blocks:
the analysis module 401 is configured to analyze a source file to obtain structure object information related to a structure of the source file;
a generating module 402, configured to generate a test file of the source file according to the structure object information.
Optionally, the structure object information includes at least one or more of: file information, package-leading information, class name, member variable, method body, and internal attributes of the method body.
Optionally, the generating module 402 is further configured to:
generating class basic information for representing the attribute of the test file according to the structure object information;
generating a calling code and a verification result code for testing the source file according to the structure object information;
writing the class basic information, the calling code and the verification result code into a file to generate a test file of the source file.
Optionally, the generating module 402 is further configured to:
generating an instance object according to the structural object information;
judging whether the method body of the source file has input parameters and return values;
if the method body of the source file has input parameters and the method body does not return values, generating a calling code for testing the source file according to the instance object and the calling input parameters;
if the method body of the source file has input parameters and the method body has return values, generating a calling code according to the relevant information of the return values, the instance object and the calling input parameters;
if the method body of the source file has no input parameter and the method body has no return value, generating a calling code according to the instance object;
and if the method body of the source file has no input parameter and has a return value, generating a calling code according to the instance object and the related information of the return value.
Optionally, if the method body of the source file has no input parameter and the method body has no return value, the format of the calling code is: instance object method name ();
if the method body of the source file has no input parameter and the method body has a return value, the format of the calling code is as follows: the return value class return value variable name ═ instance object.
If the method body of the source file has input parameters and the method body does not return values, the format of the calling code is as follows: method name (call input parameter);
if the method body of the source file has input parameters and the method body has return values, the format of the calling code is as follows: the return value class return value variable name is the instance object.
Optionally, the generating module 402 is further configured to:
and generating an instance object by adopting the structural object information in a reflection mode.
Optionally, the parsing module 401 is further configured to:
the source file is a java file; parsing the source file includes:
and analyzing the source file by adopting a java analysis tool class.
In the embodiment of the present invention, a source file is first parsed to obtain structure object information related to the structure of the source file. And then generating a test file of the source file according to the structure object information. The implementation method can finish unit test writing on the premise of modifying a small amount of codes, and greatly saves the time for writing the test method main body. Meanwhile, the template can be written according to the custom rules of different clients, and the custom single test requirement can be met.
Fig. 5 shows an exemplary system architecture 500 to which the test method or test apparatus of an embodiment of the invention may be applied.
As shown in fig. 5, the system architecture 500 may include terminal devices 501, 502, 503, a network 504, and a server 505. The network 504 serves to provide a medium for communication links between the terminal devices 501, 502, 503 and the server 505. Network 504 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
The user may use the terminal devices 501, 502, 503 to interact with a server 505 over a network 504 to receive or send messages or the like.
The terminal devices 501, 502, 503 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like. The server 505 may be a server that provides various services.
It should be noted that the testing method provided by the embodiment of the present invention is generally executed by the server 505, and accordingly, the testing apparatus is generally disposed in the server 505.
It should be understood that the number of terminal devices, networks, and servers in fig. 5 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 6, a block diagram of a computer system 600 suitable for use with a terminal device implementing an embodiment of the invention is shown. The terminal device shown in fig. 6 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 6, the computer system 600 includes a Central Processing Unit (CPU)601 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)602 or a program loaded from a storage section 608 into a Random Access Memory (RAM) 603. In the RAM 603, various programs and data necessary for the operation of the system 600 are also stored. The CPU 601, ROM 602, and RAM 603 are connected to each other via a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.
The following components are connected to the I/O interface 605: an input portion 606 including a keyboard, a mouse, and the like; an output portion 607 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage section 608 including a hard disk and the like; and a communication section 609 including a network interface card such as a LAN card, a modem, or the like. The communication section 609 performs communication processing via a network such as the internet. The driver 610 is also connected to the I/O interface 605 as needed. A removable medium 611 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 610 as necessary, so that a computer program read out therefrom is mounted in the storage section 608 as necessary.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure 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 in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 609, and/or installed from the removable medium 611. The computer program performs the above-described functions defined in the system of the present invention when executed by the central processing unit (CP U) 601.
It should be noted that the computer readable medium shown in the present invention can 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 invention, 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 the present invention, 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: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
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 invention. 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 or flowchart illustration, and combinations of blocks in the block diagrams 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.
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be unique and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise: analyzing a source file to acquire structure object information related to the structure of the source file; and generating a test file of the source file according to the structure object information.
In the embodiment of the present invention, a source file is first parsed to obtain structure object information related to the structure of the source file. And then generating a test file of the source file according to the structure object information. The implementation method can finish unit test writing on the premise of modifying a small amount of codes, and greatly saves the time for writing the test method main body. Meanwhile, the template can be written according to the custom rules of different clients, and the custom single test requirement can be met.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (10)

1. A method of testing, comprising:
analyzing a source file to acquire structure object information related to the structure of the source file;
and generating a test file of the source file according to the structure object information.
2. The method of claim 1, wherein the structural object information includes at least one or more of: file information, package-leading information, class name, member variable, method body, and internal attributes of the method body.
3. The method of claim 2, wherein generating the test file of the source file according to the structure object information comprises:
generating class basic information for representing the attribute of the test file according to the structure object information;
generating a calling code and a verification result code for testing the source file according to the structure object information;
writing the class basic information, the calling code and the verification result code into a file to generate a test file of the source file.
4. The method of claim 3, wherein generating calling code for testing the source file according to the structure object information comprises:
generating an instance object according to the structural object information;
judging whether the method body of the source file has input parameters and return values;
if the method body of the source file has input parameters and the method body does not return values, generating a calling code for testing the source file according to the instance object and the calling input parameters; the calling input parameter is generated according to the input parameter of the source file method body;
if the method body of the source file has input parameters and the method body has return values, generating a calling code according to the relevant information of the return values, the instance object and the calling input parameters;
if the method body of the source file has no input parameter and the method body has no return value, generating a calling code according to the instance object;
and if the method body of the source file has no input parameter and has a return value, generating a calling code according to the instance object and the related information of the return value.
5. The method of claim 4, wherein if the method body of the source file has no input parameters and the method body has no return values, the calling code is in the format of: instance object method name ();
if the method body of the source file has no input parameter and the method body has a return value, the format of the calling code is as follows: the return value class return value variable name ═ instance object.
If the method body of the source file has input parameters and the method body does not return values, the format of the calling code is as follows: method name (call input parameter);
if the method body of the source file has input parameters and the method body has return values, the format of the calling code is as follows: the return value class return value variable name is the instance object.
6. The method of claim 4, wherein generating an instance object from the structure object information comprises:
and generating an instance object by adopting the structural object information in a reflection mode.
7. A method as claimed in any one of claims 1 to 6, wherein the source file is a java file; parsing the source file includes:
and analyzing the source file by adopting a java analysis tool class.
8. A test apparatus, comprising:
the analysis module is used for analyzing the source file to acquire structural object information related to the structure of the source file;
and the generating module is used for generating a test file of the source file according to the structural object information.
9. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-7.
10. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-7.
CN202110113640.3A 2021-01-27 2021-01-27 Test method and device Pending CN113760731A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110113640.3A CN113760731A (en) 2021-01-27 2021-01-27 Test method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110113640.3A CN113760731A (en) 2021-01-27 2021-01-27 Test method and device

Publications (1)

Publication Number Publication Date
CN113760731A true CN113760731A (en) 2021-12-07

Family

ID=78786477

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110113640.3A Pending CN113760731A (en) 2021-01-27 2021-01-27 Test method and device

Country Status (1)

Country Link
CN (1) CN113760731A (en)

Similar Documents

Publication Publication Date Title
CN112631590B (en) Component library generation method, device, electronic equipment and computer readable medium
CN113031946A (en) Method and device for rendering page component
CN111309304B (en) Method, device, medium and electronic equipment for generating IDL file
CN113076153A (en) Interface calling method and device
CN116302218B (en) Function information adding method, device, equipment and storage medium
CN111414154A (en) Method and device for front-end development, electronic equipment and storage medium
CN111752644A (en) Interface simulation method, device, equipment and storage medium
CN110888794A (en) Interface test method and device
CN113760731A (en) Test method and device
CN112395194B (en) Method and device for accessing test platform
CN111796865B (en) Byte code file modification method, device, terminal equipment and medium
CN114218313A (en) Data management method, device, electronic equipment, storage medium and product
CN114625458A (en) Page data processing method and device, electronic equipment and storage medium
CN113885841A (en) Script generation method and device, electronic equipment and readable medium
CN112068814A (en) Method, device, system and medium for generating executable file
CN111736805B (en) Method and device for processing Excel table
CN116431108B (en) Object type processing method and device, electronic equipment and storage medium
CN113760706B (en) Webpage debugging method and device
CN113535565B (en) Interface use case generation method, device, equipment and medium
CN113342633B (en) Performance test method and device
CN112688863B (en) Gateway data processing method and device and electronic equipment
CN109376023B (en) Method and equipment for generating calling information and issuing return code group
CN111026666A (en) Test data processing method, device, computer system and medium
CN117271301A (en) Test method, test device, electronic equipment and medium
CN117649459A (en) Image drawing method, data generating method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination