Software test stubs based on an automated testing framework, writing method, and application method
By writing software test piles in the automated test framework and integrating them with the automated test framework, the problems of poor flexibility and high development costs caused by the separation of software test piles and automated test frameworks in the traditional mode are solved, and more efficient writing and lower development and maintenance costs are achieved.
Patent Information
- Application Number
- CN202111021935.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-01
- Publication Date
- 2025-06-20
- Estimated Expiration
- 2041-09-01
AI Technical Summary
The separation of traditional software testing piles from the automated testing framework results in poor system flexibility, high development costs, and difficulty in meeting the needs of the automated testing framework.
Write software test piles into the automated testing framework, so that they are integrated with the automated testing framework, and use the same framework, language, grammar, etc., thereby reducing communication costs and repeated coding costs.
It greatly improves the flexibility of writing software test piles, reduces the high development and maintenance costs caused by developing automated test frameworks and software test piles under the traditional mode, and solves the need for verification of software test pile messages by the automated test framework.
Smart Images

Figure CN113868117B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the technical field of automated testing, and more particularly to a software test stub, a writing method, and an application method based on an automated testing framework. Background Art
[0002] Traditional software test stubs are separated from the automated testing framework, resulting in the following disadvantages: First, the system flexibility is poor. When the automated testing framework needs to verify the content received by the software test stub, it needs to communicate with the software test stub to obtain it. This process is not flexible and there may be error rates such as network fluctuations or environmental interference. Second, the development cost is high. When a new protocol is added to the system under test, after the automated testing framework develops an automated testing protocol library for this protocol, it is also necessary to develop a corresponding protocol library for the software test stub, that is, two sets of protocol libraries need to be developed for the same protocol. Summary of the Invention
[0003] The purpose of the embodiments of the present invention is to provide a software test stub based on an automated testing framework. Since the automated testing framework and the software test stub are integrated, and the frameworks, languages, grammars, etc. used are the same, the communication cost and repeated coding cost in the process of writing the software test stub are greatly reduced.
[0004] Specifically, the present invention provides a software test stub based on an automated testing framework. The automated testing framework includes a function module, a test case module, and a data module. The automated testing script in the test case module calls the function module and the data module to send a request to an external device.
[0005] The software test stub includes: a mapping module and an entity module;
[0006] The mapping module is written in the function module, and the entity module is written in the test case module;
[0007] The entity module is used to listen to the message sent by the external device based on the request, save a copy of the listened message to the data module, and call the mapping module for processing;
[0008] The mapping module is used to match the corresponding request and response according to the message, and dynamically process the response as needed and return it to the external device, so that the external device processes the request according to the response and returns it to the automated testing script in the test case module.
[0009] In the present invention, by writing the software test stub into the automated test framework, the automated test framework and the software test stub are integrated. The frameworks, languages, grammars, etc. used are the same, enabling the writer of the automated test framework script to be the writer of the software test stub. Compared with the traditional mode where the automated test framework and the software test stub are separated, the flexibility of writing is greatly improved, and the high development costs and maintenance costs brought by the traditional development of the automated test framework and the software test stub are significantly reduced.
[0010] In one embodiment, the function module includes: function methods and protocol libraries.
[0011] In one embodiment, the process of writing the mapping module into the function module is as follows:
[0012] Implement the response according to actual needs and write at least one set of mapping configurations;
[0013] Match the message with the requests of all mapping configurations;
[0014] After matching, take out the response corresponding to the matched request;
[0015] Extract content from the message as needed to replace the corresponding content in the taken-out response;
[0016] Reply the replaced response to the source address of the matched request.
[0017] In one embodiment, the process of writing the entity module into the test case module is as follows:
[0018] Call the protocol listening method corresponding to the protocol library in the function module to listen to the message sent by the external device based on the request, and save a copy of the listened message to the data module;
[0019] Use the message as an input parameter and call the mapping module for processing to complete the writing of the entity module.
[0020] The present invention also provides a method for writing a software test stub based on an automated test framework. The automated test framework includes a function module, a test case module, and a data module;
[0021] Write the mapping module of the software test stub into the function module and write the entity module of the software test stub into the test case module;
[0022] The automated test script in the test case module calls the function module and the data module to send requests to an external device;
[0023] Monitor the message sent by the external device based on the request, save a copy of the message to the data module by the entity module, and call the mapping module for processing to complete the programming of the entity module;
[0024] Match the corresponding request and response according to the message, and dynamically process the response as needed and return it to the external device to complete the programming of the mapping module.
[0025] In one embodiment, the function module includes: function methods and protocol libraries.
[0026] In one embodiment, the processing the message as needed and returning a response to the external device to complete the programming of the mapping module includes:
[0027] Implement the response and write at least one set of mapping configurations according to actual needs;
[0028] Match the message with the requests of all mapping configurations;
[0029] After matching, take out the response corresponding to the matched request;
[0030] Extract content from the message as needed to replace the corresponding content in the taken-out response;
[0031] Reply the replaced response to the source address of the matched request to complete the programming of the mapping module.
[0032] In one embodiment, the monitoring the message sent by the external device based on the request and saving a copy of the message to the data module and calling the mapping module for processing includes:
[0033] Call the protocol listening method corresponding to the protocol library in the function module to monitor the message sent by the external device based on the request, and save a copy of the monitored message to the data module;
[0034] Use the message as an input parameter and call the mapping module for processing to complete the programming of the entity module.
[0035] The present invention also provides an application method of a software test stub based on an automated test framework. The automated test framework includes a function module, a test case module, and a data module; the mapping module of the software test stub is programmed in the function module, and the entity module of the software test stub is programmed in the test case module. The application method includes:
[0036] The automated test script in the automated test framework calls the data module and the function module to initiate a request to an external device;
[0037] The external device calls the entity module to send a message based on the request;
[0038] The entity module calls the function module to receive a message, saves a copy of the message to the data module, and transfers the message to the mapping processing module for processing and returns a response to the external device;
[0039] The external device processes according to the response and returns it to the automated test script in the automated test framework. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] The non-limiting and non-exhaustive embodiments of the present invention are described with reference to the following drawings by way of example, wherein:
[0041] Figure 1 FIG. shows a schematic structural diagram of a software test stub based on an automated test framework according to an embodiment of the present invention;
[0042] Figure 2 FIG. shows a flowchart of a method for writing a software test stub based on an automated test framework according to an embodiment of the present invention;
[0043] Figure 3 FIG. shows a schematic diagram of an application method of a software test stub based on an automated test framework according to an embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0044] In order to make the above and other features and advantages of the present invention clearer, the present invention will be further described below with reference to the drawings. It should be understood that the specific embodiments given herein are for the purpose of explaining to those skilled in the art and are merely exemplary, not restrictive.
[0045] In order to enable those skilled in the art to better understand the technical solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
[0046] It should be noted that the terms "first", "second", etc. in the description, claims and the above-mentioned drawings of the present invention are used to distinguish similar objects, and do not necessarily have to be used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances, so that the embodiments of the present invention described here can be implemented in an order other than those illustrated or described here. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device comprising a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0047] The present invention realizes a software test stub integrated with an automated test framework, maximizing flexibility. For the writing of a new protocol, a set of protocol libraries are shared by the automated test framework and the software test stub, greatly improving the development efficiency of the automated test framework and the software test stub for the new protocol library. At the same time, since the automated test framework and the software test stub are integrated, it well solves the part where the traditional software test stub is difficult to meet the requirements of the automated test framework. For example, when the automated test framework verifies the message content received by the software test stub, because they are integrated, the message content received by the software test stub is shared with the automated test framework and the format and syntax are consistent, eliminating the need to write additional logic to obtain it, and also avoiding many problems caused by inconsistent formats, languages, and syntax in the traditional mode, as well as greatly reducing the high development and maintenance costs incurred to solve and be compatible with these problems.
[0048] In addition, since the automated test framework and the software test stub are integrated and use the same framework, language, syntax, etc., the script writer of the automated test framework can be the writer of the software test stub logic. Compared with the traditional mode where the automated test framework and the software test stub are separated, the communication cost and duplicate coding cost in the writing process are greatly reduced.
[0049] Figure 1 The structural schematic diagram of a software test stub based on an automated test framework according to an embodiment of the present invention is shown.
[0050] In one embodiment, referring to Figure 1 , the software test stub 100 based on the automated test framework includes:
[0051] The automated test framework includes a function module, a test case module, and a data module. The automated test scripts in the test case module call the function module and the data module to send requests to external devices. The function module includes: function methods and protocol libraries. The automated test framework further includes a running module. The function module is used to provide function methods, protocol libraries, etc. for the test case module. The test case module is used to carry the automated test scripts. The running module is used to run the test case module and call the software test stub entity module. The data module is used for data access between modules of the automated test framework.
[0052] The software test stub includes: a mapping module and an entity module. The mapping module is written in the function module, and the entity module is written in the test case module.
[0053] The entity module is used to listen for the messages sent by the external device based on the request, save a copy of the listened message to the data module, and call the mapping module for processing.
[0054] The mapping module is used to match the corresponding requests and responses according to the message, and dynamically process the response as needed and return it to the external device, so that the external device processes the request according to the response and returns it to the automated test script in the test case module.
[0055] It can be understood that the mapping module is used to match the request and its corresponding response according to, for example, "the message received by the software test stub", and dynamically process the response as needed and then return it to the source address of "the message received by the software test stub". The entity module is used to continuously listen for the messages of the external device, save a copy of the message, and then transfer it to the mapping module for processing.
[0056] In one embodiment, the process of writing the mapping module in the function module is as follows:
[0057] Implement the response according to actual needs and write at least one set of mapping configurations;
[0058] Match the message with the requests of all mapping configurations;
[0059] After matching, take out the response corresponding to the matched request;
[0060] Extract the content from the message as needed to replace the corresponding content in the taken-out response;
[0061] Reply the replaced response to the source address of the matched request.
[0062] It can be understood that the mapping module of the software test stub is implemented by using the function module of the automated test framework. The input parameter is the "message received by the software test stub". The internal processing is to write several groups of mapping configurations according to the actual needs for the simulated response and its corresponding request, match the "message received by the software test stub" with the requests of all mapping configurations, and after matching, extract the response corresponding to the matched request and extract the content from the "message received by the software test stub" as needed for the response to use, so as to achieve dynamic response. For example, write a group of mapping configurations, where the "request" configuration is "when the message contains 123", and the "response" configuration is "abc${variable1}xyz", where ${variable1} is the content intercepted according to the left and right boundaries of the "message received by the software test stub". The left boundary is set to 123 and the right boundary is set to 789. When the "message received by the software test stub" is 123456789, extract the content between the left and right boundaries 123 and 789 and use it as the value of ${variable1} to replace the corresponding variable name in the "response" to achieve dynamic response. In this embodiment, after the "response" is replaced, it becomes "abc456xyz". After replacement, return this replaced "response" to the source address of the request to complete a main workflow of the mapping module.
[0063] In one embodiment, the process of writing the entity module in the test case module is as follows:
[0064] Call the protocol listening method corresponding to the protocol library in the function module to listen to the message sent by the external device based on the request, and save a copy of the listened message in the data module;
[0065] Use the message as an input parameter and call the mapping module for processing to complete the writing of the entity module.
[0066] It can be understood that when using the test case module of the automated test framework to write the software test stub entity module, the internal processing is to call the protocol listening method corresponding to the protocol library in the function module of the automated test framework for listening, save a copy of the "message received by the software test stub" listened to in the data module of the automated test framework, then use this message as an input parameter, call the mapping module, and repeat this process to achieve continuous listening, saving the copy, calling the mapping module to process and return the simulated message, that is, complete the writing of the software test stub entity module.
[0067] In the present invention, by integrating the automated test framework with the software test stub, using the same framework, language, grammar, etc., the writer of the automated test framework script can be the writer of the software test stub. Compared with the traditional mode of separating the automated test framework and the software test stub, the flexibility of writing is greatly improved, and the high development cost and maintenance cost brought by the traditional need to develop the automated test framework and the software test stub are reduced.
[0068] Figure 2 The flowchart of the writing method of the software test stub based on the automated test framework according to an embodiment of the present invention is shown.
[0069] Referring to Figure 2 As shown, the automated test framework includes a function module, a test case module, and a data module; wherein, the function module includes: function methods and protocol libraries.
[0070] The writing method 200 includes:
[0071] Step 210, writing the mapping module of the software test stub in the function module, and writing the entity module of the software test stub in the test case module;
[0072] Step 220, the automated test script in the test case module calls the function module and the data module to send a request to an external device;
[0073] Step 230, listening to the message sent by the external device based on the request, the entity module saves a copy of the message to the data module, and calls the mapping module for processing to complete the writing of the entity module;
[0074] Step 240, matching the corresponding request and response according to the message, and dynamically processing the response as needed and returning it to the external device to complete the writing of the mapping module.
[0075] In an embodiment, the processing the message as needed and returning a response to the external device to complete the writing of the mapping module includes:
[0076] Implementing the response and writing at least one set of mapping configurations according to actual needs;
[0077] Matching the message with the requests of all mapping configurations;
[0078] After matching, taking out the response corresponding to the matched request;
[0079] Extracting content from the message as needed to replace the corresponding content in the taken-out response;
[0080] Return the replaced response to the source address of the matching request to complete the writing of the mapping module.
[0081] In one embodiment, listening to the message sent by the external device based on the request, saving a copy of the message to the data module, and calling the mapping module for processing includes:
[0082] Call the protocol listening method corresponding to the protocol library in the function module to listen to the message sent by the external device based on the request, and save a copy of the listened message to the data module;
[0083] Use the message as an input parameter and call the mapping module for processing to complete the writing of the entity module.
[0084] Figure 3 FIG. shows a schematic diagram of an application method of a software test stub based on an automated test framework according to an embodiment of the present invention.
[0085] The present invention also provides an application method of a software test stub based on an automated test framework. The automated test framework includes a function module, a test case module, and a data module; the mapping module of the software test stub is written in the function module, and the entity module of the software test stub is written in the test case module. The application method includes:
[0086] The automated test script in the automated test framework calls the data module and the function module to initiate a request to an external device;
[0087] The external device calls the entity module to send a message based on the request;
[0088] The entity module calls the function module to receive the message, saves a copy of the message to the data module, and transfers the message to the mapping processing module for processing and returns a response to the external device;
[0089] The external device processes according to the response and returns it to the automated test script in the automated test framework.
[0090] It can be understood that with reference to Figure 3, the automated test framework running module sequentially calls the software test stub entity module and the automated test script. The automated test script calls the data module, protocol library, and function methods to send a request to Server A. To process this request, Server A needs to send a request to Server B. After processing according to the response from Server B, it returns to the automated test script. Since Server B is replaced by the software test stub in this case, Server A will not call Server B but instead call the software test stub entity module to send the message. Then, the entity module calls the protocol library to receive the message and saves a copy of "the message received by the software test stub" to the data module. Next, it transfers the message to the mapping processing module for processing and returns a simulated response to Server A. Server A processes according to the simulated response and then returns it to the automated test script, completing a main workflow of the software test stub. Among them, the software test stub entity module saves a copy of "the message received by the software test stub" to the data module in real time. The automated test script of the automated test framework reads the copy of "the message received by the software test stub" in the data module as needed for various purposes, including but not limited to verifying the content received by the software test stub.
[0091] In this embodiment, since the automated test framework script and the software test stub are integrated, with the same framework, language, and syntax used and data shared, it greatly improves the flexibility of their writing and use. At the same time, a set of protocol libraries can be used by both, significantly reducing the high development cost and maintenance cost brought by the traditional need to develop two sets of protocol libraries.
[0092] The technical features of the above embodiments can be combined arbitrarily. For the sake of brevity in description, not all possible combinations of the technical features in the above embodiments are described. However, as long as these combinations of technical features do not conflict, they should all be considered as within the scope described in this specification.
[0093] Although the present invention has been described in conjunction with the embodiments, those skilled in the art should understand that the above description and the accompanying drawings are merely exemplary and not restrictive. The present invention is not limited to the disclosed embodiments. Various modifications and variations are possible without departing from the spirit of the present invention.
Claims
1. A software test stub based on an automated test framework, the automated test framework including a function module, a test case module, and a data module, and the automated test script in the test case module calling the function module and the data module to initiate a request to an external device; characterized in that, The software test stub includes: a mapping module and an entity module; The mapping module is written within the function module, and the entity module is written within the test case module; The entity module is used to monitor the message sent by the external device based on the request, save a copy of the monitored message to the data module, and call the mapping module for processing; The mapping module is used to match the corresponding request and response according to the message, and dynamically process the response as needed and return it to the external device, so that after the external device processes the request according to the response, it is returned to the automated test script in the test case module; The process of writing the mapping module within the function module is as follows: Implement the response according to actual needs and write at least one set of mapping configurations; Match the message with the requests of all mapping configurations; After matching, take out the response corresponding to the matched request; Extract content from the message as needed to replace the corresponding content in the taken-out response; Reply the replaced response to the source address of the matched request; The process of writing the entity module within the test case module is as follows: Call the protocol listening method corresponding to the protocol library in the function module to monitor the message sent by the external device based on the request, and save a copy of the monitored message to the data module; Use the message as an input parameter and call the mapping module for processing to complete the writing of the entity module.
2. The software test stub according to claim 1, characterized in that, The function module includes function methods and a protocol library.
3. A method for writing a software test stub based on an automated test framework, characterized in that, The automated test framework includes a function module, a test case module, and a data module; Write the mapping module of the software test stub within the function module, and write the entity module of the software test stub within the test case module; The automated test script in the test case module calls the function module and the data module to initiate a request to an external device; Monitor the message sent by the external device based on the request. The entity module saves a copy of the message to the data module, calls the mapping module for processing to complete the writing of the entity module; Match the corresponding request and response according to the message, and dynamically process the response as needed and return it to the external device to complete the writing of the mapping module; The process of writing the mapping module within the function module is as follows: Implement the response according to actual needs and write at least one set of mapping configurations; Match the message with the requests of all mapping configurations; After matching, take out the response corresponding to the matched request; Extract content from the message as needed to replace the corresponding content in the taken-out response; Reply the replaced response to the source address of the matched request; The process of writing the entity module within the test case module is as follows: Call the protocol listening method corresponding to the protocol library in the function module to monitor the message sent by the external device based on the request, and save a copy of the monitored message to the data module; Use the message as an input parameter and call the mapping module for processing to complete the writing of the entity module.
4. The writing method according to claim 3, characterized in that, The function module includes function methods and a protocol library.
5. An application method of a software test stub based on an automated test framework, the automated test framework including a function module, a test case module, and a data module; the mapping module of the software test stub is written in the function module, the entity module of the software test stub is written in the test case module, and the application method includes: The automated test script in the automated test framework calls the data module and the function module to send a request to an external device; The external device calls the entity module based on the request to send a message; The entity module calls the function module to receive the message, saves a copy of the message to the data module, and transfers the message to the mapping module for processing and returns a response to the external device; The external device processes according to the response and returns it to the automated test script in the automated test framework; The process of writing the mapping module within the function module is as follows: Implement the response and write at least one set of mapping configurations according to actual needs; Match the message with the requests of all mapping configurations; After matching, extract the response corresponding to the matched request; Extract content from the message as needed to replace the corresponding content in the extracted response; Reply the replaced response to the source address of the matched request; The process of writing the entity module in the test case module is as follows: Call the protocol listening method corresponding to the protocol library in the function module to listen to the message sent by the external device based on the request, and save a copy of the listened message to the data module; Use the message as an input parameter and call the mapping module for processing to complete the writing of the entity module.
Citation Information
Patent Citations
Method and system for automatically testing digital television middleware interface
CN102110049A
Automatic test method, device and system of Android interface
CN104834586A