CN112380118A - Unit testing method, unit testing device, medium and electronic equipment - Google Patents
Unit testing method, unit testing device, medium and electronic equipment Download PDFInfo
- Publication number
- CN112380118A CN112380118A CN202011257340.4A CN202011257340A CN112380118A CN 112380118 A CN112380118 A CN 112380118A CN 202011257340 A CN202011257340 A CN 202011257340A CN 112380118 A CN112380118 A CN 112380118A
- Authority
- CN
- China
- Prior art keywords
- input parameter
- code
- parameter data
- methods
- test
- 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
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Preventing errors by testing or debugging software
- G06F11/3668—Software testing
- G06F11/3672—Test management
- G06F11/3688—Test management for test execution, e.g. scheduling of test suites
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Computer Hardware Design (AREA)
- Quality & Reliability (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Debugging And Monitoring (AREA)
Abstract
The application relates to the field of software function testing, and discloses a unit testing method, a unit testing device, a unit testing medium and electronic equipment. The method comprises the following steps: establishing a data model, wherein the logic structure of the data model corresponds to the incidence relation among the methods in the service logic code to be tested, the data model comprises input parameter data corresponding to the parameters of the methods in the service logic code, and the data model is used for transmitting the input parameter data to the unit test code when the service logic code is subjected to unit test; and acquiring input parameter data provided by the data model, and transmitting the input parameter data as an input parameter into a written unit test code so as to perform unit test on the business logic code. Under the method, the construction of parameter data does not need to be carried out for each class or method when the unit test is carried out, the development and test cost is reduced, and the efficiency is improved.
Description
Technical Field
The present disclosure relates to the field of software functional testing technologies, and in particular, to a unit testing method, an apparatus, a medium, and an electronic device.
Background
Unit testing is an important method in developing code for checking the changing effect of code. The method avoids the situation that the original function is influenced by newly added logic, developers do not know the logic, the testing environment defect is caused, and even production accidents are caused. Unit testing is to verify whether the logic of individual methods in the system is designed. The unit test of a system is completely covered, when new changes are added, developers complete the development and complete the unit test, then all the unit tests are executed, and if problems occur, the situation that the original functions are unavailable due to the modification is explained. An efficient unit test can improve development quality assurance.
The traditional unit test is independently coded according to each method, so that the parameter entering structure is needed for each class, the test result structure is needed when the test result is verified, a large amount of manpower is needed when the unit test is compiled, when a data structure is changed, a large amount of parameter entering of the unit test is needed to be modified, manpower waste can be caused, meanwhile, omission easily occurs, repeated modification can cause the waste of development resources, the efficiency is low, and the development cost is high.
Disclosure of Invention
In the field of software testing technologies, to solve the above technical problems, an object of the present application is to provide a unit testing method, apparatus, medium, and electronic device.
According to an aspect of the present application, there is provided a unit testing method, the method including:
establishing a data model, wherein the logic structure of the data model corresponds to the incidence relation among the methods in the service logic code to be tested, the data model comprises input parameter data corresponding to the parameters of the methods in the service logic code, and the data model is used for transmitting the input parameter data to the unit test code when the service logic code is subjected to unit test;
and acquiring input parameter data provided by the data model, and transmitting the input parameter data as an input parameter into a written unit test code so as to perform unit test on the business logic code.
According to another aspect of the present application, there is provided a unit testing apparatus, the apparatus including:
the data model establishing module is configured to establish a data model, a logic structure of the data model corresponds to an incidence relation among methods in a service logic code to be tested, the data model comprises input parameter data corresponding to parameters of the methods in the service logic code, and the data model is used for transmitting the input parameter data to a unit test code when the service logic code is subjected to unit test;
and the input parameter data acquisition module is configured to acquire the input parameter data provided by the data model and use the input parameter data as an input parameter to transmit the written unit test code so as to perform unit test on the business logic code.
According to another aspect of the present application, there is provided a computer readable program medium storing computer program instructions which, when executed by a computer, cause the computer to perform the method as previously described.
According to another aspect of the present application, there is provided an electronic device including:
a processor;
a memory having computer readable instructions stored thereon which, when executed by the processor, implement the method as previously described.
The technical scheme provided by the embodiment of the application can have the following beneficial effects:
for the unit testing method, device, medium and electronic device provided by the application, the method comprises the following steps: establishing a data model, wherein the logic structure of the data model corresponds to the incidence relation among the methods in the service logic code to be tested, the data model comprises input parameter data corresponding to the parameters of the methods in the service logic code, and the data model is used for transmitting the input parameter data to the unit test code when the service logic code is subjected to unit test; and acquiring input parameter data provided by the data model, and transmitting the input parameter data as an input parameter into a written unit test code so as to perform unit test on the business logic code.
The method constructs the data model, makes the logic structure of the data model correspond to the incidence relation among the methods in the business logic code, and simultaneously utilizes the data model to maintain and provide the parameter data required by the unit test, so that the construction of the parameter data for each class or method is not required when the unit test is carried out, the development and test cost is reduced, and the efficiency is improved.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the invention, as claimed.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and together with the description, serve to explain the principles of the invention.
FIG. 1 is a system architecture diagram illustrating a method of unit testing in accordance with an exemplary embodiment;
FIG. 2 is a flow chart illustrating a method of unit testing according to an exemplary embodiment;
FIG. 3 is a detailed flow diagram of step 220 according to one embodiment shown in a corresponding embodiment in FIG. 2;
FIG. 4 is a detailed flowchart of step 220 of another embodiment, shown in accordance with the corresponding embodiment of FIG. 2;
FIG. 5 is an overall process diagram illustrating an application unit testing method according to an exemplary embodiment;
FIG. 6 is an overall process diagram illustrating an application unit testing method in a multi-system scenario in accordance with an exemplary embodiment;
FIG. 7 is a block diagram illustrating a unit testing device according to an exemplary embodiment;
FIG. 8 is a block diagram illustrating an example of an electronic device implementing the above-described unit testing method in accordance with one illustrative embodiment;
FIG. 9 illustrates a program product for implementing the above-described cell testing method, according to an exemplary embodiment.
Detailed Description
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the invention, as detailed in the appended claims.
Furthermore, the drawings are merely schematic illustrations of the present application and are not necessarily drawn to scale. The same reference numerals in the drawings denote the same or similar parts, and thus their repetitive description will be omitted. Some of the block diagrams shown in the figures are functional entities and do not necessarily correspond to physically or logically separate entities.
The present application first provides a unit testing method. Unit testing refers to checking and verifying the smallest unit under test in a software or program. Typically, the smallest unit of testability in a software or program is a method. In C language, the method herein may be equivalent to a function; in the Java language, the methods correspond to those in classes. The unit testing method can efficiently complete unit testing.
The implementation terminal of the present application may be any device having computing, processing, and communication functions, and the device may be connected to an external device for receiving or sending data, and specifically may be a portable mobile device, such as a smart phone, a tablet computer, a notebook computer, a pda (personal Digital assistant), or the like, or may be a fixed device, such as a computer device, a field terminal, a desktop computer, a server, a workstation, or the like, or may be a set of multiple devices, such as a physical infrastructure of cloud computing or a server cluster.
Optionally, the implementation terminal of the present application may be a server or a physical infrastructure of cloud computing.
FIG. 1 is a system architecture diagram illustrating a method of unit testing, according to an example embodiment. As shown in FIG. 1, the system architecture includes a personal computer 110 and a server 120, which are coupled via a communication link between the personal computer 110 and the server 120 and can be used to send or receive data. The personal computer 110 is an implementation terminal in the embodiment, and the personal computer 110 is deployed with service logic codes and written unit test codes for testing the service logic codes. When a unit testing method provided by the present application is applied to the system architecture shown in fig. 1, a process may be as follows: firstly, a user establishes a data model by operating the personal computer 110, makes the logic structure of the data model correspond to the incidence relation among the methods in the business logic code, and maintains input parameter data corresponding to the parameters of the methods in the business logic code in the data model; the user then persists the data model to the server 120; finally, when a unit test is to be performed on the business logic code on the personal computer 110, the unit test can be performed on the business logic code by obtaining input parameter data from the data model on the server 120 and passing the input parameter data as input parameters into the unit test code.
It is worth mentioning that fig. 1 is only one embodiment of the present application. Although the implementation terminal in this embodiment is a personal computer, in other embodiments, the implementation terminal may be various terminals or devices as described above; although in this embodiment the data model is located on a server external to the implementing terminal and the input parameter data is also obtained from a terminal external to the implementing terminal, in other embodiments or specific applications, the data model may be located locally to the implementing terminal, that is, the input parameter data may be obtained directly from the local. The present application is not limited in this respect, and the scope of protection of the present application should not be limited thereby.
FIG. 2 is a flow chart illustrating a method of unit testing according to an exemplary embodiment. The unit testing method provided by this embodiment may be executed by a server, as shown in fig. 2, and includes the following steps:
step S210, establishing a data model, wherein the logic structure of the data model corresponds to the incidence relation among the methods in the service logic code to be tested, the data model comprises input parameter data corresponding to the parameters of the methods in the service logic code, and the data model is used for transmitting the input parameter data to the unit test code when the service logic code is subjected to unit test.
The business logic code may be written in various languages for various scenarios or services, for example, the business logic code may be code written in C language, Python language, or Java language for an online loan process.
The built internal logic structure of the data model is a mapping corresponding to the relationship among the methods in the business logic code, so that the data model can transmit input parameter data according to the relationship among the methods in the business logic code, and provides data support for unit test of the business logic code.
The parameters of each method are names of the parameters listed when each method is defined, which are equivalent to form parameters, all of which have corresponding parameter types, and the parameter data corresponding to the parameters are actual parameter values.
The business logic code comprises a plurality of methods, the methods can realize specific functions, the methods determine the operation executed by the business logic code, and a plurality of methods are called mutually, for example, the method A calls the method B, and the method B calls the method C. If the method a in the service logic code is to be executed completely, the method C needs to be executed first to obtain an output result of the method C, then the output result is input to the method B to obtain an output result of the method B, and finally the method a in the service logic code is executed based on the output result of the method B. And when the method is called, corresponding values are transmitted according to the parameters of the method.
In the java language, for example, the methods may be in classes.
The input parameter data corresponding to the parameters of each method in the service logic code can be added, deleted or modified by maintaining the data model, specifically, a corresponding UI (user interface) can be established for the data model, and a user interacts with the data model through the UI, so that the data model is maintained.
Specifically, the data model can be established according to requirements, the service logic code can be written based on the data model and the requirements after the data model is established, and the unit test code is correspondingly written and generated according to the service logic code; of course, the order of writing the business logic codes and the unit test codes may also be changed, for example, after the data model is established, the unit test codes may be written based on the data model and the requirements, and then the corresponding business logic codes may be written according to the data model, the requirements, and/or the unit test codes.
In one embodiment, the establishing the data model includes:
acquiring required document text information;
analyzing the required document text information by using a deep learning model, and establishing a data model comprising input parameter data based on an analysis result, wherein the business logic code is compiled according to the required document text information and the data model.
Specifically, a deep learning model can be trained in advance by using a large number of data sets, each data set comprises a requirement document and corresponding business logic codes, each business logic code comprises a plurality of interrelated methods and parameters required by each method, and therefore, the deep learning model can be used for learning the methods, the relationships among the methods and the parameters of the methods which need to be established and are determined based on the requirement documents.
The requirement document text information provides development requirement information of the business logic code, specifically comprises contents such as function points, the requirement document text information can be analyzed by using the deep learning model to obtain specific information related to the establishment of the data model, the specific information comprises a mode of establishing mapping corresponding to incidence relations among methods in the business logic code, a mode of establishing input parameter data corresponding to parameters of the methods in the business logic code, and the like, therefore, a data model can be established based on the analysis result of the requirement document text information, the requirement document text information and the data model can provide guidance information for writing the business logic code, and developers can write the business logic code based on the requirement document text information and the data model.
Step S220, obtaining input parameter data provided by the data model, and using the input parameter data as an input parameter, and transmitting a written unit test code to perform a unit test on the service logic code.
As previously mentioned, unit test code is code used to test and verify the correctness and reasonableness of business logic code, and unit test code can generally call methods in business logic code to perform unit test on business logic code.
In one embodiment, before obtaining input parameter data provided by the data model and importing written unit test code with the input parameter data as input parameters to perform unit test on the business logic code, the method further comprises:
unit test code written by a developer is obtained.
As mentioned above, the unit test code may be written before the business logic code is built, or may be written after the business logic code is built.
FIG. 5 is an overall process diagram illustrating an application unit testing method according to an exemplary embodiment. Referring to fig. 5, when the unit testing method provided in the embodiment of the present application is applied, the overall process may be as follows: firstly, designing and establishing a data model according to business requirements, maintaining various parameter data such as data, states and the like in the data model, after unit test codes are developed, providing the parameter data by the data model to perform unit test to verify the correctness of the business logic codes, after the verification is passed, finishing the whole test process, if the verification is not passed, modifying the business logic codes, and performing the unit test process again until the verification is passed. When a service logic is changed, the change of a data model or the increase or decrease of parameter data is also involved, so that maintenance is needed in the data model at first, and after the maintenance is completed, a service logic code is compiled; after the service logic code is compiled, compiling a unit test code; after writing, the whole unit test can be executed, if error is reported, a certain unit test is indicated to have a problem, if the new unit test is indicated to have a problem, the newly established service logic code is indicated to have a problem, if the original unit test is indicated to have a problem, the influence on the original logic is not analyzed, and the service logic code with defects is detected through the unit test.
In one embodiment, the data model further includes output parameter data corresponding to methods in the business logic code, the unit test code including a plurality of sets of subunit test codes, each set of subunit test codes corresponding to a method.
In an embodiment of the application, as shown in fig. 3, in the step S220, the step of importing the written unit test code by using the input parameter data as an input parameter to perform unit test on the business logic code may further include:
step S221, aiming at each method in the business logic code, inputting a group of subunit test codes corresponding to the method by taking input parameter data corresponding to the method as input parameters to obtain test parameter output data;
step S222, acquiring output parameter data from the data model;
step S223, comparing the test parameter output data with the output parameter data corresponding to the method, and determining whether the method in the service logic code passes the unit test according to the comparison result.
The output parameter data corresponding to the method is data of the same type as the data of the return value of the method, and can be directly used as the return value of the method.
When the test parameter output data is inconsistent with the output parameter data, it may be determined that the corresponding method fails the unit test, otherwise, it may be determined that the corresponding method passes the unit test.
For example, each method in the service logic code is A, B, C, where input parameter data corresponding to parameters of each method is a1, B1, and C1, respectively, and output parameter data corresponding to each method in the service logic code is a2, B2, and C2, respectively, in this embodiment, first, the input parameter data of a1, B1, and C1 are transmitted as input parameters to subunit test codes corresponding to A, B, C, to obtain test parameter output data output by the subunit test codes, which are a2, B2, and C2, then, a2 and a2, B2 and B2, and C2 and C2 are compared, and after the comparison, a unit test result is determined according to the comparison result.
In an embodiment, after comparing the test parameter output data with the output parameter data corresponding to the method and determining whether the method in the service logic code passes the unit test according to the comparison result, that is, after step S223, the method may further include:
and if the method in the service logic code fails the unit test, sending reminding information to prompt the method in the service logic code to be modified, wherein the reminding information comprises the method name of the method.
Specifically, the reminding information may be various types of information, and only the information needs to prompt the developer that the method is wrong and needs to be modified, for example, the reminding information may exist in a manner of changing visual information such as colors and patterns on a user interface, or exist in a manner of recording a popup window, a mail, and the like for reminding, and the reminding information may be directly sent to the user at the application implementation terminal, or sent to other terminals except the application implementation terminal through a medium.
The parameters of each method in the business logic code correspond to input parameter data and each method in the business logic code also corresponds to output parameter data, so that for the same method in the business logic code, it corresponds to both input parameter data and output parameter data.
In one embodiment, the business logic code includes a plurality of methods that are sequentially called in a designated order, and the written unit test code corresponds to the plurality of methods that are sequentially called.
As shown in fig. 4, in the step S220, the step of importing the written unit test code with the input parameter data as an input parameter to perform unit test on the business logic code may further include:
step S221', determining the method called first in the multiple methods called in sequence as the initial method;
step S222', using the input parameter data corresponding to the initial method as an input parameter, importing unit test codes corresponding to the sequentially called methods, and sequentially performing unit tests on the sequentially called methods.
The multiple methods that are sequentially called in a specified order may be, for example, A, B, C, method a is called by method B, which is called by method C, and then method a is the first method called, i.e., the initial method.
In one embodiment, the data model further includes output parameter data corresponding to methods in the business logic code;
when the methods called sequentially in sequence are executed, if the first method is called by the second method, the output parameter of the first method is used as the input parameter and is transmitted into the second method;
the output parameter data corresponding to the called method in the multiple methods called in sequence is consistent with the input parameter data corresponding to the method calling the method;
the unit test code comprises a plurality of groups of subunit test codes, and each group of subunit test codes corresponds to one of the methods called in sequence.
The sequentially performing unit testing on the plurality of methods sequentially called comprises the following steps:
sequentially executing a first unit testing step on each method sequentially called until the methods sequentially called all pass unit testing;
wherein the first unit testing step comprises:
if one method of the methods sequentially called passes the unit test, test parameter output data output by the subunit test code corresponding to the method during the unit test is taken as input parameters and is transmitted into the subunit test code corresponding to the method calling the method;
if one method in the multiple methods sequentially called does not pass the unit test, acquiring output parameter data corresponding to the method from the data model, and transmitting the output parameter data serving as an input parameter into a subunit test code corresponding to the method calling the method.
The methods sequentially called in a designated order may be, for example, A, B, C, method a calling method B, and method B calling method C, and if the input parameter data corresponding to the parameters of each method are a1, B1, and C1, the output parameter data corresponding to each method may be a2, a1, and B1, that is, the output parameter data of method C may be equal to the input parameter data of method B, the output parameter data of method B may be equal to the input parameter data of method a, the test parameter output data of the corresponding subunit test code output when performing the unit test of each method may be a2, B2, C2, respectively, then in this embodiment, if method B passes the unit test, test parameter output data B2 is sent as input parameters to method A, and if method B does not pass the unit test, output parameter data A1 is sent as input parameters to method A.
In this embodiment, output parameter data corresponding to a called method of the methods that are sequentially called and input parameter data corresponding to a method that calls the method are set to be the same for a case that the methods are sequentially called in sequence, so that the number of parameter data that needs to be maintained in the data model can be effectively reduced, thereby reducing labor cost and improving efficiency.
For example, the service logic code may be a code for controlling a loan application process, and then, the methods sequentially invoked in sequence may be methods in the loan application process, and may include, for example, method 1, method 2, and method 3, and then, the input and output parameter data corresponding to the three methods may be — a first set of parameters (application number a001, state 001), a second set of parameters (application number a001, state 002), and a third set of parameters (application number a001, state 003), where each state corresponds to a certain link in the loan application process, if a method corresponding to a link passes through the loan application process corresponding to the link, the method may be subjected to a unit test with the first set of parameters as an input parameter of a subunit test code corresponding to the method, and the subunit test code may output at least the second set of parameters, at this time, the status code changes from 001 to 002.
If the method corresponding to one link returns to the loan application process corresponding to the link, that is, the loan application process returns to the previous link, at this time, when the method is subjected to unit test, the third set of parameters may be used as parameters of the subunit test code corresponding to the method, the subunit test code may output at least the second set of parameters, and at this time, the status code is changed from 003 to 002.
If the method in the loan application flow relates to the state code changing from 002 to 0021 during execution, when the corresponding method is subjected to unit test, only the state code after maintenance change needs to be carried out on the data model, and the corresponding test code needs to be written, so that the test time can be saved, the efficiency can be improved, and the cost can be reduced.
In one embodiment, the data model further includes output parameter data corresponding to methods in the business logic code;
when the methods called sequentially in sequence are executed, if the first method is called by the second method, the output parameter of the first method is used as the input parameter and is transmitted into the second method; (ii) a
The output parameter data corresponding to the called method in the multiple methods called in sequence is consistent with the input parameter data corresponding to the method calling the method;
the unit test code comprises a plurality of groups of subunit test codes, and each group of subunit test codes corresponds to one of the methods called in sequence.
In step S222', the step of sequentially performing unit testing on the sequentially called methods may further include:
sequentially executing a second unit testing step on each method sequentially called until the methods sequentially called all pass through the unit testing;
wherein the second unit testing step comprises:
and when one method in the multiple methods sequentially called completes unit testing, acquiring output parameter data corresponding to the method from the data model, and introducing the output parameter data serving as an input parameter into a subunit testing code corresponding to the method calling the method.
If the methods called sequentially in the designated order are A, B, C, method a calls method B, and method B calls method C, and the output parameter data corresponding to each method in the business logic code maintained by the data model are a2, B2, and C2, then if method B fails the unit test, the output parameter data B2 corresponding to method B obtained from the data model will be transmitted to method a as the input parameter.
Compared with the above embodiments, the difference in this embodiment is that when the corresponding method is tested by using the subunit test code, all the input parameters are obtained from the data model, and the input parameters are the output parameter data corresponding to the method called by the method to be tested currently.
In one embodiment, the data model listens for business logic code;
after the obtaining input parameter data provided by the data model and using the input parameter data as an input parameter, importing written unit test code to perform unit test on the business logic code, the method further includes:
and acquiring corrected input parameter data provided by the data model, and performing unit test on the service logic code based on the corrected input parameter data, wherein the corrected input parameter data is obtained by correcting corresponding input parameter data after the data model monitors that at least one method parameter of the service logic code is changed.
For example, if a parameter of a method in the business logic code is (X, Y) and the corresponding input parameter data is (X, Y), if the parameter of the method changes and becomes (X, Y, Z), the data model will provide the modified input parameter data (X, Y, Z) after listening for the change of the parameter of the method.
In this embodiment, the data model further has a monitoring function for monitoring parameters of the method in the service logic code, and by monitoring and correcting the input parameter data after monitoring that the parameters of the method are changed, it is ensured that the data model can provide effective parameters in time when performing unit test, and that the unit test can be performed smoothly.
In one embodiment, the data model continuously monitors the state of the parameter in the service logic code in a first time interval, and determines the monitoring frequency of each time period every day according to the monitoring result in the first time interval.
The first time interval may be various time intervals such as a day, a week, a month, etc., for example, statistics of the monitoring results shows that the parameters of 15:00-17:00 change more every day, and the parameters of 11:00-13:00 change less every day, so that a higher monitoring frequency may be set for the time interval of 15:00-17:00 every day, and a lower monitoring frequency may be set for the time interval of 11:00-13:00 every day.
In the embodiment, different monitoring frequencies are set in each time period of each day in a targeted manner, so that the parameter data can be corrected in time once the parameters of the method in the service logic code are changed, and meanwhile, the computing resources are saved.
In one embodiment, the logical structure of the data model corresponds to the association relationship between methods in the business logic codes of a plurality of business systems, respectively, and the data model includes input parameter data corresponding to parameters of each method in the business logic codes of the plurality of business systems.
FIG. 6 is a diagram illustrating an overall process for applying a unit testing method in a multi-system scenario, according to an example embodiment. Referring to fig. 6, the data models correspond to the business logic codes of system a and system B, respectively, and can provide parameter data for unit testing of the business logic codes of system a and system B at the same time. The business logic code of system a and system B may also include a plurality of methods that require unit testing, respectively, for example, the data model in fig. 6 may provide parameter data for the unit testing of method 1 and method 2 in system a. The data model is used for supporting the unit test of the service logic codes in a plurality of systems, so that the advantage of improving the unit test efficiency of the unit test method provided by the application is further highlighted.
In summary, according to the unit testing method provided in the embodiment of fig. 2, the data model is constructed, the logical structure of the data model corresponds to the association relationship between the methods in the business logic code, and the data model is used to maintain and provide the parameter data required for the unit testing, so that the construction of the parameter data for each class or method is not required during the unit testing, the cost of development and testing is reduced, and the efficiency is improved.
The application also provides a unit testing device, and the following is the device embodiment of the application.
FIG. 7 is a block diagram illustrating a unit testing device according to an exemplary embodiment. As shown in fig. 7, the apparatus 700 includes:
a data model establishing module 710 configured to establish a data model, a logical structure of which corresponds to an incidence relation between methods in a business logic code to be tested, the data model including input parameter data corresponding to parameters of the methods in the business logic code, the data model being used for transmitting the input parameter data to a unit test code when the business logic code is subjected to the unit test;
an input parameter data obtaining module 720, configured to obtain the input parameter data provided by the data model, and with the input parameter data as an input parameter, import the written unit test code to perform unit test on the business logic code.
In one embodiment, the data model building module is further configured to:
acquiring required document text information;
analyzing the required document text information by using a deep learning model, and establishing a data model comprising input parameter data based on an analysis result, wherein the business logic code is compiled according to the required document text information and the data model.
In one embodiment, the data model further includes output parameter data corresponding to methods in the business logic code, the unit test code including a plurality of sets of subunit test codes, each set of subunit test codes corresponding to a method;
the input parameter data acquisition module is further configured to:
for each method in the business logic codes, inputting a group of subunit test codes corresponding to the method by taking input parameter data corresponding to the method as input parameters to obtain test parameter output data;
obtaining output parameter data from the data model;
and comparing the test parameter output data with the output parameter data corresponding to the method, and determining whether the method in the service logic code passes the unit test or not according to the comparison result.
In one embodiment, the service logic code includes a plurality of methods sequentially called according to a specified sequence, and the written unit test code corresponds to the plurality of methods sequentially called;
the input parameter data acquisition module is further configured to:
determining a method called first in the multiple methods called sequentially in sequence as an initial method;
and taking the input parameter data corresponding to the initial method as an input parameter, transmitting unit test codes corresponding to the methods called in sequence, and sequentially carrying out unit test on the methods called in sequence.
It will be readily appreciated that, as with the three embodiments described above, the unit test apparatus provided in the embodiments of the present application may be used to perform any of the methods described above.
According to a third aspect of the present application, there is also provided an electronic device capable of implementing the above method.
As will be appreciated by one skilled in the art, aspects of the present invention may be embodied as a system, method or program product. Thus, various aspects of the invention may be embodied in the form of: an entirely hardware embodiment, an entirely software embodiment (including firmware, microcode, etc.) or an embodiment combining hardware and software aspects that may all generally be referred to herein as a "circuit," module "or" system.
An electronic device 800 according to this embodiment of the invention is described below with reference to fig. 8. The electronic device 800 shown in fig. 8 is only an example and should not bring any limitations to the function and scope of use of the embodiments of the present invention.
As shown in fig. 8, electronic device 800 is in the form of a general purpose computing device. The components of the electronic device 800 may include, but are not limited to: the at least one processing unit 810, the at least one memory unit 820, and a bus 830 that couples the various system components including the memory unit 820 and the processing unit 810.
Wherein the storage unit stores program code that can be executed by the processing unit 810, such that the processing unit 810 performs the steps according to various exemplary embodiments of the present invention described in the "example methods" section above in this specification.
The storage unit 820 may include readable media in the form of volatile storage units, such as a random access storage unit (RAM)821 and/or a cache storage unit 822, and may further include a read only storage unit (ROM) 823.
The electronic device 800 may also communicate with one or more external devices 1000 (e.g., keyboard, pointing device, bluetooth device, etc.), with one or more devices that enable a user to interact with the electronic device 800, and/or with any devices (e.g., router, modem, etc.) that enable the electronic device 800 to communicate with one or more other computing devices. Such communication may occur via an input/output (I/O) interface 850, such as with display unit 840. Also, the electronic device 800 may communicate with one or more networks (e.g., a Local Area Network (LAN), a Wide Area Network (WAN), and/or a public network, such as the internet) via the network adapter 860. As shown, the network adapter 860 communicates with the other modules of the electronic device 800 via the bus 830. It should be appreciated that although not shown, other hardware and/or software modules may be used in conjunction with the electronic device 800, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, among others.
Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein may be implemented by software, or by software in combination with necessary hardware. Therefore, the technical solution according to the embodiments of the present application can be embodied in the form of a software product, which can be stored in a volatile or non-volatile storage medium (which can be a CD-ROM, a usb disk, a removable hard disk, etc.) or on a network, and includes several instructions to make a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) execute the method according to the embodiments of the present application.
According to a fourth aspect of the present application, there is also provided a computer-readable storage medium having stored thereon a program product capable of implementing the above-described method of the present specification. In some possible embodiments, aspects of the invention may also be implemented in the form of a program product comprising program code means for causing a terminal device to carry out the steps according to various exemplary embodiments of the invention described in the above section "exemplary methods" of the present description, when said program product is run on the terminal device.
Referring to fig. 9, a program product 900 for implementing the above method according to an embodiment of the present invention is described, which may employ a portable compact disc read only memory (CD-ROM) and include program code, and may be run on a terminal device, such as a personal computer. However, the program product of the present invention is not limited in this regard and, in the present document, a 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.
The program product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. A 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 (a non-exhaustive list) of the readable storage medium include: an electrical connection having one or more wires, a portable disk, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
A computer readable signal medium may include a propagated data signal with 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 readable signal medium may also be any readable medium that is not a 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 readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computing device, partly on the user's device, as a stand-alone software package, partly on the user's computing device and partly on a remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computing device (e.g., through the internet using an internet service provider).
Furthermore, the above-described figures are merely schematic illustrations of processes involved in methods according to exemplary embodiments of the invention, and are not intended to be limiting. It will be readily understood that the processes shown in the above figures are not intended to indicate or limit the chronological order of the processes. In addition, it is also readily understood that these processes may be performed synchronously or asynchronously, e.g., in multiple modules.
It will be understood that the invention is not limited to the precise arrangements described above and shown in the drawings and that various modifications and changes may be made without departing from the scope thereof. The scope of the invention is limited only by the appended claims.
Claims (10)
1. A method of unit testing, the method comprising:
establishing a data model, wherein the logic structure of the data model corresponds to the incidence relation among the methods in the service logic code to be tested, the data model comprises input parameter data corresponding to the parameters of the methods in the service logic code, and the data model is used for transmitting the input parameter data to the unit test code when the service logic code is subjected to unit test;
and acquiring input parameter data provided by the data model, and transmitting the input parameter data as an input parameter into a written unit test code so as to perform unit test on the business logic code.
2. The method of claim 1, wherein the data model further comprises output parameter data corresponding to methods in the business logic code, wherein the unit test code comprises a plurality of sets of subunit test codes, wherein each set of subunit test codes corresponds to a method;
the step of using the input parameter data as input parameters and transmitting written unit test codes to perform unit test on the business logic codes comprises the following steps:
for each method in the business logic codes, inputting a group of subunit test codes corresponding to the method by taking input parameter data corresponding to the method as input parameters to obtain test parameter output data;
obtaining output parameter data from the data model;
and comparing the test parameter output data with the output parameter data corresponding to the method, and determining whether the method in the service logic code passes the unit test or not according to the comparison result.
3. The method of claim 1, wherein the business logic code comprises a plurality of methods that are sequentially called in a specified order, and wherein the written unit test code corresponds to the plurality of methods that are sequentially called;
the step of using the input parameter data as input parameters and transmitting written unit test codes to perform unit test on the business logic codes comprises the following steps:
determining a method called first in the multiple methods called sequentially in sequence as an initial method;
and taking the input parameter data corresponding to the initial method as an input parameter, transmitting unit test codes corresponding to the methods called in sequence, and sequentially carrying out unit test on the methods called in sequence.
4. The method of claim 3, wherein the data model further includes output parameter data corresponding to each method in the business logic code, and when executing the sequentially called methods, if a first method is called by a second method, the output parameter of the first method is transmitted as an input parameter to the second method, and the output parameter data corresponding to the called method in the sequentially called methods is consistent with the input parameter data corresponding to the method calling the method; the unit test code comprises a plurality of groups of subunit test codes, and each group of subunit test codes corresponds to one of the methods called in sequence;
the sequentially performing unit testing on the plurality of methods sequentially called comprises the following steps:
sequentially executing a first unit testing step on each method sequentially called until the methods sequentially called all pass unit testing;
wherein the first unit testing step comprises:
if one method of the methods sequentially called passes the unit test, test parameter output data output by the subunit test code corresponding to the method during the unit test is taken as input parameters and is transmitted into the subunit test code corresponding to the method calling the method;
if one method in the multiple methods sequentially called does not pass the unit test, acquiring output parameter data corresponding to the method from the data model, and transmitting the output parameter data serving as an input parameter into a subunit test code corresponding to the method calling the method.
5. The method of claim 3, wherein the data model further includes output parameter data corresponding to each method in the business logic code, and when executing the sequentially called methods, if a first method is called by a second method, the output parameter of the first method is transmitted as an input parameter to the second method, the output parameter data corresponding to the called method in the sequentially called methods is consistent with the input parameter data corresponding to the method calling the method, the unit test code includes a plurality of sets of subunit test codes, and each set of subunit test code corresponds to one method in the sequentially called methods;
the sequentially performing unit testing on the plurality of methods sequentially called comprises the following steps:
sequentially executing a second unit testing step on each method sequentially called until the methods sequentially called all pass through the unit testing;
wherein the second unit testing step comprises:
and when one method in the multiple methods sequentially called completes unit testing, acquiring output parameter data corresponding to the method from the data model, and introducing the output parameter data serving as an input parameter into a subunit testing code corresponding to the method calling the method.
6. The method of claim 1, wherein the data model listens for business logic code; after the obtaining input parameter data provided by the data model and using the input parameter data as an input parameter, importing written unit test code to perform unit test on the business logic code, the method further includes:
and acquiring corrected input parameter data provided by the data model, and performing unit test on the service logic code based on the corrected input parameter data, wherein the corrected input parameter data is obtained by correcting corresponding input parameter data after the data model monitors that at least one method parameter of the service logic code is changed.
7. The method of any one of claims 1-6, wherein the establishing a data model comprises:
acquiring required document text information;
analyzing the required document text information by using a deep learning model, and establishing a data model comprising input parameter data based on an analysis result, wherein the business logic code is compiled according to the required document text information and the data model.
8. A unit testing apparatus, the apparatus comprising:
the data model establishing module is configured to establish a data model, a logic structure of the data model corresponds to an incidence relation among methods in a service logic code to be tested, the data model comprises input parameter data corresponding to parameters of the methods in the service logic code, and the data model is used for transmitting the input parameter data to a unit test code when the service logic code is subjected to unit test;
and the input parameter data acquisition module is configured to acquire the input parameter data provided by the data model and use the input parameter data as an input parameter to transmit the written unit test code so as to perform unit test on the business logic code.
9. A computer-readable program medium, characterized in that it stores computer program instructions which, when executed by a computer, cause the computer to perform the method according to any one of claims 1 to 7.
10. An electronic device, characterized in that the electronic device comprises:
a processor;
a memory having stored thereon computer readable instructions which, when executed by the processor, implement the method of any of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202011257340.4A CN112380118A (en) | 2020-11-11 | 2020-11-11 | Unit testing method, unit testing device, medium and electronic equipment |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202011257340.4A CN112380118A (en) | 2020-11-11 | 2020-11-11 | Unit testing method, unit testing device, medium and electronic equipment |
Publications (1)
Publication Number | Publication Date |
---|---|
CN112380118A true CN112380118A (en) | 2021-02-19 |
Family
ID=74582929
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202011257340.4A Pending CN112380118A (en) | 2020-11-11 | 2020-11-11 | Unit testing method, unit testing device, medium and electronic equipment |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN112380118A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113434527A (en) * | 2021-07-07 | 2021-09-24 | 北京京东振世信息技术有限公司 | Data processing method and device, electronic equipment and storage medium |
-
2020
- 2020-11-11 CN CN202011257340.4A patent/CN112380118A/en active Pending
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113434527A (en) * | 2021-07-07 | 2021-09-24 | 北京京东振世信息技术有限公司 | Data processing method and device, electronic equipment and storage medium |
CN113434527B (en) * | 2021-07-07 | 2023-09-22 | 北京京东振世信息技术有限公司 | Data processing method, device, electronic equipment and storage medium |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110674047B (en) | Software testing method and device and electronic equipment | |
US20210263841A1 (en) | Machine code analysis for identifying software defects | |
CN109977012B (en) | Joint debugging test method, device, equipment and computer readable storage medium of system | |
CN112650685A (en) | Automatic testing method and device, electronic equipment and computer storage medium | |
US12032477B2 (en) | Method and apparatus for generating and applying deep learning model based on deep learning framework | |
CN111679977B (en) | Method, equipment and storage medium for testing exact project unit based on Jest | |
US11663113B2 (en) | Real time fault localization using combinatorial test design techniques and test case priority selection | |
CN111767209A (en) | Code testing method, device, storage medium and terminal | |
CN112380118A (en) | Unit testing method, unit testing device, medium and electronic equipment | |
CN115599683A (en) | Automatic testing method, device, equipment and storage medium | |
CN113032256B (en) | Automated testing method, apparatus, computer system, and readable storage medium | |
CN116149978A (en) | Service interface testing method and device, electronic equipment and storage medium | |
CN112965910B (en) | Automatic regression testing method and device, electronic equipment and storage medium | |
CN116467156A (en) | Joint debugging test method and device, storage medium and electronic equipment | |
CN113986263A (en) | Code automation test method, device, electronic equipment and storage medium | |
CN113885841A (en) | Script generation method and device, electronic equipment and readable medium | |
CN111221719B (en) | Automatic test system and test method | |
CN116383068B (en) | Quick test method, device and storage medium of C++ program interface | |
CN114579444A (en) | Automated testing method, automated testing device, electronic apparatus, storage medium, and program product | |
CN117389877A (en) | Test method, test device, computer readable medium and electronic equipment | |
CN115934546A (en) | Go language-based block chain integration test method and system | |
CN114168466A (en) | Unit testing method, device, system and storage medium | |
CN116974950A (en) | Method, system, equipment and medium for analyzing general software test requirement | |
CN113778390A (en) | Interface access method and device | |
CN116383068A (en) | Quick test method, device and storage medium of C++ program interface |
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 |