Test method, device, equipment and storage medium
By reading multiple test scenario parameter groups from the data source and generating multiple test scenario data, the network request message is simulated to call the control interface logic to be tested, which solves the problem that MockMvc can only simulate one request scenario and realizes the interface Adequate testing improves test coverage and efficiency.
Patent Information
- Application Number
- CN202011435724.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-10
- Publication Date
- 2025-01-21
- Estimated Expiration
- 2040-12-10
AI Technical Summary
The existing MockMvc technology can only simulate one Http request scenario, resulting in the need to write multiple unit test code to improve interface test coverage, increasing work pressure.
By reading multiple test scenario parameter groups from the data source, generating multiple test scenario data based on a single scenario generation logic, and calling the control interface logic to be tested in the form of simulated network request messages, multiple request scenarios are realized. simulation.
It realizes that you only need to write the scenario generation logic once for a tested interface, configure multiple message data into the data source, and simulate Http requests in the form of simulated network request messages to fully test the interface and save the interface test code. Improved interface test coverage.
Smart Images

Figure CN112559335B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of testing technology, and in particular to a testing method, device, equipment and storage medium. Background Art
[0002] MockMvc can simulate Http requests and directly use the form of simulated network request messages to convert them into calls to the control (Controller) interface, making the test fast and independent of the network environment.
[0003] Although MockMvc can simulate HTTP request messages as the input of the Controller interface, it can only simulate one request scenario at a time. In order to improve the interface test coverage and test multiple interface request scenarios, it is necessary to write multiple unit test codes, which increases the work pressure. Summary of the invention
[0004] Embodiments of the present invention provide a testing method, apparatus, device and storage medium to implement simulation of multiple request scenarios based on a single scenario generation logic.
[0005] In a first aspect, an embodiment of the present invention provides a testing method, the method comprising:
[0006] Reading at least two test scenario parameter groups from a data source, and generating at least two test scenario data according to the read at least two test scenario parameter groups based on at least one scenario generation logic;
[0007] According to the at least two test scenario data, calling the control interface logic to be tested in the form of a simulated network request message;
[0008] A test result of the control interface logic to be tested is determined according to the output result of the control interface logic to be tested.
[0009] In a second aspect, an embodiment of the present invention further provides a testing device, the device comprising:
[0010] A scenario data generation module, used to read at least two test scenario parameter groups from a data source, and generate at least two test scenario data according to the at least two test scenario parameter groups read based on at least one scenario generation logic;
[0011] A request simulation module, used to call the control interface logic to be tested in the form of a simulated network request message according to the at least two test scenario data;
[0012] The test result determination module is used to determine the test result of the control interface logic to be tested according to the output result of the control interface logic to be tested.
[0013] In a third aspect, an embodiment of the present invention further provides a device, the device comprising:
[0014] one or more processors;
[0015] a storage device for storing one or more programs,
[0016] When the one or more programs are executed by the one or more processors, the one or more processors implement the testing method as described in any one of the embodiments of the present invention.
[0017] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a test method as described in any one of the embodiments of the present invention.
[0018] The embodiment of the present invention reads at least two test scenario parameter groups from a data source, and based on at least one scenario generation logic, generates at least two test scenario data according to the at least two test scenario parameter groups read; according to the at least two test scenario data, the control interface logic to be tested is called in the form of a simulated network request message, thereby realizing the simulation of multiple request scenarios based on a single scenario generation logic, and then realizing that for a tested interface, only one scenario generation logic needs to be written, multiple message data are configured in the data source, and the Http request is simulated in the form of a simulated network request message, so as to fully test the interface. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1 A flow chart of a testing method provided in Embodiment 1 of the present invention;
[0020] Figure 2 is a flow chart of a testing method provided in Example 2 of the present application;
[0021] Figure 3 is a flow chart of a testing method provided in Example 3 of the present application;
[0022] Figure 4 is a flow chart of a testing method provided in Example 4 of the present application;
[0023] Figure 5 is a schematic diagram of an input interface provided by Embodiment 4 of the present invention;
[0024] Figure 6 is a structural schematic diagram of a testing device provided in Embodiment 5 of the present invention;
[0025] Figure 7 A schematic diagram of the structure of a device provided in Example 6 of the present invention. DETAILED DESCRIPTION
[0026] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It should also be noted that, for ease of description, only parts related to the present invention, rather than all structures, are shown in the accompanying drawings.
[0027] Embodiment 1
[0028] Figure 1 This is a flow chart of a test method provided in Embodiment 1 of the present invention. This embodiment is applicable to the case where a high coverage and low workload test is performed on the control interface logic to be tested. The method can be executed by a test device, which can be implemented by software and / or hardware. Figure 1 , the testing method provided by the embodiment of the present invention includes:
[0029] S110, reading at least two test scenario parameter groups from a data source, and generating at least two test scenario data according to the read at least two test scenario parameter groups based on at least one scenario generation logic.
[0030] The data source is a storage medium storing at least two test scenario parameter groups. Specifically, the data source may be a file, a database, or a table.
[0031] A test scenario parameter group refers to a combination of at least one parameter describing a test scenario. Typically, the test scenario parameter group can be configured by a tester.
[0032] The at least two test scenario parameter groups include two test scenario parameter groups, three test scenario parameter groups, and more test scenario parameter groups.
[0033] The scenario generation logic is the logic for generating test scenario data.
[0034] Test scenario data refers to data that describes the test scenario.
[0035] Specifically, based on Junit, at least two test scenario parameter groups may be read from a data source, and based on at least one scenario generation logic, at least two test scenario data may be generated according to the at least two test scenario parameter groups read.
[0036] Among them, Junit is a widely used Java unit testing framework.
[0037] S120: According to the at least two test scenario data, call the control interface logic to be tested in the form of a simulated network request message.
[0038] The control interface logic to be tested refers to the execution logic of the control interface to be tested.
[0039] The control interface is the Controller interface in web application development. The Controller interface mainly handles external requests.
[0040] S130: Determine a test result of the control interface logic to be tested according to an output result of the control interface logic to be tested.
[0041] Specifically, determining the test result of the control interface logic to be tested according to the output result of the control interface logic to be tested includes:
[0042] The output result of the control interface logic to be tested is compared with the corresponding true value, and the test result of the control interface logic to be tested is determined according to the comparison result.
[0043] The embodiment of the present invention reads at least two test scenario parameter groups from a data source, and based on at least one scenario generation logic, generates at least two test scenario data according to the at least two test scenario parameter groups read; according to the at least two test scenario data, the control interface logic to be tested is called in the form of a simulated network request message, thereby realizing the simulation of multiple request scenarios based on a single scenario generation logic, and then realizing that for a tested interface, only one scenario generation logic needs to be written, multiple message data are configured in the data source, and the Http request is simulated in the form of a simulated network request message, so as to fully test the interface.
[0044] Embodiment 2
[0045] Figure 2 1 is a flow chart of a test method provided in Example 2 of the present application. This embodiment is a refinement of the above S120 based on the above embodiment. Figure 2 , the test method provided in the embodiment of the present application includes:
[0046] S110, reading at least two test scenario parameter groups from a data source, and generating at least two test scenario data according to the read at least two test scenario parameter groups based on at least one scenario generation logic.
[0047] S121. Based on a Mock framework with simulated Http requests, according to the at least two test scenario data, the control interface logic to be tested is called in the form of simulated network request messages.
[0048] Optionally, it can be any Mock framework that can simulate HTTP requests.
[0049] Typically, the Mock framework having simulated HTTP requests includes a MockMvc framework.
[0050] Among them, MockMvc realizes the simulation of Http request, and can directly use the form of simulated network request message to convert it into the call of Controller interface, making the test fast and independent of network environment.
[0051] S130: Determine a test result of the control interface logic to be tested according to an output result of the control interface logic to be tested.
[0052] The embodiment of the present invention uses a mock framework with simulated Http request and calls the control interface logic to be tested in the form of simulated network request messages according to the at least two test scenario data, thereby simulating the Http request.
[0053] Embodiment 3
[0054] Figure 3 This is a flow chart of a test method provided in Example 3 of the present application. This embodiment is a further refinement of the above S110 based on the above embodiment. Figure 3 , the testing method provided in this embodiment includes:
[0055] S111. Based on Feed4Junit, read at least two test scenario parameter groups from a data source, and based on at least one scenario generation logic, generate at least two test scenario data according to the read at least two test scenario parameter groups.
[0056] Among them, Feed4Junit is an open source extension based on Junit. By using the annotations provided by Feed4Junit, users can easily store test data in files or other data sources.
[0057] S120: According to the at least two test scenario data, call the control interface logic to be tested in the form of a simulated network request message.
[0058] S130: Determine a test result of the control interface logic to be tested according to an output result of the control interface logic to be tested.
[0059] The technical solution of the embodiment of the present invention solves the problem of separation of data and code well through Feed4Junit. Feed4Junit is an extension of the Junit test framework. It makes tests easier to write and maintain by operating test data from files and different data sources.
[0060] Because most of the current test logic is implemented based on the Spring framework, in order to adapt to the Spring framework, the Feed4Junit-based method reads at least two test scenario parameter groups from the data source, and generates logic based on at least one scenario, and generates at least two test scenario data according to the read at least two test scenario parameter groups, including:
[0061] Based on the new unit test framework, at least two test scenario parameter groups are read from a data source, and based on at least one scenario generation logic, at least two test scenario data are generated according to the at least two test scenario parameter groups read;
[0062] The new unit test framework is obtained by modifying the inheritance relationship of Feed4Junit, and the new unit test framework inherits from the executor of the Spring framework.
[0063] Among them, the new unit testing framework is a unit testing framework integrated with Spring, which realizes the separation of data and code, and can completely separate test cases and test driver codes, realizing the complete decoupling of test cases and test codes. It is implemented by extending the Feed4Junit source code. It is not the same framework as Junit4. JUnit4 does not realize the separation of data and test code, and data and code need to be coupled together.
[0064] The Spring framework is an open source Java platform that provides a comprehensive infrastructure for developing durable Java applications easily and quickly. It is created to solve the complexity of enterprise application development. Currently, from state-owned enterprises to Internet companies, from traditional private enterprises to joint-stock companies, almost all web systems involved are built with the Spring framework.
[0065] Specifically, the executor of the Spring framework may be SpringJunit4Classrunner.
[0066] Embodiment 4
[0067] Figure 4 4 is a flow chart of a test method provided in Example 4 of the present application. This embodiment is an optional solution provided on the basis of the above embodiment. Figure 4 , the test method provided in the embodiment of the present application includes:
[0068] S210. Based on the new unit test framework, at least two test scenario parameter groups are read from a data source, and based on at least one scenario generation logic, at least two test scenario data are generated according to the at least two test scenario parameter groups read.
[0069] Among them, the new unit testing framework inherits from the executor of the Spring framework.
[0070] S220. Based on the MockMvc framework, according to the at least two test scenario data, the control interface logic to be tested is called in the form of a simulated network request message.
[0071] S230: Determine a test result of the control interface logic to be tested according to an output result of the control interface logic to be tested.
[0072] The key points of the embodiments of the present invention are:
[0073] 1. Since the Feed4Junit framework does not support the Spring framework, the present invention expands the Feed4Junit source code and recompiles the framework to generate a new unit test framework, which realizes integration with the Spring framework and solves the shortcomings of Feed4Junit.
[0074] 2. Since MockMvc can only simulate one test scenario at a time, in order to improve the coverage of unit tests and test multiple request scenarios of the interface, this solution invents the fusion of the new unit test framework and MockMvc, so that for a tested interface, only one scenario generation logic needs to be written, multiple message data are configured in the data source, and the Http request is simulated in the form of simulated network request messages, so that the interface can be fully tested.
[0075] The technical effects of the embodiments of the present invention are:
[0076] The embodiment of the present invention can greatly save interface test code for interface testing and improve interface test coverage. The present invention can achieve full coverage of complex interfaces. For example Figure 5 Input interface in (corresponding to a Controller interface in the system): If the test of five multiple-selection boxes such as the initiating department, business type, currency, business line, and whether the invoice has been received is implemented, then there are 20×30×30×5×2=180,000 combinations of 180,000 scenarios. If an interface covers all five optional scenarios and there are test combinations of other input boxes, such as the bank number of the receiving bank, the payment amount, etc., then the total number of scenarios of all combinations needs to increase exponentially. The existing method is to write an interface test method for each scenario, which requires writing a large number of interface test methods.
[0077] Using the embodiment of the present invention, only one interface test method needs to be written, and all 180,000 test cases are configured in the data source. The fusion framework of the present invention can automatically read the 180,000 test cases to test the interface, making full coverage of the interface possible, and only one interface test method code needs to be written, while the existing testing method needs to write 180,000.
[0078] For the interface test of the Controller interface of the SpringMVC framework, it is also possible to write one interface test method to test all the Controller interfaces of the entire system, that is, to test all the interfaces of the entire project. Using the present invention, only one test method needs to be written, and the test cases of all test scenarios are configured in the data source, which further improves the efficiency of the interface test.
[0079] Embodiment 5
[0080] Figure 6 Schematic diagram of the structure of a test device provided by Embodiment 5 of the present invention. Figure 6 The test device provided by the embodiment of the present invention includes: a scenario data generating module 10, a request simulation module 20 and a test result determining module 30.
[0081] The scenario data generation module 10 is used to read at least two test scenario parameter groups from a data source, and based on at least one scenario generation logic, generate at least two test scenario data according to the read at least two test scenario parameter groups;
[0082] A request simulation module 20, configured to call the control interface logic to be tested in the form of a simulated network request message according to the at least two test scenario data;
[0083] The test result determination module 30 is used to determine the test result of the control interface logic to be tested according to the output result of the control interface logic to be tested.
[0084] The embodiment of the present invention reads at least two test scenario parameter groups from a data source, and based on at least one scenario generation logic, generates at least two test scenario data according to the at least two test scenario parameter groups read; according to the at least two test scenario data, the control interface logic to be tested is called in the form of a simulated network request message, thereby realizing the simulation of multiple request scenarios based on a single scenario generation logic, and then realizing that for a tested interface, only one scenario generation logic needs to be written, multiple message data are configured in the data source, and the Http request is simulated in the form of a simulated network request message, so as to fully test the interface.
[0085] Furthermore, the request simulation module includes:
[0086] The request simulation unit is used to call the control interface logic to be tested based on a Mock framework with simulated Http requests and according to the at least two test scenario data in the form of simulated network request messages.
[0087] Furthermore, the Mock framework having simulated Http request includes a MockMvc framework.
[0088] Furthermore, the scene data generation module includes:
[0089] The scenario data generation unit is used to read at least two test scenario parameter groups from a data source based on the Feed4Junit unit test framework, and generate at least two test scenario data according to the at least two test scenario parameter groups read based on at least one scenario generation logic.
[0090] Furthermore, the scene data generating unit is used to:
[0091] Modify the inheritance relationship of Feed4Junit to obtain a new unit test framework, so that the new unit test framework inherits from the executor of the Spring framework;
[0092] Based on the new unit test framework, at least two test scenario parameter groups are read from a data source, and based on at least one scenario generation logic, at least two test scenario data are generated according to the at least two test scenario parameter groups read.
[0093] Embodiment 6
[0094] Figure 7 A schematic diagram of a device structure provided in Embodiment 6 of the present invention is shown in FIG. Figure 7 As shown, the device includes a processor 70, a memory 71, an input device 72 and an output device 73; the number of processors 70 in the device can be one or more. Figure 7 A processor 70 is taken as an example; the processor 70, the memory 71, the input device 72 and the output device 73 in the device can be connected by a bus or other means. Figure 7 The example of connecting through bus is taken in the following.
[0095] The memory 71, as a computer-readable storage medium, can be used to store software programs, computer executable programs and modules, such as program instructions / modules corresponding to the test method in the embodiment of the present invention (for example, the scenario data generation module 10, the request simulation module 20 and the test result determination module 30 in the test device). The processor 70 executes various functional applications and data processing of the device by running the software programs, instructions and modules stored in the memory 71, that is, implements the above-mentioned test method.
[0096] The memory 71 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system and at least one application required for a function; the data storage area may store data created according to the use of the terminal, etc. In addition, the memory 71 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some instances, the memory 71 may further include a memory remotely arranged relative to the processor 70, and these remote memories may be connected to the device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0097] The input device 72 may be used to receive input digital or character information and generate key signal input related to user settings and function control of the device. The output device 73 may include a display device such as a display screen.
[0098] Embodiment 7
[0099] Embodiment 7 of the present invention further provides a storage medium including computer executable instructions, wherein the computer executable instructions are used to perform a testing method when executed by a computer processor, the method comprising:
[0100] Reading at least two test scenario parameter groups from a data source, and generating at least two test scenario data according to the read at least two test scenario parameter groups based on at least one scenario generation logic;
[0101] According to the at least two test scenario data, calling the control interface logic to be tested in the form of a simulated network request message;
[0102] A test result of the control interface logic to be tested is determined according to the output result of the control interface logic to be tested.
[0103] Of course, the computer executable instructions of the storage medium provided in the embodiment of the present invention are not limited to the method operations described above, but can also perform related operations in the test method provided in any embodiment of the present invention.
[0104] Through the above description of the implementation methods, the technicians in the relevant field can clearly understand that the present invention can be implemented by means of software and necessary general hardware, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as a computer floppy disk, read-only memory (ROM), random access memory (RAM), flash memory (FLASH), hard disk or optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, server, or network device, etc.) to execute the methods described in each embodiment of the present invention.
[0105] It is worth noting that in the embodiment of the above-mentioned testing device, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention.
[0106] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. A testing method, characterized in that: include: Reading at least two test scenario parameter groups from a data source, and generating at least two test scenario data according to the read at least two test scenario parameter groups based on at least one scenario generation logic; According to the at least two test scenario data, calling the control interface logic to be tested in the form of a simulated network request message; Determining a test result of the control interface logic to be tested according to an output result of the control interface logic to be tested; The step of calling the control interface logic to be tested in the form of a simulated network request message according to the at least two test scenario data includes: Based on a Mock framework with simulated Http requests, according to the at least two test scenario data, the control interface logic to be tested is called in the form of simulated network request messages.
2. The method according to claim 1, characterized in that: The Mock framework with simulated Http request includes a MockMvc framework.
3. The method according to claim 1, characterized in that The step of reading at least two test scenario parameter groups from a data source and generating at least two test scenario data according to the read at least two test scenario parameter groups based on at least one scenario generation logic includes: Based on the Feed4Junit unit test framework, at least two test scenario parameter groups are read from a data source, and based on at least one scenario generation logic, at least two test scenario data are generated according to the at least two test scenario parameter groups read.
4. The method according to claim 2, characterized in that The method of reading at least two test scenario parameter groups from a data source based on Feed4Junit and generating at least two test scenario data according to the read at least two test scenario parameter groups based on at least one scenario generation logic includes: Based on the new unit test framework, at least two test scenario parameter groups are read from a data source, and based on at least one scenario generation logic, at least two test scenario data are generated according to the at least two test scenario parameter groups read; The new unit test framework is obtained by modifying the inheritance relationship of Feed4Junit, and the new unit test framework inherits from the executor of the Spring framework.
5. A testing device, characterized in that: include: A scenario data generation module, used to read at least two test scenario parameter groups from a data source, and generate at least two test scenario data according to the at least two test scenario parameter groups read based on at least one scenario generation logic; A request simulation module, used to call the control interface logic to be tested in the form of a simulated network request message according to the at least two test scenario data; A test result determination module, used to determine the test result of the control interface logic to be tested according to the output result of the control interface logic to be tested; The request simulation module comprises: The request simulation unit is used to call the control interface logic to be tested based on a Mock framework with simulated Http requests and according to the at least two test scenario data in the form of simulated network request messages.
6. The device according to claim 5, characterized in that The Mock framework with simulated Http request includes a MockMvc framework.
7. An electronic device, characterized in that: The device comprises: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the testing method according to any one of claims 1 to 4.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the testing method as described in any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Automatic safety testing method and device, electronic device and readable storage medium
CN108572911A