CN114579470A - Unit testing method and device, electronic equipment and storage medium - Google Patents

Unit testing method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN114579470A
CN114579470A CN202210302354.6A CN202210302354A CN114579470A CN 114579470 A CN114579470 A CN 114579470A CN 202210302354 A CN202210302354 A CN 202210302354A CN 114579470 A CN114579470 A CN 114579470A
Authority
CN
China
Prior art keywords
unit
tested
test
data
dependent
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
CN202210302354.6A
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.)
Chuangyou Digital Technology Guangdong Co Ltd
Original Assignee
Chuangyou Digital Technology Guangdong 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 Chuangyou Digital Technology Guangdong Co Ltd filed Critical Chuangyou Digital Technology Guangdong Co Ltd
Priority to CN202210302354.6A priority Critical patent/CN114579470A/en
Publication of CN114579470A publication Critical patent/CN114579470A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test 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 invention discloses a unit testing method, a unit testing device, electronic equipment and a storage medium, which are used for solving the technical problem of high cost of the existing unit testing method. The invention comprises the following steps: determining a unit to be tested and a dependent unit of the unit to be tested in a preset service; acquiring test data of the unit to be tested; creating a mock object of the dependent unit to simulate execution of the dependent unit; and testing the unit to be tested by adopting the test data and the mock object to obtain a test result. The method simulates the execution of the dependent unit to obtain the return data required by the unit to be tested by creating the mock object of the dependent unit of the unit to be tested, and tests the unit to be tested by combining the test data, so that the execution flow of the dependent unit is not required to be executed, the execution process of the unit test is reduced, the test program is simplified, and the expenditure of the unit test is reduced.

Description

Unit testing method and device, electronic equipment and storage medium
Technical Field
The present invention relates to the field of application testing technologies, and in particular, to a unit testing method and apparatus, an electronic device, and a storage medium.
Background
When an application needs to be functionally adjusted, it is often necessary to reconstruct the internal execution code. Reconstructing the code requires a large number of unit test cases. Unit testing refers to checking and verifying the smallest testable unit in software. For the meaning of the unit in the unit test, generally, the specific meaning is determined according to the actual situation, for example, the unit in the C language refers to a function, the unit in the Java refers to a class, and the graphical software may refer to a window or a menu. In general, the unit is the minimum tested functional module specified by human. Unit testing is the lowest level of testing activity to be performed during software development, and individual units of software will be tested in isolation from other parts of the program.
In the general scheme of the existing unit test, the following defects exist:
1. due to the 'independent' characteristic of the unit tests, a complex test method may need many unit tests to cover a completed service scenario, for example, any change (such as version upgrade and new function addition) of the internal architecture implementation of the applet also needs to independently set one unit test, thereby bringing a large workload to development;
2. in the unit testing process, a plurality of dependent items such as a database are needed, so a large number of native jdbc interfaces need to be defined to perform data query and the like, thereby causing extra expenses of developers;
3. in the existing unit test, data needs to be frequently constructed to complete the unit test, for example, for the unit test of the payment module, order data to be paid needs to be frequently constructed in advance as test data, and whether the payment module is normal is tested by the test data, so that the cost of the test process is too high.
Disclosure of Invention
The invention provides a unit testing method, a unit testing device, electronic equipment and a storage medium, which are used for solving the technical problem of high cost of the existing unit testing method.
The invention provides a unit testing method, which comprises the following steps:
determining a unit to be tested and a dependent unit of the unit to be tested in a preset service;
acquiring test data of the unit to be tested;
creating a mock object of the dependent unit to simulate execution of the dependent unit;
and testing the unit to be tested by adopting the test data and the mock object to obtain a test result.
Optionally, the step of obtaining the test data of the unit under test includes:
acquiring service data of the preset service;
acquiring a configuration file of the unit to be tested;
and generating test data of the unit to be tested according to the service data and the configuration file.
Optionally, the step of generating test data of the unit to be tested according to the service data and the configuration file includes:
extracting a storage data structure from the configuration file;
and filling the service data in the storage data structure, and generating the test data of the unit to be tested according to the filled service data.
Optionally, the creating a mock object of the dependent unit to simulate the step of executing the dependent unit includes:
determining an API (application program interface) of the dependency unit and acquiring a data structure of the API;
and generating a mock object of the dependent unit based on the data structure of the API interface so as to simulate the execution of the dependent unit.
Optionally, the step of testing the unit to be tested by using the test data and the mock object to obtain a test result includes:
obtaining return data returned by the mock object based on the call request of the unit to be tested;
and testing the unit to be tested based on the execution flow of the unit to be tested by adopting the test data and the return data to obtain a test result.
Optionally, after the step of testing the unit to be tested by using the test data and the mock object to obtain the test result, the method further includes:
and verifying the test result to obtain a verification result of the unit to be tested.
Optionally, the step of verifying the test result to obtain the verification result of the unit to be tested includes:
acquiring a target result of the unit to be tested;
verifying the test result by adopting the target result;
and when the target result is the same as the test result, judging that the unit to be tested passes the test.
The present invention also provides a unit testing apparatus, comprising:
the unit determining module is used for determining a unit to be tested and a dependent unit of the unit to be tested in a preset service;
the test data acquisition module is used for acquiring the test data of the unit to be tested;
a mock object creating module, configured to create a mock object of the dependent unit, so as to simulate execution of the dependent unit;
and the testing module is used for testing the unit to be tested by adopting the test data and the mock object to obtain a test result.
Optionally, the test data obtaining module includes:
the data acquisition submodule is used for acquiring the service data of the preset service;
the configuration file acquisition submodule is used for acquiring the configuration file of the unit to be tested;
and the test data generation submodule is used for generating the test data of the unit to be tested according to the service data and the configuration file.
The invention also provides an electronic device comprising a processor and a memory:
the memory is used for storing program codes and transmitting the program codes to the processor;
the processor is configured to perform the unit testing method as described in any one of the above in accordance with instructions in the program code.
The invention also provides a computer readable storage medium for storing program code for performing a unit testing method as defined in any one of the above.
According to the technical scheme, the invention has the following advantages: the method simulates the execution of the dependent unit to obtain the return data required by the unit to be tested by creating the mock object of the dependent unit of the unit to be tested, and tests the unit to be tested by combining the test data, so that the execution flow of the dependent unit is not required to be executed, the execution process of the unit test is reduced, the test program is simplified, and the expenditure of the unit test is reduced.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to these drawings without inventive exercise.
FIG. 1 is a flowchart illustrating steps of a unit testing method according to an embodiment of the present invention;
fig. 2 is a schematic diagram of a unit dependency relationship according to an embodiment of the present invention;
FIG. 3 is a flowchart illustrating steps of a method for unit testing according to another embodiment of the present invention;
FIG. 4 is a block diagram of a unit testing method according to an embodiment of the present invention;
fig. 5 is a block diagram of a unit testing apparatus according to an embodiment of the present invention.
Detailed Description
The embodiment of the invention provides a unit testing method, a unit testing device, electronic equipment and a storage medium, which are used for solving the technical problem of high cost of the existing unit testing method.
In order to make the objects, features and advantages of the present invention more obvious and understandable, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is obvious that the embodiments described below are only a part of the embodiments of the present invention, 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 invention.
Referring to fig. 1, fig. 1 is a flowchart illustrating a unit testing method according to an embodiment of the present invention.
The unit testing method provided by the invention specifically comprises the following steps:
step 101, determining a unit to be tested and a dependent unit of the unit to be tested in a preset service;
in the embodiment of the present invention, the preset service may be any application program. Such as a payment applet, etc.
And the dependent unit refers to an associated unit of the unit to be tested in the execution process. In the embodiment of the present invention, the dependent unit of the unit to be tested can be determined by determining whether there is interference between the unit to be tested and other units during the service execution process. If the unit to be called in the execution process of the unit to be tested is needed, the unit to be called can be determined as the dependent unit of the unit to be tested. For example, in a business scenario, in an order placing process of a user purchasing a commodity, the order placing and the payment are two services corresponding to different units, respectively, and in the order placing process, a service for calling the payment is required, that is, an operation of placing the order needs to depend on the service for calling the payment. And if the ordering service is the unit to be tested, the payment service is the dependent unit of the ordering service.
For easy understanding, please refer to fig. 2, wherein fig. 2 is a schematic diagram illustrating a unit dependency relationship according to an embodiment of the present invention.
Fig. 2 is a part of units involved in a payment applet, including service, bean a, bean b, dao and outservice, where service can be understood as a shopping operation, bean a represents an ordering service associated with service, bean b represents a payment service associated with service, dao represents an inventory query for querying an order status at the time of ordering, and outservice represents an external payment service. Then both beans a and beans b, which would have direct feedback on the service, and dao and outservice, which are directly associated with beans a and beans b, are dependent units of the service.
Step 102, obtaining test data of a unit to be tested;
in the embodiment of the present invention, to test a unit to be tested, first, test data needs to be obtained. For traditional unit testing, many native jdbc are usually written to connect databases, and database data change is always a problem. For example: during the order placing payment process, the jdbc interface needs to be written to operate the order table, and the order is changed from the state of waiting payment to the state of successful payment after the payment is finished. When the unit for placing the order and paying the bill needs to be tested again, the order in the state of waiting to pay needs to be generated by a new process, so that the payment can be tested, the process is complicated, and the resource occupation is high.
Since the necessary data for executing the test is the order data to be paid for the order payment unit, the application can directly generate the order data for payment by generating the configuration file in advance, so as to reduce the process of writing the native jdbc.
jdbc (Java Database Connectivity) is an application program interface in the Java language that specifies how client programs access databases, providing methods such as querying and updating data in databases.
103, creating a mock object of a dependent unit to simulate and execute the dependent unit;
the mock is a test method for creating a virtual object to replace some objects which are not easy to construct or obtain in the test process so as to test, and the virtual object is the mock object. Mock's greatest function is to break the coupling of unit tests, which helps you to model dependencies if your code has dependencies on another class or interface, and helps you verify the behavior of the invoked dependencies.
For ease of understanding, the following describes the functions of the mock object by way of specific examples: assuming that an alarm clock carries out reminding service according to time, an audio file is played for off-duty reminding after 5 o' clock afternoon. If the real object is used for testing, the test can only wait for five pm; if the test is performed with a mock object, the time can be simulated without waiting for the clock to go to 5 pm. It can be understood that the mock object can simulate the actual process so as to directly obtain the required result. If the reminding service is a unit to be tested, the time tracking is a dependent unit of the testing unit, and a mock object of the time tracking is established, so that the data processing process of the dependent unit can be reduced, and the testing expense of developers is reduced.
And step 104, testing the unit to be tested by adopting the test data and the mock object to obtain a test result.
After the test data and the mock object are obtained, the unit to be tested can be tested by combining the test data and the mock object.
Taking the ordering process of purchasing commodities by a user as an example, in the ordering process, an order to be paid can be obtained through a configuration file to serve as test data, and the return result of a payment unit (a dependence unit of an ordering unit) is simulated through mock. Thereby completing the test of the unit to be tested.
The method simulates the execution of the dependent unit to obtain the return data required by the unit to be tested by creating the mock object of the dependent unit of the unit to be tested, and tests the unit to be tested by combining the test data, so that the execution flow of the dependent unit is not required to be executed, the execution process of the unit test is reduced, the test program is simplified, and the expenditure of the unit test is reduced. In addition, the invention can directly generate the test data by generating the configuration file in advance without actually operating the unit required for generating the test data, thereby carrying out unit test before the actual operation and exposing the possible defects of the module to be tested in advance.
Referring to fig. 3, fig. 3 is a flowchart illustrating a method for testing a cell according to another embodiment of the present invention. The method specifically comprises the following steps:
step 301, determining a unit to be tested and a dependent unit of the unit to be tested in a preset service;
step 301 is the same as step 101, and reference may be specifically made to the description of step 101, which is not described herein again.
Step 302, acquiring service data of a preset service;
step 303, acquiring a configuration file of the unit to be tested;
step 304, generating test data of the unit to be tested according to the service data and the configuration file;
in the embodiment of the present invention, the service data of the preset service may include objective information of the service processing object itself and subjective information selected by the user.
For example, to complete payment of an order form by a user, commodity information is acquired, where the commodity is a service processing object and the commodity information is objective information of the commodity. Then, the purchase quantity of the commodity needs to be acquired, which depends on the selection behavior of the user, namely, the subjective information selected by the user. Based on the two points of payment, the actual order form can be calculated, so that the corresponding payment operation is executed according to the order form.
In a conventional operation, to acquire the data, a plurality of original jdbc connection databases need to be written to acquire corresponding data, and the data is processed by different units to obtain an order table as test data. And after the payment is finished, the order can jump from the state of waiting for payment to the state of successful payment; when the re-test is needed, the process is needed to be repeated to generate the order form of the state to be paid, and the payment can be tested, and the process is extremely complicated.
In view of this, the embodiment of the present invention introduces the mariad db database to store the service data, so as to avoid the process of writing jdbc. Meanwhile, corresponding storage data structures are defined for different units to be tested through configuration files (such as sql files) to store business data.
In one example, an index relationship between the unit to be tested and the storage path of the configuration file may be established, so that when the unit to be tested is tested, the corresponding configuration file is obtained to generate the test data. Different storage data structures may be configured for the units under test depending on the differences in the functions performed by them. For example, when the unit to be tested is a payment unit, the test data may be an order table, and the stored data structure in the configuration file may be a data arrangement structure, a data type, and the like required in the order table.
Test data is then constructed in an xml file with the stored business data. When the unit to be tested needs to be tested, the sql file and the xml file can be called to read the data structure and the test data, and the stored data structure and the test data are initialized and reset, so that a complicated test data generation flow does not need to be removed.
The MariaDB database is a MySQL branch version adopting a Maria storage engine, is mainly maintained by an open source community, adopts GPL authorization permission to realize the MariaDB, aims to be completely compatible with MySQL, and comprises an API and a command line, so that the MariaDB can easily become a substitute of MySQL. In terms of the storage engine, XtraDB (English: XtraDB) is used instead of InoDB of MySQL.
sql (Structured Query Language), a high-level non-procedural programming Language, allows users to work on high-level data structures. The method does not require a user to specify a data storage method and does not require the user to know a specific data storage mode, so that different database systems with completely different underlying structures can use the same structured query language as an interface for data input and management. The structured query language statements can be nested, which allows for great flexibility and powerful functionality.
xml (Extensible Markup Language) is a Markup Language for Markup electronic documents to have a structure. In electronic computers, a label refers to a symbol of information that can be understood by a computer, and by this label, various information such as articles and the like can be handled between computers. It can be used to mark data, define data types, and is a source language that allows a user to define his or her own markup language. It is well suited for world wide web transport, providing a unified approach to describing and exchanging structured data that is independent of the application or vendor. Is a cross-platform, content-dependent technology in the Internet environment and is also an effective tool today for processing distributed structural information.
In one example, the step of generating test data of the unit under test according to the service data and the configuration file may include the following sub-steps:
s41, extracting a storage data structure from the configuration file;
and S42, filling the service data in the storage data structure, and generating the test data of the unit to be tested according to the filled service data.
In a specific implementation, service data required for testing a unit to be tested can be acquired through a storage data structure of a configuration file, and test data is constructed in an xml file.
In one example, taking a payment unit as an example, the required test data may be an order form. The storage data structure may be generated using the order table as a template, according to the structure of the order table and the composition parameters. The composition parameters such as order form may include parameter types such as product name, unit price of product, quantity of product, etc. When the service data required by the payment unit needs to be acquired, matching operation can be performed in the service data through the parameter type defined by the storage data structure to obtain the corresponding service data.
Step 305, creating a mock object of a dependent unit to simulate the execution of the dependent unit;
the mock is a test method which is created by using a virtual object for some objects which are not easy to construct or obtain in the test process, and the virtual object is the mock object.
In the embodiment of the invention, in order to reduce the occupation of time and resources by the execution of the dependent unit, a mock object of the dependent unit can be created to simulate the execution of the dependent unit, so that the feedback information of the dependent unit can be quickly obtained.
In one example, creating a mock object of a dependency unit to simulate the step of executing the dependency unit includes:
s51, determining the API interface of the dependency unit and obtaining the data structure of the API interface;
and S52, generating a mock object of the dependent unit based on the data structure of the API interface so as to simulate the execution of the dependent unit.
In practical applications, the dependent unit generally has some API interfaces for data interaction with other units, so that the dependent unit can execute normally. According to the embodiment of the invention, the data structure of the API of the dependent unit is obtained, and the mock is used for simulating the data structure, so that the mock object of the dependent unit is generated. The mock object can simulate the execution of the dependent unit, and directly returns a feedback result to the unit to be tested when receiving a call request of the unit to be tested, without actually executing the dependent unit.
And step 306, testing the unit to be tested by using the test data and the mock object to obtain a test result.
After the test data and the mock object are obtained, the unit to be tested can be tested by combining the test data and the mock object.
In one example, the step of testing the unit under test with the test data and the mock object to obtain the test result may include the following sub-steps:
s61, obtaining return data returned by the mock object based on the call request of the unit to be tested;
and S62, testing the unit to be tested based on the execution flow of the unit to be tested by adopting the test data and the return data to obtain a test result.
In the embodiment of the invention, after the test data is obtained, the execution flow of the unit to be tested can be executed by adopting the test data, and when the return data of the dependent unit needs to be called, a calling request is sent to the mock object to obtain the return data generated after the mock object simulates the dependent unit to execute, so that the execution flow of the whole unit to be tested is completed, and the execution result is obtained as the test result.
And 307, verifying the test result to obtain a verification result of the unit to be tested.
In one example, step 307 may include the following sub-steps:
s71, acquiring a target result of the unit to be tested;
s72, verifying the test result by adopting the target result;
and S73, when the target result is the same as the test result, judging that the unit to be tested passes the test.
In a specific implementation, the execution data of the unit to be tested, which is executed correctly in the past, may be saved as the comparison data, and the comparison data may be saved in an xml format file, or may be saved in another manner, which is not limited in the present invention. When the unit to be tested is tested, the target result can be matched in the comparison data through the test data, and the target result is compared with the test result of the unit to be tested, so that whether the unit to be tested passes the test or not is judged.
According to the method and the device, the mock object of the dependent unit of the unit to be tested is created to simulate the execution of the dependent unit to obtain the return data required by the unit to be tested, so that the execution flow of the dependent unit is not required to be executed, the execution process of the unit test is reduced, the test program is simplified, and the expenditure of the unit test is reduced. And the data storage structure of the service data is defined in the MariaDB database, so that the service data can be acquired without writing a plurality of native jdbc. In addition, the construction of the test data is carried out through the xml file, the generation flow of the test data is simplified, and the time cost and the overhead cost for generating the test data are reduced.
For ease of understanding, the present invention is described below by way of specific examples.
Referring to fig. 4, fig. 4 is a schematic diagram illustrating a unit testing method according to an embodiment of the present invention.
As shown in fig. 4, the architecture diagram includes five links, which are: pre, parameter, mock, execute, and post.
The preposition link is mainly a process of storing business data through a MariaDB database and generating test data. Specifically, the data may be directly stored in the maria db database according to the configuration file corresponding to the unit test (mainly for objective information related to the business object), or may be first constructed in an xml format or the like, and then stored in the maria db database according to the configuration file (mainly for subjective information determined by the user through selection).
The parameter link is mainly used for determining subjective information of the user, and includes but is not limited to determination through input, clicking and the like. The parameter format may be xml, json, testcase, etc.
The mock link mainly creates a mock object of a dependent unit through mockito. mocktio is a mocking framework for Java that eliminates the need for expected behaviors (behaviors) by checking after execution what has been called.
And the execution link mainly runs the unit to be tested through the test data and the return data of the mock object to obtain a test result.
The post link is mainly used for verifying the test result through the stored target result.
Referring to fig. 5, fig. 5 is a block diagram of a unit testing apparatus according to an embodiment of the present invention.
An embodiment of the present invention provides a unit testing apparatus, including:
a unit determining module 501, configured to determine a unit to be tested and a dependent unit of the unit to be tested in a preset service;
a test data obtaining module 502, configured to obtain test data of a unit to be tested;
a mock object creating module 503, configured to create a mock object of a dependent unit to simulate execution of the dependent unit;
and the testing module 504 is configured to test the unit to be tested by using the test data and the mock object to obtain a test result.
In this embodiment of the present invention, the test data obtaining module 502 includes:
the data acquisition submodule is used for acquiring service data of a preset service;
the configuration file acquisition submodule is used for acquiring a configuration file of the unit to be tested;
and the test data generation submodule is used for generating test data of the unit to be tested according to the service data and the configuration file.
In the embodiment of the present invention, the test data generation sub-module includes:
the storage data structure extracting unit is used for extracting the storage data structure from the configuration file;
and the test data generating unit is used for filling the service data in the storage data structure and generating the test data of the unit to be tested through the filled service data.
In this embodiment of the present invention, the mock object creating module 503 includes:
the data interface acquisition submodule is used for determining an API (application program interface) of the dependency unit and acquiring a data structure of the API;
and the mock object generation submodule is used for generating a mock object of the dependency unit based on the data structure of the API interface so as to simulate the execution of the dependency unit.
In an embodiment of the present invention, the test module 504 includes:
the return data acquisition submodule is used for acquiring return data returned by the mock object based on the call request of the unit to be tested;
and the test submodule is used for testing the unit to be tested based on the execution flow of the unit to be tested by adopting the test data and the return data to obtain a test result.
In the embodiment of the present invention, the method further includes:
and the verification module is used for verifying the test result to obtain the verification result of the unit to be tested.
In an embodiment of the present invention, a verification module includes:
the target result obtaining submodule is used for obtaining a target result of the unit to be tested;
the verification submodule is used for verifying the test result by adopting the target result;
and the judging submodule is used for judging that the unit to be tested passes the test when the target result is the same as the test result.
An embodiment of the present invention further provides an electronic device, where the device includes a processor and a memory:
the memory is used for storing the program codes and transmitting the program codes to the processor;
the processor is used for executing the unit test method of the embodiment of the invention according to the instructions in the program codes.
The embodiment of the invention also provides a computer-readable storage medium, which is used for storing the program code, and the program code is used for executing the unit testing method of the embodiment of the invention.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
The embodiments in the present specification are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, apparatus, or computer program product. Accordingly, embodiments of the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, embodiments of the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
Embodiments of the present invention are described with reference to flowchart illustrations and/or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing terminal to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing terminal to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing terminal to cause a series of operational steps to be performed on the computer or other programmable terminal to produce a computer implemented process such that the instructions which execute on the computer or other programmable terminal provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present invention have been described, additional variations and modifications of these embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all such alterations and modifications as fall within the scope of the embodiments of the invention.
Finally, it should also be noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "include", "including" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or terminal device including a series of elements includes not only those elements but also other elements not explicitly listed or inherent to such process, method, article, or terminal device. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in the process, method, article, or terminal equipment comprising the element.
The above-mentioned embodiments are only used for illustrating the technical solutions of the present invention, and not for limiting the same; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.

Claims (10)

1. A method of unit testing, comprising:
determining a unit to be tested and a dependent unit of the unit to be tested in a preset service;
acquiring test data of the unit to be tested;
creating a mock object of the dependent unit to simulate execution of the dependent unit;
and testing the unit to be tested by adopting the test data and the mock object to obtain a test result.
2. The method of claim 1, wherein the step of obtaining test data for the unit under test comprises:
acquiring service data of the preset service;
acquiring a configuration file of the unit to be tested;
and generating test data of the unit to be tested according to the service data and the configuration file.
3. The method of claim 2, wherein the step of generating test data for the unit under test based on the service data and the configuration file comprises:
extracting a storage data structure from the configuration file;
and filling the service data in the storage data structure, and generating the test data of the unit to be tested according to the filled service data.
4. The method of claim 1, 2 or 3, wherein the step of creating a mock object of the dependent unit to simulate the execution of the dependent unit comprises:
determining an API (application program interface) of the dependency unit and acquiring a data structure of the API;
and generating a mock object of the dependent unit based on the data structure of the API interface so as to simulate the execution of the dependent unit.
5. The method of claim 1, 2 or 3, wherein said step of testing said unit under test with said test data and said mock object to obtain a test result comprises:
obtaining return data returned by the mock object based on the call request of the unit to be tested;
and testing the unit to be tested based on the execution flow of the unit to be tested by adopting the test data and the return data to obtain a test result.
6. The method of claim 1, 2 or 3, wherein the step of testing the unit under test with the test data and the mock object to obtain a test result further comprises:
and verifying the test result to obtain a verification result of the unit to be tested.
7. The method of claim 6, wherein the step of verifying the test result to obtain the verification result of the unit under test comprises:
acquiring a target result of the unit to be tested;
verifying the test result by adopting the target result;
and when the target result is the same as the test result, judging that the unit to be tested passes the test.
8. A unit testing apparatus, comprising:
the unit determining module is used for determining a unit to be tested and a dependent unit of the unit to be tested in a preset service;
the test data acquisition module is used for acquiring the test data of the unit to be tested;
a mock object creating module, configured to create a mock object of the dependent unit, so as to simulate execution of the dependent unit;
and the testing module is used for testing the unit to be tested by adopting the test data and the mock object to obtain a test result.
9. An electronic device, comprising a processor and a memory:
the memory is used for storing program codes and transmitting the program codes to the processor;
the processor is configured to perform the unit testing method of any of claims 1-6 according to instructions in the program code.
10. A computer-readable storage medium, characterized in that the computer-readable storage medium is configured to store a program code for performing the unit testing method of any of claims 1-6.
CN202210302354.6A 2022-03-25 2022-03-25 Unit testing method and device, electronic equipment and storage medium Pending CN114579470A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210302354.6A CN114579470A (en) 2022-03-25 2022-03-25 Unit testing method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210302354.6A CN114579470A (en) 2022-03-25 2022-03-25 Unit testing method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114579470A true CN114579470A (en) 2022-06-03

Family

ID=81782544

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210302354.6A Pending CN114579470A (en) 2022-03-25 2022-03-25 Unit testing method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114579470A (en)

Similar Documents

Publication Publication Date Title
US8056057B2 (en) System and method for generating business process test elements
US11762717B2 (en) Automatically generating testing code for a software application
CN111832236B (en) Chip regression testing method and system, electronic equipment and storage medium
Martin-Lopez et al. Specification and automated analysis of inter-parameter dependencies in web APIs
US7392162B1 (en) System and method for device developing model networks purely by modelling as meta-data in a software application
US20070061780A1 (en) Enterprise resource planning system test framework
CN110362490B (en) Automatic testing method and system for integrating iOS and Android mobile applications
US20140331212A1 (en) Computer implemented system and method for indexing and annotating use cases and generating test scenarios therefrom
CN107729246A (en) For the auxiliary test methods of intended application, device, equipment and storage medium
US8661414B2 (en) Method and system for testing an order management system
US7975259B2 (en) Verification of customization results
CN117112060A (en) Component library construction method and device, electronic equipment and storage medium
Schmid et al. A survey of simulation tools for requirements engineering
CN114579470A (en) Unit testing method and device, electronic equipment and storage medium
US20080066005A1 (en) Systems and Methods of Interfacing with Enterprise Resource Planning Systems
Musliu et al. Software automated testing using bdd approach with cucumber framework
US11989122B2 (en) Handling mock objects that are written in the form of multiple assignment instructions
Mosayeb et al. A repository of automatic GUI test patterns in Android applications: Specification and Analysis using Alloy modeling language
CN117971702A (en) Response test method and device for service platform, medium and electronic equipment
Mittal No Code Test Recording for iOS Applications
Pradhan User interface test automation and its challenges in an industrial scenario
Farchi et al. Random Test Generation of Application Programming Interfaces
Tran Testing React Applications Using React Testing Library
Dehganpour Smart Scm with instant developer
Trad Integration testing for enterprise web applications

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