Movatterモバイル変換


[0]ホーム

URL:


CN114185796A - Unit test case automatic generation method, device, device and storage medium - Google Patents

Unit test case automatic generation method, device, device and storage medium
Download PDF

Info

Publication number
CN114185796A
CN114185796ACN202111524683.7ACN202111524683ACN114185796ACN 114185796 ACN114185796 ACN 114185796ACN 202111524683 ACN202111524683 ACN 202111524683ACN 114185796 ACN114185796 ACN 114185796A
Authority
CN
China
Prior art keywords
test case
unit
parameter information
test
file
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
CN202111524683.7A
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.)
Ping An Bank Co Ltd
Original Assignee
Ping An Bank 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 Ping An Bank Co LtdfiledCriticalPing An Bank Co Ltd
Priority to CN202111524683.7ApriorityCriticalpatent/CN114185796A/en
Publication of CN114185796ApublicationCriticalpatent/CN114185796A/en
Pendinglegal-statusCriticalCurrent

Links

Images

Classifications

Landscapes

Abstract

The invention discloses a method, a device, equipment and a storage medium for automatically generating unit test cases, wherein the method comprises the following steps: acquiring a test request of a unit to be tested, wherein the test request comprises basic parameter information of the unit to be tested; analyzing the file compiled by the unit to be tested based on the basic parameter information to obtain parameter information after file analysis; and based on a preset test case template, generating a test case according to the parameter information after the file analysis, and storing the test case according to a pre-specified storage path. Through the mode, the method and the device can automatically inquire the file compiled by the unit to be tested according to the test request, analyze the file to obtain the parameter information required by case generation, and automatically generate the test case of the unit to be tested according to the parameter information.

Description

Method, device and equipment for automatically generating unit test cases and storage medium
Technical Field
The present application relates to the field of computer program testing technologies, and in particular, to a method, an apparatus, a device, and a storage medium for automatically generating unit test cases.
Background
In order to quickly respond to market changes, many companies adopt an agile development mode at present to realize quick iteration, in order to ensure iteration quality, delivery quality is improved through unit testing, interface testing, integration testing and the like in the iteration process, wherein the unit testing is indispensable as a first gateway, otherwise problems can be found after application compiling and releasing are finished, recompiling and releasing are needed after code repairing, time cost is high, and cost is high when BUG is exposed later. At present, in the market, with many mature unit test frameworks such as Junit, TestNG and the like, there are also many Mock frameworks such as PowerMock, EasyMock and the like to realize environment isolation during unit test, when the frameworks are used, testers or developers need to analyze interface method logic, and manually compile unit test cases, in order to ensure case effectiveness, Mock is needed to be performed when resource access or other business logic layers are involved, case execution conditions also need to be manually initiated and then result analysis and judgment are performed, and the labor and time costs are high. Therefore, many companies adopt an automatic means to realize the compiling and the execution of the unit test case, so as to save the development time and the development cost and improve the test efficiency. One method is to analyze a source code structure through a preset unit test standard and perform parameter construction according to an analyzed parameter type of an access parameter, thereby generating a unit test case. The other method is that mock API is obtained by simulating mock aiming at a test database, an embedded relational database comprising the mock API is generated, and when unit test is needed to be carried out on a unit to be tested, the unit to be tested is carried out by adopting the mock API included by the embedded relational database.
The existing unit test case recording and executing technology has the following defects:
the unit test mainly aims at the most basic unit code of the system, and mainly tests from five aspects of an interface, an independent path, error processing, boundary conditions and local data during the test, and the five aspects are used for verifying that the code is in accordance with the design, and meanwhile, the problems can be found in the encoding stage, the defects of leakage to the testing stage are reduced, the testing stage time is shortened, and the delivery efficiency is improved.
The existing BDD-based unit test system is a tool for automatically generating test cases, and mainly has the functions of a UTPJunit component, a UTP Idea plug-in and a UTP unit test platform, wherein the UTP Idea plug-in is used for generating a unit test case template with a UTPJUint style, the specific code logic completely needs manual filling, the workload is large, and the automation rate is low.
Disclosure of Invention
The application provides a method, a device, equipment and a storage medium for automatically generating unit test cases, which are used for solving the problems of low automation rate and excessive human resource occupation of the existing program test method.
In order to solve the technical problem, the application adopts a technical scheme that: the method for automatically generating the unit test case comprises the following steps: acquiring a test request of a unit to be tested, wherein the test request comprises basic parameter information of the unit to be tested; analyzing the file compiled by the unit to be tested based on the basic parameter information to obtain parameter information after file analysis; and based on a preset test case template, generating a test case according to the parameter information after the file analysis, and storing the test case according to a pre-specified storage path.
As a further improvement of the present application, analyzing the file compiled by the unit to be tested based on the basic parameter information to obtain parameter information after file analysis, including: obtaining storage path information of a class required by the current case generation process from the test request; and acquiring the file compiled by the unit to be tested according to the class storage path, and analyzing the file to obtain the parameter information of each method to obtain the parameter information.
As a further improvement of the present application, when the test request further includes database baffle information, generating a test case according to parameter information after file parsing, including: analyzing baffle information of the database to obtain environment debugging information; and generating a test case according to the parameter information, and importing the environment debugging information into a database of the test environment of the test case.
As a further improvement of the application, the method for generating the test case based on the preset test case template according to the parameter information after the file analysis and storing the test case according to the pre-specified storage path comprises the following steps: selecting a matched target test case template from preset test case templates according to the parameter information after file analysis; assigning the parameter information to a target test case template to generate a corresponding test case; and (3) writing test method declarations and executions in the test cases into the automatically generated Java file for saving, and writing simulation data and assertion information in the test cases into the automatically generated xml file for saving.
As a further improvement of the application, the test request comprises Mock parameter information set for the unit to be tested; before generating the test case according to the parameter information after the file analysis, the method further comprises the following steps: and when the pre-specified information needing to perform Mock exists in the parameter information after the file analysis, performing Mock operation on the information needing to perform Mock according to the Mock parameter information and returning a corresponding value.
As a further improvement of the present application, before generating the test case according to the parameter information after the file analysis, the method further includes: and automatically generating a case base class, wherein the case base class stores the initial configuration of the unit to be tested.
As a further improvement of the application, the automatic generation method of the unit test case is realized based on a Sirius plug-in.
In order to solve the above technical problem, another technical solution adopted by the present application is: provided is a unit test case automatic generation device, including: the system comprises an acquisition module, a test module and a test module, wherein the acquisition module is used for acquiring a test request of a unit to be tested, and the test request comprises basic parameter information of the unit to be tested; the analysis module is used for analyzing the file compiled by the unit to be tested based on the basic parameter information to obtain parameter information after file analysis; and the generating module is used for generating a test case according to the parameter information after the file analysis based on a preset test case template, and storing the test case according to a pre-specified storage path.
In order to solve the above technical problem, the present application adopts another technical solution that: there is provided a computer device comprising a processor, a memory coupled to the processor, having stored therein program instructions which, when executed by the processor, cause the processor to carry out the steps of the unit test case automatic generation method according to any one of claims 1-7.
In order to solve the above technical problem, the present application adopts another technical solution that: there is provided a storage medium storing program instructions capable of implementing the above-described method for automatically generating unit test cases.
The beneficial effect of this application is: according to the method for automatically generating the unit test case, after the test request of the unit to be tested is obtained, the file compiled by the unit to be tested is analyzed based on the basic parameter information, the parameter information after the file is analyzed is obtained, the test case is generated according to the parameter information after the file is analyzed, the file compiled by the unit to be tested is automatically inquired according to the test request, the parameter information required by case generation is obtained through analysis, the test case of the unit to be tested is automatically generated according to the parameter information, the whole test case generation process is automatically realized, the defect that the existing unit test case needs to be manually compiled is overcome, and the occupation of manpower resources is reduced.
Drawings
FIG. 1 is a flow chart illustrating a method for automatically generating unit test cases according to a first embodiment of the present invention;
FIG. 2 is a flowchart illustrating a method for automatically generating unit test cases according to a second embodiment of the present invention;
FIG. 3 is a flowchart illustrating a method for automatically generating unit test cases according to a third embodiment of the present invention;
FIG. 4 is a functional block diagram of an automatic unit test case generation apparatus according to an embodiment of the present invention;
FIG. 5 is a schematic structural diagram of a computer device according to an embodiment of the present invention;
fig. 6 is a schematic structural diagram of a storage medium according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The terms "first", "second" and "third" in this application are used for descriptive purposes only and are not to be construed as indicating or implying relative importance or implying any indication of the number of technical features indicated. Thus, a feature defined as "first," "second," or "third" may explicitly or implicitly include at least one of the feature. In the description of the present application, "plurality" means at least two, e.g., two, three, etc., unless explicitly specifically limited otherwise. All directional indications (such as up, down, left, right, front, and rear … …) in the embodiments of the present application are only used to explain the relative positional relationship between the components, the movement, and the like in a specific posture (as shown in the drawings), and if the specific posture is changed, the directional indication is changed accordingly. Furthermore, the terms "include" and "have," as well as any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not limited to only those steps or elements listed, but may alternatively include other steps or elements not listed, or inherent to such process, method, article, or apparatus.
Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the application. The appearances of the phrase in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. It is explicitly and implicitly understood by one skilled in the art that the embodiments described herein can be combined with other embodiments.
Fig. 1 is a flowchart illustrating a method for automatically generating unit test cases according to a first embodiment of the present invention. It should be noted that the method of the present invention is not limited to the flow sequence shown in fig. 1 if the results are substantially the same. As shown in fig. 1, the method comprises the steps of:
step S101: and acquiring a test request of the unit to be tested, wherein the test request comprises basic parameter information of the unit to be tested.
It should be noted that the unit to be tested may be one unit in one item to be tested, and in general, one item to be generated may include a plurality of services, and one service includes a plurality of test objects. For example, a to-be-generated item may include a login service, a registration service, an upload service, and so on. If a certain service in the item to be generated is required to be tested, namely a test request of the item to be generated exists, a unit to be tested related to the test request of the item to be generated is obtained, and the test request is initiated to the unit to be tested, so that a corresponding test case of the request to be tested can be automatically generated. It should be understood that, in this embodiment, batch test case generation for multiple units to be tested can be simultaneously implemented.
Further, in this embodiment, the automatic generation method of the unit test case is implemented based on a Sirius plugin.
Specifically, the Sirius plug-in provides a visual information configuration interface for the generation process of the test case, and through the information configuration interface, a user can conveniently input a test request to generate the test case. It can be understood that, in this embodiment, automatic generation of the test case is realized by using the Sirius plugin, which does not need to use a third-party tool, so that the possibility of source code leakage is reduced, and the graphical operation interface provided by the Sirius plugin greatly optimizes the operation experience of a user, and is convenient to use and high in efficiency.
Step S102: and analyzing the file compiled by the unit to be tested based on the basic parameter information to obtain the parameter information after the file analysis.
Specifically, after a test request is obtained, basic parameter information of a unit to be tested and case parameter information of a generated case are obtained according to the test request, the basic parameter information includes a storage path of the unit to be tested, a file generated after the unit to be tested is compiled can be found through the storage path, and the parameter information required for generating the test case is obtained through analyzing the file.
Further, in some embodiments, step S102 specifically includes:
1. and acquiring the storage path of the class required by the current case generation process from the test request.
Furthermore, the number of CPU cores, the memory occupied, the classes and the number of the classes of the test cases to be generated, the storage path of the generated test cases, whether to generate the baffle information of the database, the mode information of the test cases, the default parameter information, and the like, which are required in the current case generation process, are also acquired from the test request.
Specifically, the parameters in the test request may be obtained through a script command input in advance, for example, the following script command is taken as an example for description: mvn-dmemoryiinmb ═ 2048-dcors ═ 2-Dcuts ═ xxx.xxx.xxx.xxx.xxx-xxx-DtargetFolder ═ src/test/java-dspringdunick ═ false-DtestMode ═ powermockranner sirius: clean sirius: general site: the port of the transport unit is connected with the transport unit, wherein, DmoryInMB 2048 means that the required occupied content is 2048Mb, Dcorps 2 means that the required number of CPU cores is 2, and Dcuts xxx refers to the class, the number of classes and the storage path of the class which are required to generate the test case, when a plurality of classes exist, the classes can be separated by using English commas, DtargetFolder refers to src/test/java and refers to a storage path of a generated test case, DSpringDBLock refers to whether database baffle information needs to be generated, when DSpringDBLock refers to false, i.e., no database fence information needs to be generated, when DSpringDBMock is equal to true, that is, the baffle information of the database needs to be generated, DtestMode ═ powermockranner refers to the mode of the test case, sirius: general site: export refers to the default parameters of a Sirius plug-in.
2. And acquiring the file compiled by the unit to be tested according to the class storage path, and analyzing the file to obtain the parameter information of each method to obtain the parameter information.
Specifically, according to the storage path of the acquired class, a file generated after the unit to be tested is compiled is acquired, the content in the file is identified so as to obtain import content, class declaration, method declaration, annotation, interface injection and other related information, the information is respectively extracted into corresponding sets, each method in the file, namely related information such as method parameters, parameter types, interfaces used in the method, static classes, method calls and the like, is analyzed and used as parameter information obtained through analysis.
Step S103: and based on a preset test case template, generating a test case according to the parameter information after the file analysis, and storing the test case according to a pre-specified storage path.
It should be noted that, the tester develops various test case templates in advance according to the daily test requirements, and a corresponding test case program can be generated through the test case templates. Specifically, when parameter information is obtained by analyzing the compiled file, the test case of the unit to be tested can be automatically generated by assigning the parameter information to the corresponding test case template, and then the test case is stored according to the case storage path specified in the case parameter information, so that the test case of the unit to be tested is automatically generated.
Further, in some embodiments, when the BBD unit test system is used, the BDD-based test case does not completely test our minimum code unit, and tests a similar scenario, although a jmoclit generating barrier is also used, but does not implement a static method, a Mock of a private method, and therefore, when the test request further includes database barrier information, step S103 specifically includes:
1. analyzing baffle information of the database to obtain environment debugging information;
it should be noted that the baffle test can be understood as follows: in some cross-system performance test projects, due to the limitation of objective factors (limited test hardware resources, coordination among multiple systems, and the like), a complete test environment cannot be built to complete the test work, at this time, a system to be tested is generally built, and then functions of other related systems are simulated by adopting a software program, which is generally called a baffle. Further, the baffle may also be referred to as an "off-line system," "sandbox system," or the like.
2. And generating a test case according to the parameter information, and importing the environment debugging information into a database of the test environment of the test case.
Specifically, after the database baffle information is obtained, a corresponding test baffle is generated according to the database baffle information, that is, the environment debugging information obtained from the database baffle information is written into the database of the test environment of the test case, and when the test case is executed, the test environment of the test case is generated according to the environment debugging information.
In this embodiment, the unit to be tested of the database barrier information in the test request is usually a static type or private method, so that the barrier function is realized for the static type and the private method, and the barrier can be configured in various ways according to the requirements of the user and realized by a Sirius plug-in, and the mock configuration process is more convenient and flexible due to the provided graphical interface.
Further, in some embodiments, in order to facilitate the user to manage the test case, step S103 specifically includes:
1. selecting a matched target test case template from preset test case templates according to the parameter information after file analysis;
2. assigning the parameter information to a target test case template to generate a corresponding test case;
3. and (3) writing test method declarations and executions in the test cases into the automatically generated Java file for saving, and writing simulation data and assertion information in the test cases into the automatically generated xml file for saving.
Specifically, the test case templates are preset for the testers, wherein the test case templates include case templates for different test requirements, so that in order to realize automatic generation of test cases, parameter information obtained through analysis is respectively matched with the test case templates, and an optimal test case template is selected as a target test case template to generate the test cases.
In this embodiment, after the test case is generated according to the parameter information, in order to facilitate management of the test case, data in the test case is divided into two parts for storage, where one part is a test method declaration and execution data in the test case, and the part is written into an automatically generated Java file for storage, and a simulation data and assertion information in the other part are written into an automatically generated xml file for storage, so that a user manages the test case.
The automatic generation method of the unit test case of the first embodiment of the invention obtains the test request of the unit to be tested, analyzes the file compiled by the unit to be tested based on the basic parameter information to obtain the parameter information after the file is analyzed, then generates the test case according to the parameter information after the file is analyzed, automatically queries the file compiled by the unit to be tested according to the test request, then analyzes to obtain the parameter information required by the case generation, and then automatically generates the test case of the unit to be tested according to the parameter information.
Fig. 2 is a flowchart illustrating a method for automatically generating unit test cases according to a second embodiment of the present invention. It should be noted that the method of the present invention is not limited to the flow sequence shown in fig. 2 if the results are substantially the same. As shown in fig. 2, the method comprises the steps of:
step S201: and acquiring a test request of the unit to be tested, wherein the test request comprises basic parameter information of the unit to be tested.
In this embodiment, step S201 in fig. 2 is similar to step S101 in fig. 1, and for brevity, is not described herein again.
Step S202: and analyzing the file compiled by the unit to be tested based on the basic parameter information to obtain the parameter information after the file analysis.
In this embodiment, step S202 in fig. 2 is similar to step S102 in fig. 1, and for brevity, is not described herein again.
Step S203: and when the pre-specified information needing to perform Mock exists in the parameter information after the file analysis, performing Mock operation on the information needing to perform Mock according to the Mock parameter information and returning a corresponding value.
It should be noted that, in this embodiment, the test request includes Mock parameter information set for the unit to be tested.
Specifically, when there is information that needs to be Mock operated in the parameter information after file analysis, the Mock operation needs to be performed on the information that needs to be Mock according to the Mock parameter information in the case parameters, and a corresponding value is returned for use in generating the test case.
It should be noted that Mock refers to a test method for creating a virtual object for testing some objects that are not easily constructed or easily obtained during the test process. For example, an alarm clock performs a reminding service according to time, if 5 pm later, an audio file is played to remind people of going to work, if a real object is used for testing, the test can be realized only by waiting for five pm, and in order to avoid the situation, a mock object can be used for testing, so that the control time is simulated without waiting for the clock to turn to 5 pm.
Step S204: and based on a preset test case template, generating a test case according to the parameter information after the file analysis, and storing the test case according to a pre-specified storage path.
In this embodiment, step S204 in fig. 2 is similar to step S103 in fig. 1, and for brevity, is not described herein again.
According to the automatic generation method of the unit test case, on the basis of the first embodiment, when the fact that information needing to be subjected to Mock exists in the analyzed parameter information is determined, a corresponding value is returned after Mock operation is carried out according to the Mock parameter information, and the returned value is used for generating the test case, so that the generated test case can be configured more flexibly.
Fig. 3 is a flowchart illustrating a method for automatically generating unit test cases according to a third embodiment of the present invention. It should be noted that the method of the present invention is not limited to the flow sequence shown in fig. 3 if the results are substantially the same. As shown in fig. 3, the method comprises the steps of:
step S301: and acquiring a test request of the unit to be tested, wherein the test request comprises basic parameter information of the unit to be tested.
In this embodiment, step S301 in fig. 3 is similar to step S101 in fig. 1, and for brevity, is not described herein again.
Step S302: and analyzing the file compiled by the unit to be tested based on the basic parameter information to obtain the parameter information after the file analysis.
In this embodiment, step S302 in fig. 3 is similar to step S102 in fig. 1, and for brevity, is not described herein again.
Step S303: and automatically generating a case base class, wherein the case base class stores the initial configuration of the unit to be tested.
Specifically, when a test case is generated, a base class needs to be generated to store the initialization configuration of the unit to be tested, and when a test is executed, the initialization configuration of the unit to be tested is completed according to the initialization configuration information. In this embodiment, the case base class is a baseunit base class.
Step S304: and based on a preset test case template, generating a test case according to the parameter information after the file analysis, and storing the test case according to a pre-specified storage path.
In this embodiment, step S304 in fig. 3 is similar to step S103 in fig. 1, and for brevity, is not described herein again.
The method for automatically generating the unit test case according to the third embodiment of the present invention is based on the first embodiment, and automatically generates the case base class of the test case when the test case is generated, so as to store the initialization configuration of the automatically generated test case, and automatically configures the relevant parameters in the test case according to the initialization configuration when the test case is subsequently used, without manual configuration.
Fig. 4 is a functional module diagram of an automatic unit test case generation apparatus according to an embodiment of the present invention. As shown in fig. 4, theapparatus 40 includes an obtaining module 41, an analyzingmodule 42, and agenerating module 43.
An obtaining module 41, configured to obtain a test request of a unit to be tested, where the test request includes basic parameter information of the unit to be tested;
theanalysis module 42 is configured to analyze the file compiled by the unit to be tested based on the basic parameter information to obtain parameter information after file analysis;
and the generatingmodule 43 is configured to generate a test case according to the parameter information after the file analysis based on a preset test case template, and store the test case according to a pre-specified storage path.
Optionally, the analyzingmodule 42 executes an operation of analyzing the file compiled by the unit to be tested based on the basic parameter information to obtain parameter information after file analysis, which specifically includes: obtaining a storage path of a class required by the current case generation process from the test request; and acquiring the file compiled by the unit to be tested according to the class storage path, and analyzing the file to obtain the parameter information of each method to obtain the parameter information.
Optionally, when the test request further includes database baffle information, the generatingmodule 43 executes an operation of generating a test case according to the parameter information after the file analysis, which specifically includes: analyzing baffle information of the database to obtain environment debugging information; and generating a test case according to the parameter information, and importing the environment debugging information into a database of the test environment of the test case.
Optionally, the generatingmodule 43 executes an operation of generating a test case based on a preset test case template according to the parameter information after the file analysis, and saving the test case according to a pre-specified storage path, and may further include: selecting a matched target test case template from preset test case templates according to the parameter information after file analysis; assigning the parameter information to a target test case template to generate a corresponding test case; and (3) writing test method declarations and executions in the test cases into the automatically generated Java file for saving, and writing simulation data and assertion information in the test cases into the automatically generated xml file for saving.
Optionally, the test request includes Mock parameter information set for the unit to be tested, and before the generatingmodule 43 executes the operation of generating the test case according to the parameter information after the file analysis, the generating module is further configured to: and when the pre-specified information needing to perform Mock exists in the parameter information after the file analysis, performing Mock operation on the information needing to perform Mock according to the Mock parameter information and returning a corresponding value.
Optionally, before the generatingmodule 43 performs the operation of generating the test case according to the parameter information after the file parsing, it is further configured to: and automatically generating a case base class, wherein the case base class stores the initial configuration of the unit to be tested.
Optionally, the automatic generation method of the unit test case is implemented based on a Sirius plug-in.
For other details of the technical solution implemented by each module in the automatic generation apparatus for unit test cases in the above embodiments, reference may be made to the description of the automatic generation method for unit test cases in the above embodiments, and details are not described herein again.
It should be noted that, in the present specification, the embodiments are all described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments may be referred to each other. For the device-like embodiment, since it is basically similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
Referring to fig. 5, fig. 5 is a schematic structural diagram of a computer device according to an embodiment of the present invention. As shown in fig. 5, thecomputer device 50 includes aprocessor 51 and amemory 52 coupled to theprocessor 51, wherein thememory 52 stores program instructions, and the program instructions, when executed by theprocessor 51, cause theprocessor 51 to execute the steps of the automatic generation method of unit test cases according to any of the embodiments.
Theprocessor 51 may also be referred to as a CPU (Central Processing Unit). Theprocessor 51 may be an integrated circuit chip having signal processing capabilities. Theprocessor 51 may also be a general purpose processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
Referring to fig. 6, fig. 6 is a schematic structural diagram of a storage medium according to an embodiment of the invention. The storage medium of the embodiment of the present inventionstores program instructions 61 capable of implementing all the methods described above, where theprogram instructions 61 may be stored in the storage medium in the form of a software product, and include several instructions to enable a computer device (which may be a personal computer, a server, or a network device) or a processor (processor) to execute all or part of the steps of the methods described in the embodiments of the present application. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, or computer equipment, such as a computer, a server, a mobile phone, and a tablet.
In the several embodiments provided in the present application, it should be understood that the disclosed computer apparatus, device and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, a division of a unit is merely a logical division, and an actual implementation may have another division, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit. The above embodiments are merely examples and are not intended to limit the scope of the present disclosure, and all modifications, equivalents, and flow charts using the contents of the specification and drawings of the present disclosure or those directly or indirectly applied to other related technical fields are intended to be included in the scope of the present disclosure.

Claims (10)

Translated fromChinese
1.一种单元测试案例自动生成方法,其特征在于,包括:1. a unit test case automatic generation method, is characterized in that, comprises:获取待测试单元的测试请求,所述测试请求包括所述待测试单元的基本参数信息;Obtain a test request of the unit to be tested, where the test request includes basic parameter information of the unit to be tested;基于所述基本参数信息解析所述待测试单元编译后的文件,得到所述文件解析后的参数信息;Parse the compiled file of the unit to be tested based on the basic parameter information, and obtain the parsed parameter information of the file;基于预设的测试案例模板,根据所述文件解析后的参数信息生成测试案例,并将所述测试案例按预先指定的存储路径进行保存。Based on a preset test case template, a test case is generated according to the parsed parameter information of the file, and the test case is saved in a pre-specified storage path.2.根据权利要求1所述的单元测试案例自动生成方法,其特征在于,所述基于所述基本参数信息解析所述待测试单元编译后的文件,得到所述文件解析后的参数信息,包括:2. The method for automatically generating a unit test case according to claim 1 , wherein the compiled file of the unit to be tested is parsed based on the basic parameter information, and the parsed parameter information of the file is obtained, comprising: :从所述测试请求中获取当前案例生成过程所需的类的存储路径;Obtain the storage path of the class required by the current case generation process from the test request;按照所述类的存储路径,获取所述待测试单元编译后的文件,并从所述文件中解析得到每个方法的参数信息,得到所述参数信息。According to the storage path of the class, the compiled file of the unit to be tested is obtained, and the parameter information of each method is obtained by parsing the file to obtain the parameter information.3.根据权利要求2所述的单元测试案例自动生成方法,其特征在于,当所述测试请求中还包括数据库挡板信息时,所述根据所述文件解析后的参数信息生成测试案例,包括:3. The method for automatically generating a unit test case according to claim 2, wherein when the test request also includes database baffle information, the test case is generated according to the parsed parameter information of the file, comprising: :解析所述数据库挡板信息得到环境调试信息;Parse the database baffle information to obtain environment debugging information;根据所述参数信息生成所述测试案例,并将所述环境调试信息导入至所述测试案例的测试环境的数据库中。The test case is generated according to the parameter information, and the environment debugging information is imported into the database of the test environment of the test case.4.根据权利要求1所述的单元测试案例自动生成方法,其特征在于,所述基于预设的测试案例模板,根据所述文件解析后的参数信息生成测试案例,并将所述测试案例按预先指定的存储路径进行保存,包括:4. The method for automatically generating a unit test case according to claim 1, wherein the test case is generated based on the preset test case template according to the parameter information after the file is parsed, and the test case is Pre-specified storage path for saving, including:根据所述文件解析后的参数信息从预设的测试案例模板中选取匹配的目标测试案例模板;Select a matching target test case template from the preset test case template according to the parsed parameter information of the file;将所述参数信息赋值给所述目标测试案例模板,以生成对应的所述测试案例;Assign the parameter information to the target test case template to generate the corresponding test case;将所述测试案例中的测试方法声明和执行写入自动生成的Java文件保存,且将所述测试案例中的模拟数据和断言信息写入自动生成的xml文件保存。Write the test method declaration and execution in the test case into an automatically generated Java file for saving, and write the simulation data and assertion information in the test case into an automatically generated xml file for saving.5.根据权利要求1所述的单元测试案例自动生成方法,其特征在于,所述测试请求包括为所述待测试单元设定的Mock参数信息;所述根据所述文件解析后的参数信息生成测试案例之前,还包括:5. The method for automatically generating a unit test case according to claim 1, wherein the test request includes Mock parameter information set for the unit to be tested; the generation of the parsed parameter information according to the file Before the test case, also include:当所述文件解析后的参数信息中存在预先指定的需要进行Mock的信息时,根据所述Mock参数信息对所述需要进行Mock的信息进行Mock操作并返回相应的值。When there is pre-specified information that needs to be mocked in the parsed parameter information of the file, a Mock operation is performed on the information that needs to be mocked according to the Mock parameter information, and a corresponding value is returned.6.根据权利要求1所述的单元测试案例自动生成方法,其特征在于,所述根据所述文件解析后的参数信息生成测试案例之前,还包括:6. The method for automatically generating a unit test case according to claim 1, wherein before the test case is generated according to the parsed parameter information of the file, the method further comprises:自动生成案例基类,所述案例基类存储所述待测试单元的初始化配置。A case base class is automatically generated, and the case base class stores the initialization configuration of the unit to be tested.7.根据权利要求1所述的单元测试案例自动生成方法,其特征在于,所述单元测试案例自动生成方法基于Sirius插件实现。7. The method for automatically generating unit test cases according to claim 1, wherein the method for automatically generating unit test cases is implemented based on a Sirius plug-in.8.一种单元测试案例自动生成装置,其特征在于,包括:8. A device for automatically generating unit test cases, comprising:获取模块,用于获取待测试单元的测试请求,所述测试请求包括所述待测试单元的基本参数信息;an acquisition module, configured to acquire a test request of the unit to be tested, where the test request includes basic parameter information of the unit to be tested;解析模块,用于基于所述基本参数信息解析所述待测试单元编译后的文件,得到所述文件解析后的参数信息;A parsing module, configured to parse the compiled file of the unit to be tested based on the basic parameter information to obtain the parsed parameter information of the file;生成模块,用于基于预设的测试案例模板,根据所述文件解析后的参数信息生成测试案例,并将所述测试案例按预先指定的存储路径进行保存。The generating module is configured to generate a test case according to the parsed parameter information of the file based on a preset test case template, and save the test case according to a pre-specified storage path.9.一种计算机设备,其特征在于,所述计算机设备包括处理器、与所述处理器耦接的存储器,所述存储器中存储有程序指令,所述程序指令被所述处理器执行时,使得所述处理器执行如权利要求1-7中任一项权利要求所述的单元测试案例自动生成方法的步骤。9. A computer device, characterized in that the computer device comprises a processor and a memory coupled to the processor, wherein program instructions are stored in the memory, and when the program instructions are executed by the processor, The processor is caused to perform the steps of the method for automatically generating a unit test case according to any one of claims 1-7.10.一种存储介质,其特征在于,存储有能够实现如权利要求1-7中任一项所述的单元测试案例自动生成方法的程序指令。10. A storage medium, characterized in that it stores program instructions capable of implementing the method for automatically generating a unit test case according to any one of claims 1-7.
CN202111524683.7A2021-12-142021-12-14 Unit test case automatic generation method, device, device and storage mediumPendingCN114185796A (en)

Priority Applications (1)

Application NumberPriority DateFiling DateTitle
CN202111524683.7ACN114185796A (en)2021-12-142021-12-14 Unit test case automatic generation method, device, device and storage medium

Applications Claiming Priority (1)

Application NumberPriority DateFiling DateTitle
CN202111524683.7ACN114185796A (en)2021-12-142021-12-14 Unit test case automatic generation method, device, device and storage medium

Publications (1)

Publication NumberPublication Date
CN114185796Atrue CN114185796A (en)2022-03-15

Family

ID=80543652

Family Applications (1)

Application NumberTitlePriority DateFiling Date
CN202111524683.7APendingCN114185796A (en)2021-12-142021-12-14 Unit test case automatic generation method, device, device and storage medium

Country Status (1)

CountryLink
CN (1)CN114185796A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN115509923A (en)*2022-09-292022-12-23平安银行股份有限公司Unit test case generation method and device and computer storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN107844421A (en)*2017-10-312018-03-27平安科技(深圳)有限公司Interface test method, device, computer equipment and storage medium
CN109947646A (en)*2019-03-132019-06-28平安信托有限责任公司Interface test method, device, computer equipment and storage medium
CN110750442A (en)*2019-09-062020-02-04平安医疗健康管理股份有限公司Test case generation method, device, equipment and storage medium
CN111209195A (en)*2019-12-302020-05-29瑞庭网络技术(上海)有限公司Method and device for generating test case

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN107844421A (en)*2017-10-312018-03-27平安科技(深圳)有限公司Interface test method, device, computer equipment and storage medium
CN109947646A (en)*2019-03-132019-06-28平安信托有限责任公司Interface test method, device, computer equipment and storage medium
CN110750442A (en)*2019-09-062020-02-04平安医疗健康管理股份有限公司Test case generation method, device, equipment and storage medium
CN111209195A (en)*2019-12-302020-05-29瑞庭网络技术(上海)有限公司Method and device for generating test case

Cited By (1)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN115509923A (en)*2022-09-292022-12-23平安银行股份有限公司Unit test case generation method and device and computer storage medium

Similar Documents

PublicationPublication DateTitle
CN112270149B (en)Verification platform automatic integration method and system, electronic equipment and storage medium
US8924937B1 (en)Method and system for generating verification information and tests for software
CN110008113B (en)Test method and device and electronic equipment
US9202005B2 (en)Development and debug environment in a constrained random verification
EP2572294B1 (en)System and method for sql performance assurance services
CN111832236A (en) A chip regression test method, system, electronic device and storage medium
CN108345532A (en)A kind of automatic test cases generation method and device
US10176078B1 (en)Debugging process
US10592703B1 (en)Method and system for processing verification tests for testing a design under test
CN111026670B (en) Test case generation method, test case generation device and storage medium
CN108809755B (en)Automatic testing method and system for home gateway compatible with command line and WEB interface
CN114297961A (en) A chip test case processing method and related device
CN117493188A (en) Interface testing methods and devices, electronic equipment and storage media
CN110309046A (en) modeling system
Engels et al.Model-based verification and validation of properties
CN112241373A (en) Automated test method, test apparatus, processor and test system
CN115809076A (en) ECU software automation integration method and system
CN114185796A (en) Unit test case automatic generation method, device, device and storage medium
CN117892665B (en)Modeling simulation method, device, medium and equipment based on circuit system level model
CN117873874A (en)Interface element positioning method, system, medium and electronic equipment
CN117931623A (en)Semiconductor parameter testing method and system based on interpreted high-level language
CN116185826A (en)Test method, device, equipment and storage medium
RU2729210C1 (en)Electronic devices software testing system
CN114579470A (en) A unit testing method, device, electronic device and storage medium
CN112328281A (en) Method and device for refreshing server firmware

Legal Events

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

[8]ページ先頭

©2009-2025 Movatter.jp