CN112486824B - Case code generation method, device, computer equipment and storage medium - Google Patents
Case code generation method, device, computer equipment and storage medium Download PDFInfo
- Publication number
- CN112486824B CN112486824B CN202011376578.9A CN202011376578A CN112486824B CN 112486824 B CN112486824 B CN 112486824B CN 202011376578 A CN202011376578 A CN 202011376578A CN 112486824 B CN112486824 B CN 112486824B
- Authority
- CN
- China
- Prior art keywords
- network request
- request
- response information
- test
- information
- 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.)
- Active
Links
- 238000000034 method Methods 0.000 title claims abstract description 92
- 238000012360 testing method Methods 0.000 claims abstract description 330
- 230000004044 response Effects 0.000 claims abstract description 244
- 238000004590 computer program Methods 0.000 claims description 28
- 238000012163 sequencing technique Methods 0.000 claims description 15
- 238000012545 processing Methods 0.000 claims description 12
- 230000007246 mechanism Effects 0.000 claims description 9
- 238000012544 monitoring process Methods 0.000 claims description 8
- 230000006870 function Effects 0.000 description 12
- 238000010586 diagram Methods 0.000 description 10
- 238000011990 functional testing Methods 0.000 description 9
- 230000008569 process Effects 0.000 description 3
- 230000001360 synchronised effect Effects 0.000 description 2
- 238000005516 engineering process Methods 0.000 description 1
- 239000000284 extract Substances 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000004904 shortening Methods 0.000 description 1
- 230000003068 static effect Effects 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Preventing errors by testing or debugging software
- G06F11/3668—Software testing
- G06F11/3672—Test management
- G06F11/3684—Test management for test design, e.g. generating new test cases
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Computer Hardware Design (AREA)
- Quality & Reliability (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Debugging And Monitoring (AREA)
Abstract
The application relates to a method, a device, a computer device and a storage medium for generating a case code of a test case, wherein the method comprises the following steps: acquiring a first request parameter in a first network request sent by a test application; acquiring interface response information of a first network request and network request response information of the first network request, which are fed back by a server side; acquiring a preset first code template of a first test case of a first network request, and identifying a first position of a first request parameter, a second position of interface response information and a third position of network request response information in the first code template; and generating a case code of the first test case according to the first code template, the first position, the second position, the third position, the first request parameter, the interface response information and the network request response information. The method can shorten the generation time of the case code of the automatic test case so as to improve the test efficiency of the application program.
Description
Technical Field
The present application relates to the field of code processing technologies, and in particular, to a method and apparatus for generating a case code of a test case, a computer device, and a storage medium.
Background
The testing phase of current applications generally includes functional testing and regression testing. The traditional test mode is as follows: the method comprises the steps of firstly realizing the function test of a front-end application program, then writing the case code of an automatic test case, and carrying out regression test by playing back the case code of the automatic test case. In the conventional test of an application program, functional test and the writing of case codes of an automation test case belong to two stages, and the writing of case codes of the automation test case needs to take time, so that the test efficiency of the application program is low.
Disclosure of Invention
In view of the foregoing, it is desirable to provide a method, apparatus, computer device, and storage medium for generating case codes for test cases that shorten the time for generating case codes for automated test cases to improve the test efficiency of an application.
A method for generating case codes of test cases includes: acquiring a first request parameter in a first network request sent by a test application; acquiring interface response information of a first network request and network request response information of the first network request, which are fed back by a server side; acquiring a preset first code template of a first test case of a first network request, and identifying a first position of a first request parameter, a second position of interface response information and a third position of network request response information in the first code template; and generating a case code of the first test case according to the first code template, the first position, the second position, the third position, the first request parameter, the interface response information and the network request response information.
In one embodiment, generating a case code of the first test case according to the first code template, the first location, the second location, the third location, the first request parameter, the interface response information, and the network request response information includes: acquiring first path information of a first request parameter, wherein the first path information is used for indicating a storage address of the first request parameter; acquiring second path information of the interface response information, wherein the second path information is used for indicating a storage address of the interface response information; acquiring third path information of the network request response information, wherein the third path information is used for indicating a storage address of the network request response information; filling the acquired first request parameters into a first position according to the first path information, filling the acquired interface response information into a second position according to the second path information, filling the acquired network request response information into a third position according to the third path information, and generating a case code of the first test case according to the first code template after the information is filled.
In one embodiment, the method for generating the case code of the test case further includes: receiving a first network request sent by a test application, and acquiring a value of a service method and a value of a method from the first network request; obtaining an intermediate request of the first network request through a reflection mechanism according to the value of the service method and the value of the method; and sending an intermediate request to the server side so that the server side feeds back the interface response information of the first network request and the network request response information of the first network request.
In one embodiment, receiving a first network request sent by a test application includes: the method comprises the steps that a mock server is received and used for sending a first network request, and the mock server is used for receiving the first network request sent by a test application and forwarding the first network request; after sending the intermediate request to the server, the method further comprises: receiving network request response information of a first network request fed back by a server; and sending the network request response information to the mock server so that the mock server sends the network request response information to the test application.
In one embodiment, the method for generating the case code of the test case further includes: acquiring a second network request sent by a test application; if the second request parameter of the second network request is the same as the first request parameter of the first network request, acquiring interface feedback information of the second network request and network request feedback information of the second network request, which are fed back by the server side; when the interface feedback information of the second network request is the same as the interface response information of the first network request and the network request feedback information of the second network request is the same as the network request response information of the first network request, judging that the second network request is the same as the first network request; when the interface feedback information of the second network request is different from the interface response information of the first network request and/or the network request feedback information of the second network request is different from the network request response information of the first network request, a preset second code template of the second network request is obtained, and a case code of the second test case is generated according to the second code template, the second request parameter, the interface feedback information of the second network request and the network request feedback information of the second network request.
In one embodiment, the method for generating the case code of the test case further includes: generating a first timestamp of the first test case and a second timestamp of the second test case; and sequencing the case codes of the first test case and the case codes of the second test case according to the first timestamp and the second timestamp, and obtaining the automatic test case of the test application after sequencing.
In one embodiment, the method for generating the case code of the test case further includes: generating a class file of a test case of the test application; generating a monitor in the class file, wherein the monitor is used for monitoring a network request sent by the test application; and when the first network request sent by the test application is monitored by the monitor, executing the step of acquiring a first request parameter in the first network request sent by the test application.
A use case code generating apparatus of a test use case, the apparatus comprising: the first acquisition module is used for acquiring first request parameters in a first network request sent by the test application; the second acquisition module is used for acquiring interface response information of the first network request and network request response information of the first network request, which are fed back by the server side; the identification module is used for acquiring a preset first code template of a first test case of a first network request and identifying a first position of a first request parameter, a second position of interface response information and a third position of network request response information in the first code template; the generating module is used for generating a case code of the first test case according to the first code template, the first position, the second position, the third position, the first request parameter, the interface response information and the network request response information.
A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the steps of any of the methods of the embodiments described above when the computer program is executed by the processor.
A computer readable storage medium having stored thereon a computer program which when executed by a processor performs the steps of the method of any of the embodiments described above.
The method, the device, the computer equipment and the storage medium for generating the case code of the test case are characterized in that the test case generating equipment acquires a first request parameter, interface response information of the first network request and network request response information of the first network request in a first network request sent by a test application, also acquires a preset first code template of the first test case of the first network request, identifies a first position of the first request parameter, a second position of the interface response information and a third position of the network request response information in the first code template, and finally generates the case code of the first test case according to the first code template, the first position, the second position and the third position, the first request parameter, the interface response information and the network request response information. Therefore, when the function test is executed on the test application, the first request parameter of the first network request, the interface response information of the first network request and the network request response information of the first network request, which are sent by the test application in the function test stage, can be directly obtained, and the case code of the corresponding first test case is directly generated by combining with the preset first code template.
Drawings
FIG. 1 is an application environment diagram of a method for generating case codes of test cases in one embodiment;
FIG. 2 is a flowchart of an example code generation method of a test case according to an embodiment;
FIG. 3 is a data flow diagram of a method for generating case codes for test cases in one embodiment;
FIG. 4 is a schematic diagram showing interface code written in a local mock server in one embodiment;
FIG. 5 is a schematic diagram of code for a method of performing a reflection mechanism in one embodiment;
FIG. 6 is a schematic diagram showing code for recording a first network request, interface response information of the first network request, and traffic of the network request response information of the first network request in one embodiment;
FIG. 7 is a schematic diagram of a display of case code for an automated test case generated in one embodiment;
FIG. 8 is a diagram of a base class file implementation of a test case in one embodiment with code for adding listeners;
FIG. 9 is a block diagram of an example code generation apparatus for a test example in one embodiment;
fig. 10 is an internal structural view of a computer device in one embodiment.
Detailed Description
The present application will be described in further detail with reference to the drawings and examples, in order to make the objects, technical solutions and advantages of the present application more apparent. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the application.
The application provides a case code generation method of a test case, which is applied to an application environment shown in figure 1. The test application is installed in the terminal 102. In performing a functional test of an application, the test application sends a first network request to a remote server 106 through an intermediary service 104. The server 106 forwards the first network request to the corresponding interface to obtain interface response information of the first network request. In addition, the server 106 obtains the network request response information of the first network request. The server 106 feeds back interface response information and network request response information to the intermediate service 104. The intermediary service 104 feeds back the network request response information to the test application of the terminal 102. Thus, the functional test of the test application is completed. The present application provides a test case generation device 108 for executing a case code generation method of a test case of the present application.
The test case generating device 108 obtains, from the intermediate service 104, a first request parameter in a first network request sent by the test application, interface response information of the first network request, and network request response information of the first network request. And acquiring a preset first code template of the first test case of the first network request from the local test case generating equipment 108, identifying a first position of a first request parameter, a second position of interface response information and a third position of network request response information in the first code template, and finally generating a case code of the first test case according to the first code template, the first position, the second position, the third position, the first request parameter, the interface response information and the network request response information. Therefore, when the functional test is executed on the test application, the test case generating device 108 can directly obtain the first request parameter of the first network request, the interface response information of the first network request and the network request response information of the first network request, which are sent by the test application in the functional test stage, and combine the preset first code template to directly generate the corresponding case code of the first test case, and can automatically generate the case code corresponding to the automatic test in the functional test stage without writing the case code of the test case of the automatic test after the functional test is finished, thereby shortening the generation time of the case code of the automatic test case and improving the test efficiency of the application program.
In one embodiment, as shown in fig. 2, a method for generating a case code of a test case is provided, and the method is applied to the test case generating device 108 in fig. 1 for explanation, and includes the following steps:
s102, acquiring a first request parameter in a first network request sent by a test application.
In this embodiment, an application is simply referred to as an application program, and a test application refers to a test object when an application program test is executed. When the function test is executed on the test application, the test application sends a first network request to a remote server. The first network request comprises a first request parameter, and the server side acquires feedback information of the first network request according to the first request parameter in the first network request. The feedback information includes interface response information and network request response information.
When the function test is executed on the test application, the test case generating device obtains a first request parameter in a first network request sent by the test application. The intermediate service may receive a first network request sent by the test application, and forward the first network request to a remote server. At this time, if the first request parameter in the first network request has been extracted from the intermediate service, the test case generating device acquires the first request parameter from the intermediate service. If the first request parameter in the first network request is not extracted from the intermediate service, the test case generating device acquires the first network request from the intermediate service, and extracts the first request parameter from the first network request.
S104, acquiring interface response information of the first network request and network request response information of the first network request, which are fed back by the server side.
In this embodiment, when performing a functional test on the test application, the server responds to the first network request. The server forwards the first network request to a corresponding interface in the server, the corresponding interface responds to the first network request and feeds back interface response information of the first network request, specifically, the corresponding interface feeds back interface response information according to a first request parameter in the first network request. In addition, the server side obtains network request response information of the first network request. The server may determine the network request response information according to the interface response information fed back by the corresponding interface. The network request response information is used for being fed back to the test application, so that the test application displays the network request response information to the terminal interface. The interface response information is used for representing the information response condition of the corresponding interface in the server. Typically, the interface response information is not used for feedback to the test application. When the subsequent regression test is executed, not only the first network request and the network request response information fed back by the server side are simulated according to the first request parameter of the first network request, but also the interface response information fed back by the corresponding interface in the server side is simulated. Therefore, the test case generating device acquires the interface response information of the first network request and the network request response information of the first network request, which are fed back by the server side.
In one implementation, the intermediate service is configured to forward the first network request to the server, and simultaneously feed back network request response information that the server feeds back the first network request to the test application. In addition, the intermediate service stores interface response information of the first network request fed back by the server side. The test case generating device acquires interface response information of the first network request and network request response information of the first network request, which are fed back by the server side, from the intermediate service.
S106, acquiring a preset first code template of a first test case of a first network request, and identifying a first position of a first request parameter, a second position of interface response information and a third position of network request response information in the first code template.
In this embodiment, the test case generating device obtains a first code template of a first test case of a first network request that is set in advance. The first code template of the first test case may be configured by the external terminal, and the configured first code template is sent to the test case generating device for storage. The universal code of the first test case is preset in the first code template of the first test case. The universal code refers to a code used for generating test cases corresponding to any network request. For example, in the method for implementing a network request in the test case, codes other than the request parameters corresponding to the network request are general codes. Such as other code in the main method than the request parameters.
The test application sends different network requests, and interface response information and network request response information fed back by the server are different. When in functional test, the request parameters of different network requests of the test application, the corresponding interface response information and the network request response information are required to be recorded. And writing an automatic test case according to different request parameters, the corresponding interface response information and the network request response information so as to execute subsequent regression tests by adopting the automatic test case. The first code template of the first test case is provided with a first position of a first request parameter, a second position of interface response information and a third position of network request response information. The first position, the second position and the third position are respectively provided with identification information, and the corresponding positions can be identified through the identification information.
S108, generating a case code of the first test case according to the first code template, the first position, the second position, the third position, the first request parameter, the interface response information and the network request response information.
In this embodiment, after obtaining the first request parameter, the interface response information, and the network request response information, the test case generating device may generate a case code of the first test case according to the first location of the first request parameter, the second location of the interface response information, the third location information of the network request response information, and the first code template. Specifically, after the first request parameter is filled in the first position of the first code template, the interface response information is filled in the second position of the first code template, and the network request response information is filled in the third position of the first code template, the case code of the first test case is obtained.
According to the case code generation method of the test case, when the function test is executed on the test application, the first request parameter of the first network request, the interface response information of the first network request and the network request response information of the first network request, which are sent by the test application in the function test stage, can be directly obtained, and the case code of the corresponding first test case is directly generated by combining the preset first code template.
In one embodiment, S108 includes: acquiring first path information of a first request parameter, wherein the first path information is used for indicating a storage address of the first request parameter; acquiring second path information of the interface response information, wherein the second path information is used for indicating a storage address of the interface response information; acquiring third path information of the network request response information, wherein the third path information is used for indicating a storage address of the network request response information; filling the acquired first request parameters into a first position according to the first path information, filling the acquired interface response information into a second position according to the second path information, filling the acquired network request response information into a third position according to the third path information, and generating a case code of the first test case according to the first code template after the information is filled.
In this embodiment, the test case generating device stores the acquired first request parameter, interface response information, and network request response information, and records first path information of the first request parameter, second path information of the interface response information, and third path information of the network request response information. When executing the case code for generating the first test case, the test case generating device fills the acquired first request parameter into the first position of the first code template according to the first path information, fills the acquired interface response information into the second position of the first code template according to the second path information, and fills the acquired network request response information into the third position of the first code template according to the third path information. And then, the test case generating equipment generates a case code of the first test case according to the first code template filled with the information. Therefore, the automatic generation of the case code of the first test case can be realized.
In one embodiment, S102 further includes, before: receiving a first network request sent by a test application, and acquiring a value of a service method and a value of a method from the first network request; obtaining an intermediate request of the first network request through a reflection mechanism according to the value of the service method and the value of the method; and sending an intermediate request to the server side so that the server side feeds back the interface response information of the first network request and the network request response information of the first network request.
Preferably, receiving a first network request sent by a test application includes: and the mock server is used for receiving the first network request sent by the test application and forwarding the first network request. After sending the intermediate request to the server, the method further comprises: receiving network request response information of a first network request fed back by a server; and sending the network request response information to the mock server so that the mock server sends the network request response information to the test application.
In this embodiment, as shown in fig. 3, a first network request sent by the test application is received and forwarded using a configuration Vmock. Wherein Vmock is a server based on mcok service settings. A use case code generation method for a test case of the present application is implemented using local mcok. Wherein local mcok is a server based on mcok service settings. mcok service: simulating the service of the object. For some more complex objects that are not easily constructed or easily obtained, a virtual object is created for testing. The virtual object is mcok objects.
Code of an interface to be recorded is configured and written in a local mock server for generating response and request files. The interfaces to be recorded comprise an interface for receiving the first network request, an interface response message for receiving the feedback of the server side and an interface for receiving the network request response message. The code for configuring and writing the interface to be recorded is shown in fig. 4. After the configuration is completed, a method in the recording program com.qa.vca.RecordCaseTest in the local mock server is started. And then, completing the function test at the APP end or the H5 end. When the local mock server monitors a first network request sent by the Vmock server, a service method and a method of the first network request are obtained through analysis. The values of the service method and the method are obtained, and local method logic is executed through a java reflection mechanism, as shown in fig. 5. In logic of the local method, the first network request sent by Vmock is forwarded to the real service of the temporary remote agent, and the return value of the corresponding service end can be obtained through the temporary remote agent. The server may include each system of the third party platform. The temporary remote agent forwards the first network request through a third party interface of the third party platform into an interface of a corresponding system of the third party platform. And returning interface response information of the first network request by an interface of the corresponding system, and returning network request response information of the first network request by the third-party platform. The local mock server locally stores the first network request, the interface response information of the first network request and the network request response information of the first network request through the tool class, so as to realize the recording of the traffic, as shown in fig. 6. Further, the local mock server sends network request response information to the Vmock server, such that the Vmock server sends the network request response information to the test application. Therefore, the first network request, the interface response information of the first network request and the recording of the network request response information of the first network request are realized in the function test process, and a data basis is provided for automatically generating the case code of the first test case.
In an embodiment, after S104, further includes: acquiring a second network request sent by a test application; if the second request parameter of the second network request is the same as the first request parameter of the first network request, acquiring interface feedback information of the second network request and network request feedback information of the second network request, which are fed back by the server side; when the interface feedback information of the second network request is the same as the interface response information of the first network request and the network request feedback information of the second network request is the same as the network request response information of the first network request, judging that the second network request is the same as the first network request; when the interface feedback information of the second network request is different from the interface response information of the first network request and/or the network request feedback information of the second network request is different from the network request response information of the first network request, a preset second code template of the second network request is obtained, and a case code of the second test case is generated according to the second code template, the second request parameter, the interface feedback information of the second network request and the network request feedback information of the second network request.
In this embodiment, the test case generating device performs deduplication processing on the network request sent by the test application. If the network request sent by the test application and the corresponding feedback information are the same, the repeated network request does not need to be subjected to case code generation processing. For example, a local mock server is adopted to record the flow of a network request and corresponding feedback information sent by a test application and generate and process case codes. When the network request sent by the test application is an HTTP request, after the recording flow starts, a use case folder is generated for each received HTTP request. The case folder is stored under the src/resource/record/date directory. Further, the HTTP request is subjected to deduplication processing according to an algorithm. The processing mode is as follows: comparing the request parameters of the HTTP requests received twice, if the request parameters of the HTTP requests are different, the HTTP requests can be judged to be different, and duplicate removal processing is not needed. If the request parameters of the two HTTP requests are the same, whether the information fed back by the server corresponding to the two HTTP requests is the same is compared. When the feedback information is the same, the HTTP requests are judged to be the same for the two times, and the duplicate removal processing is carried out on the HTTP requests received for the second time. If the feedback information is different, the repeated processing of the HTTP request received for the second time is not needed, and the corresponding application code generation processing is performed by acquiring the information fed back by the server side of the HTTP request received for the second time. Therefore, when generating the case code of the test case of the test application, the generation of the repeated case code is reduced, and the accuracy of the case code of the test case of the finally generated test application is improved.
In an embodiment, after generating the case code of the second test case according to the second code template, the second request parameter of the second network request, the interface feedback information of the second network request, and the network request feedback information of the second network request, the method further includes: generating a first timestamp of the first test case and a second timestamp of the second test case; and sequencing the case codes of the first test case and the case codes of the second test case according to the first timestamp and the second timestamp, and obtaining the automatic test case of the test application after sequencing.
In the embodiment, the test case generating device sorts the test cases according to the time stamps of the test cases, and obtains the automation test cases of the test application according to the sorted test cases. The time stamp of each test case characterizes the scenario dependency between each test case. Generating a first timestamp of the first test case and a second timestamp of the second test case, wherein the first timestamp and the second timestamp respectively represent the dependency relationship of the first test case and the second test case among various scenes in the automatic test case. And sequencing the case codes of the first test case and the case codes of the second test case according to the first timestamp and the second timestamp to obtain the automatic test case of the test application, so that the generated automatic test case can describe the dependency relationship of each scene in the function test process more accurately. For example, the use case code in the final generated executable automated test case is shown in FIG. 7.
In one embodiment, before S102, the method further includes: generating a class file of a test case of the test application; generating a monitor in the class file, wherein the monitor is used for monitoring network requests sent by the test application. When the first network request sent by the test application is monitored by the monitor, step S102 is performed.
In this embodiment, the test case generating device 108 generates a class file of the test case, and then adds a monitor in the class file, so as to monitor a network request sent by the test application. Specifically, as shown in fig. 8, a listener of a Vmock server is added in the @ BeforeSuite method in the base class file of the test case, and the listener has 3 methods to be implemented, which are respectively: onStubPrepared/onStubNotHit/onStubHit. The main logic of recording the flow of the first network request and the feedback information of the server is implemented in onStubHit method. Therefore, the network request sent by the test application during the dynamic monitoring function test can be realized, and the network request sent by the test application, the interface response information fed back by the server side and the network request response information are automatically acquired.
According to the case code generation method of the test case, the case code of the test case can be automatically generated when the function test of the application program is executed, the generated case code of the test case can quickly return to a tested item, and the time for writing the test case code is shortened.
It should be understood that, although the steps in the flowchart are shown in sequence as indicated by the arrows, the steps are not necessarily performed in sequence as indicated by the arrows. The steps are not strictly limited to the order of execution unless explicitly recited herein, and the steps may be executed in other orders. Moreover, at least some of the steps in the figures may include multiple sub-steps or stages that are not necessarily performed at the same time, but may be performed at different times, nor does the order in which the sub-steps or stages are performed necessarily performed in sequence, but may be performed alternately or alternately with at least a portion of other steps or other steps.
The application also provides a device for generating the case code of the test case, which comprises a first acquisition module 10, a second acquisition module 20, an identification module 30 and a generation module 40 as shown in fig. 9. A first obtaining module 10, configured to obtain a first request parameter in a first network request sent by a test application; the second obtaining module 20 is configured to obtain interface response information of the first network request and network request response information of the first network request, which are fed back by the server; the identifying module 30 is configured to obtain a preset first code template of a first test case of a first network request, and identify a first location of a first request parameter, a second location of interface response information, and a third location of network request response information in the first code template; the generating module 40 is configured to generate a case code of the first test case according to the first code template, the first location, the second location, the third location, the first request parameter, the interface response information, and the network request response information.
In one embodiment, the generating module 40 is specifically configured to obtain first path information of the first request parameter, where the first path information is used to indicate a storage address of the first request parameter; acquiring second path information of the interface response information, wherein the second path information is used for indicating a storage address of the interface response information; acquiring third path information of the network request response information, wherein the third path information is used for indicating a storage address of the network request response information; filling the acquired first request parameters into a first position according to the first path information, filling the acquired interface response information into a second position according to the second path information, filling the acquired network request response information into a third position according to the third path information, and generating a case code of the first test case according to the first code template after the information is filled.
In one embodiment, a case code generation apparatus for a test case may include a proxy module. The agent module is used for receiving a first network request sent by the test application, and acquiring a value of a service method and a value of a method from the first network request; obtaining an intermediate request of the first network request through a reflection mechanism according to the value of the service method and the value of the method; and sending an intermediate request to the server side so that the server side feeds back the interface response information of the first network request and the network request response information of the first network request.
In one embodiment, receiving a first network request sent by a test application includes: and the mock server is used for receiving the first network request sent by the test application and forwarding the first network request. After sending the intermediate request to the server, the method further comprises: receiving network request response information of a first network request fed back by a server; and sending the network request response information to the mock server so that the mock server sends the network request response information to the test application.
In one embodiment, a case code generation apparatus for a test case may include a processing module. The processing module is used for acquiring a second network request sent by the test application; if the second request parameter of the second network request is the same as the first request parameter of the first network request, acquiring interface feedback information of the second network request and network request feedback information of the second network request, which are fed back by the server side; when the interface feedback information of the second network request is the same as the interface response information of the first network request and the network request feedback information of the second network request is the same as the network request response information of the first network request, judging that the second network request is the same as the first network request; when the interface feedback information of the second network request is different from the interface response information of the first network request and/or the network request feedback information of the second network request is different from the network request response information of the first network request, a preset second code template of the second network request is obtained, and a case code of the second test case is generated according to the second code template, the second request parameter, the interface feedback information of the second network request and the network request feedback information of the second network request.
In one embodiment, a case code generation apparatus for a test case may include a ranking module. The sequencing module is used for generating a first time stamp of the first test case and a second time stamp of the second test case; and sequencing the case codes of the first test case and the case codes of the second test case according to the first timestamp and the second timestamp, and obtaining the automatic test case of the test application after sequencing.
In one embodiment, a case code generation apparatus for a test case may include a listening module. The monitoring module is used for generating a class file of a test case of the test application; generating a monitor in the class file, wherein the monitor is used for monitoring a network request sent by the test application; and when the first network request sent by the test application is monitored by the monitor, executing the step of acquiring a first request parameter in the first network request sent by the test application.
The specific limitation of the case code generating device of the test case can be referred to the limitation of the case code generating method of the test case, and is not repeated herein. All or part of each module in the case code generating device of the test case can be realized by software, hardware and a combination thereof. The above modules may be embedded in hardware or may be independent of a processor in the computer device, or may be stored in software in a memory in the computer device, so that the processor may call and execute operations corresponding to the above modules.
In one embodiment, a computer device is provided, which may be a server supporting the operation of a test case generating device, and the internal structure diagram of which may be as shown in fig. 10. The computer device includes a processor, a memory, a network interface, and a database connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The network interface of the computer device is used for being connected with external equipment to acquire the related information of the first network request sent by the test application. The computer program, when executed by a processor, implements a method for generating case code for a test case.
It will be appreciated by those skilled in the art that the structure shown in FIG. 10 is merely a block diagram of some of the structures associated with the present inventive arrangements and is not limiting of the computer device to which the present inventive arrangements may be applied, and that a particular computer device may include more or fewer components than shown, or may combine some of the components, or have a different arrangement of components.
In one embodiment, a computer device is provided comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, the processor implementing the steps of when executing the computer program: acquiring a first request parameter in a first network request sent by a test application; acquiring interface response information of a first network request and network request response information of the first network request, which are fed back by a server side; acquiring a preset first code template of a first test case of a first network request, and identifying a first position of a first request parameter, a second position of interface response information and a third position of network request response information in the first code template; and generating a case code of the first test case according to the first code template, the first position, the second position, the third position, the first request parameter, the interface response information and the network request response information.
In one embodiment, when the processor executes the computer program to implement the above-mentioned case code step of generating the first test case according to the first code template, the first location, the second location, the third location, the first request parameter, the interface response information, and the network request response information, the following steps are specifically implemented: acquiring first path information of a first request parameter, wherein the first path information is used for indicating a storage address of the first request parameter; acquiring second path information of the interface response information, wherein the second path information is used for indicating a storage address of the interface response information; acquiring third path information of the network request response information, wherein the third path information is used for indicating a storage address of the network request response information; filling the acquired first request parameters into a first position according to the first path information, filling the acquired interface response information into a second position according to the second path information, filling the acquired network request response information into a third position according to the third path information, and generating a case code of the first test case according to the first code template after the information is filled.
In one embodiment, the processor, when executing the computer program, performs the steps of: receiving a first network request sent by a test application, and acquiring a value of a service method and a value of a method from the first network request; obtaining an intermediate request of the first network request through a reflection mechanism according to the value of the service method and the value of the method; and sending an intermediate request to the server side so that the server side feeds back the interface response information of the first network request and the network request response information of the first network request.
In one embodiment, when the processor executes the computer program to implement the step of receiving the first network request sent by the test application, the following steps are specifically implemented: and the mock server is used for receiving the first network request sent by the test application and forwarding the first network request. The processor when executing the computer program implements the steps of: receiving network request response information of a first network request fed back by a server; and sending the network request response information to the mock server so that the mock server sends the network request response information to the test application.
In one embodiment, the processor, when executing the computer program, performs the steps of: acquiring a second network request sent by a test application; if the second request parameter of the second network request is the same as the first request parameter of the first network request, acquiring interface feedback information of the second network request and network request feedback information of the second network request, which are fed back by the server side; when the interface feedback information of the second network request is the same as the interface response information of the first network request and the network request feedback information of the second network request is the same as the network request response information of the first network request, judging that the second network request is the same as the first network request; when the interface feedback information of the second network request is different from the interface response information of the first network request and/or the network request feedback information of the second network request is different from the network request response information of the first network request, a preset second code template of the second network request is obtained, and a case code of the second test case is generated according to the second code template, the second request parameter, the interface feedback information of the second network request and the network request feedback information of the second network request.
In one embodiment, the processor, when executing the computer program, performs the steps of: generating a first timestamp of the first test case and a second timestamp of the second test case; and sequencing the case codes of the first test case and the case codes of the second test case according to the first timestamp and the second timestamp, and obtaining the automatic test case of the test application after sequencing.
In one embodiment, the processor, when executing the computer program, performs the steps of: generating a class file of a test case of the test application; generating a monitor in the class file, wherein the monitor is used for monitoring a network request sent by the test application; and when the first network request sent by the test application is monitored by the monitor, executing the step of acquiring a first request parameter in the first network request sent by the test application.
In one embodiment, a computer readable storage medium is provided having a computer program stored thereon, which when executed by a processor, performs the steps of: acquiring a first request parameter in a first network request sent by a test application; acquiring interface response information of a first network request and network request response information of the first network request, which are fed back by a server side; acquiring a preset first code template of a first test case of a first network request, and identifying a first position of a first request parameter, a second position of interface response information and a third position of network request response information in the first code template; and generating a case code of the first test case according to the first code template, the first position, the second position, the third position, the first request parameter, the interface response information and the network request response information.
In one embodiment, when the computer program is executed by the processor to implement the above-mentioned case code step of generating the first test case according to the first code template, the first location, the second location, the third location, the first request parameter, the interface response information, and the network request response information, the following steps are specifically implemented: acquiring first path information of a first request parameter, wherein the first path information is used for indicating a storage address of the first request parameter; acquiring second path information of the interface response information, wherein the second path information is used for indicating a storage address of the interface response information; acquiring third path information of the network request response information, wherein the third path information is used for indicating a storage address of the network request response information; filling the acquired first request parameters into a first position according to the first path information, filling the acquired interface response information into a second position according to the second path information, filling the acquired network request response information into a third position according to the third path information, and generating a case code of the first test case according to the first code template after the information is filled.
In one embodiment, the computer program when executed by a processor performs the steps of: receiving a first network request sent by a test application, and acquiring a value of a service method and a value of a method from the first network request; obtaining an intermediate request of the first network request through a reflection mechanism according to the value of the service method and the value of the method; and sending an intermediate request to the server side so that the server side feeds back the interface response information of the first network request and the network request response information of the first network request.
In one embodiment, when the computer program is executed by the processor to implement the step of receiving the first network request sent by the test application, the following steps are specifically implemented: and the mock server is used for receiving the first network request sent by the test application and forwarding the first network request. The computer program when executed by a processor performs the steps of: receiving network request response information of a first network request fed back by a server; and sending the network request response information to the mock server so that the mock server sends the network request response information to the test application.
In one embodiment, the computer program when executed by a processor performs the steps of: acquiring a second network request sent by a test application; if the second request parameter of the second network request is the same as the first request parameter of the first network request, acquiring interface feedback information of the second network request and network request feedback information of the second network request, which are fed back by the server side; when the interface feedback information of the second network request is the same as the interface response information of the first network request and the network request feedback information of the second network request is the same as the network request response information of the first network request, judging that the second network request is the same as the first network request; when the interface feedback information of the second network request is different from the interface response information of the first network request and/or the network request feedback information of the second network request is different from the network request response information of the first network request, a preset second code template of the second network request is obtained, and a case code of the second test case is generated according to the second code template, the second request parameter, the interface feedback information of the second network request and the network request feedback information of the second network request.
In one embodiment, the computer program when executed by a processor performs the steps of: generating a first timestamp of the first test case and a second timestamp of the second test case; and sequencing the case codes of the first test case and the case codes of the second test case according to the first timestamp and the second timestamp, and obtaining the automatic test case of the test application after sequencing.
In one embodiment, the computer program when executed by a processor performs the steps of: generating a class file of a test case of the test application; generating a monitor in the class file, wherein the monitor is used for monitoring a network request sent by the test application; and when the first network request sent by the test application is monitored by the monitor, executing the step of acquiring a first request parameter in the first network request sent by the test application.
Those skilled in the art will appreciate that implementing all or part of the above described methods may be accomplished by way of a computer program stored on a non-transitory computer readable storage medium, which when executed, may comprise the steps of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in embodiments provided herein may include non-volatile and/or volatile memory. The nonvolatile memory can include Read Only Memory (ROM), programmable ROM (PROM), electrically Programmable ROM (EPROM), electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double Data Rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (SYNCHLINK) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), among others.
The technical features of the above embodiments may be arbitrarily combined, and all possible combinations of the technical features in the above embodiments are not described for brevity of description, however, as long as there is no contradiction between the combinations of the technical features, they should be considered as the scope of the description.
The above examples illustrate only a few embodiments of the application, which are described in detail and are not to be construed as limiting the scope of the application. It should be noted that it will be apparent to those skilled in the art that several variations and modifications can be made without departing from the spirit of the application, which are all within the scope of the application. Accordingly, the scope of protection of the present application is to be determined by the appended claims.
Claims (7)
1. A use case code generation method of a test use case, the method comprising:
Receiving a first network request sent by a test application, acquiring a value of a service method and a value of a method from the first network request, and acquiring an intermediate request of the first network request through a reflection mechanism according to the value of the service method and the value of the method;
The intermediate request is sent to a server side, so that the server side feeds back interface response information of the first network request and network request response information of the first network request;
Acquiring a first request parameter in a first network request sent by a test application from an intermediate service, acquiring the first request parameter from the intermediate service if the first request parameter in the first network request is already extracted from the intermediate service, acquiring the first network request from the intermediate service if the first request parameter in the first network request is not already extracted from the intermediate service, and extracting the first request parameter from the first network request; the method comprises the steps that an intermediate service receives a first network request sent by a test application, forwards the first network request to a remote server, and feeds back network request response information fed back by the server to the test application, so that the test application displays the network request response information to a terminal interface;
Acquiring interface response information of the first network request and network request response information of the first network request, which are fed back by a server side, from an intermediate service, wherein the interface response information is used for representing information response conditions of a first network request corresponding interface in the server side and is not used for being fed back to the test application;
Acquiring a preset first code template of a first test case of the first network request, and identifying a first position of the first request parameter, a second position of the interface response information and a third position of the network request response information in the first code template;
Generating a case code of the first test case according to the first code template, the first position, the second position, the third position, the first request parameter, the interface response information and the network request response information;
acquiring a second network request sent by the test application from an intermediate service, and acquiring interface feedback information of the second network request and network request feedback information of the second network request fed back by the server if a second request parameter of the second network request is the same as a first request parameter of the first network request;
When the interface feedback information of the second network request is the same as the interface response information of the first network request and the network request feedback information of the second network request is the same as the network request response information of the first network request, judging that the second network request is the same as the first network request;
When the interface feedback information of the second network request is different from the interface response information of the first network request and/or the network request feedback information of the second network request is different from the network request response information of the first network request, acquiring a preset second code template of the second network request, and generating a case code of a second test case according to the second code template, the second request parameter, the interface feedback information of the second network request and the network request feedback information of the second network request;
Generating a first time stamp of the first test case and a second time stamp of the second test case, and sorting the case codes of the first test case and the second test case according to the first time stamp and the second time stamp to obtain the automatic test case of the test application.
2. The method of claim 1, wherein the generating the case code of the first test case from the first code template, the first location, the second location, the third location, and the first request parameter, the interface response information, and the network request response information comprises:
acquiring first path information of the first request parameter, wherein the first path information is used for indicating a storage address of the first request parameter;
Acquiring second path information of the interface response information, wherein the second path information is used for indicating a storage address of the interface response information;
Acquiring third path information of the network request response information, wherein the third path information is used for indicating a storage address of the network request response information;
And filling the acquired first request parameters into the first position according to the first path information, filling the acquired interface response information into the second position according to the second path information, filling the acquired network request response information into the third position according to the third path information, and generating a case code of the first test case according to a first code template after information filling.
3. The method of claim 1, wherein the receiving the first network request sent by the test application comprises:
The method comprises the steps that a mock server is received and used for sending the first network request, and the mock server is used for receiving the first network request sent by the test application and forwarding the first network request;
after the sending the intermediate request to the server, the method further includes:
receiving network request response information of the first network request fed back by the server;
And sending the network request response information to the mock server so that the mock server sends the network request response information to the test application.
4. The method according to claim 1, wherein the method further comprises:
Generating a class file of the test case of the test application;
generating a monitor in the class file, wherein the monitor is used for monitoring a network request sent by the test application;
And executing the step of acquiring a first request parameter in the first network request sent by the test application when the first network request sent by the test application is monitored by the monitor.
5. A use case code generation apparatus of a test case, the apparatus comprising:
The proxy module is used for receiving a first network request sent by a test application, acquiring a value of a service method and a value of a method from the first network request, and acquiring an intermediate request of the first network request through a reflection mechanism according to the value of the service method and the value of the method; the intermediate request is sent to a server side, so that the server side feeds back interface response information of the first network request and network request response information of the first network request;
The first acquisition module is used for acquiring first request parameters in a first network request sent by the test application from the intermediate service, acquiring the first request parameters from the intermediate service if the first request parameters in the first network request are already extracted from the intermediate service, acquiring the first network request from the intermediate service if the first request parameters in the first network request are not already extracted from the intermediate service, and extracting the first request parameters from the first network request; the method comprises the steps that an intermediate service receives a first network request sent by a test application, forwards the first network request to a remote server, and feeds back network request response information fed back by the server to the test application, so that the test application displays the network request response information to a terminal interface;
the second acquisition module is used for acquiring interface response information of the first network request and network request response information of the first network request, which are fed back by the server side, from the intermediate service, wherein the interface response information is used for representing the information response condition of the first network request corresponding interface in the server side and is not used for being fed back to the test application;
The identification module is used for acquiring a preset first code template of a first test case of the first network request and identifying a first position of the first request parameter, a second position of the interface response information and a third position of the network request response information in the first code template;
The generation module is used for generating a case code of the first test case according to the first code template, the first position, the second position, the third position, the first request parameter, the interface response information and the network request response information;
The processing module is used for acquiring a second network request sent by the test application from the intermediate service, and acquiring interface feedback information of the second network request and network request feedback information of the second network request fed back by the server side if second request parameters of the second network request are the same as first request parameters of the first network request; when the interface feedback information of the second network request is the same as the interface response information of the first network request and the network request feedback information of the second network request is the same as the network request response information of the first network request, judging that the second network request is the same as the first network request; when the interface feedback information of the second network request is different from the interface response information of the first network request and/or the network request feedback information of the second network request is different from the network request response information of the first network request, acquiring a preset second code template of the second network request, and generating a case code of a second test case according to the second code template, the second request parameter, the interface feedback information of the second network request and the network request feedback information of the second network request;
The sequencing module is used for generating a first time stamp of the first test case and a second time stamp of the second test case, sequencing the case codes of the first test case and the case codes of the second test case according to the first time stamp and the second time stamp, and sequencing to obtain the automatic test case of the test application.
6. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the processor implements the steps of the method according to any one of claims 1 to 4 when the computer program is executed.
7. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the steps of the method of any of claims 1 to 4.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202011376578.9A CN112486824B (en) | 2020-11-30 | 2020-11-30 | Case code generation method, device, computer equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202011376578.9A CN112486824B (en) | 2020-11-30 | 2020-11-30 | Case code generation method, device, computer equipment and storage medium |
Publications (2)
Publication Number | Publication Date |
---|---|
CN112486824A CN112486824A (en) | 2021-03-12 |
CN112486824B true CN112486824B (en) | 2024-05-03 |
Family
ID=74937701
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202011376578.9A Active CN112486824B (en) | 2020-11-30 | 2020-11-30 | Case code generation method, device, computer equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN112486824B (en) |
Families Citing this family (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN114443481A (en) * | 2022-01-26 | 2022-05-06 | 北京京东拓先科技有限公司 | Information processing method, device and system |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108319547A (en) * | 2017-01-17 | 2018-07-24 | 阿里巴巴集团控股有限公司 | Method for generating test case, device and system |
CN109614102A (en) * | 2018-10-09 | 2019-04-12 | 平安科技(深圳)有限公司 | Code automatic generation method, device, electronic equipment and storage medium |
CN110858172A (en) * | 2018-08-23 | 2020-03-03 | 北京京东尚科信息技术有限公司 | Automatic test code generation method and device |
CN111181805A (en) * | 2019-12-25 | 2020-05-19 | 航天信息股份有限公司 | Micro-service test baffle generation method and system based on test case |
CN111459814A (en) * | 2020-03-30 | 2020-07-28 | 上海依图网络科技有限公司 | Automatic test case generation method and device and electronic equipment |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US9361211B2 (en) * | 2014-03-07 | 2016-06-07 | Ca, Inc. | Automated generation of test cases for regression testing |
-
2020
- 2020-11-30 CN CN202011376578.9A patent/CN112486824B/en active Active
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108319547A (en) * | 2017-01-17 | 2018-07-24 | 阿里巴巴集团控股有限公司 | Method for generating test case, device and system |
CN110858172A (en) * | 2018-08-23 | 2020-03-03 | 北京京东尚科信息技术有限公司 | Automatic test code generation method and device |
CN109614102A (en) * | 2018-10-09 | 2019-04-12 | 平安科技(深圳)有限公司 | Code automatic generation method, device, electronic equipment and storage medium |
CN111181805A (en) * | 2019-12-25 | 2020-05-19 | 航天信息股份有限公司 | Micro-service test baffle generation method and system based on test case |
CN111459814A (en) * | 2020-03-30 | 2020-07-28 | 上海依图网络科技有限公司 | Automatic test case generation method and device and electronic equipment |
Also Published As
Publication number | Publication date |
---|---|
CN112486824A (en) | 2021-03-12 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN109460527B (en) | Product data configuration method, device, computer equipment and storage medium | |
CN107908541B (en) | Interface testing method and device, computer equipment and storage medium | |
CN108427613B (en) | Abnormal interface positioning method and device, computer equipment and storage medium | |
CN111221743A (en) | Automatic testing method and system | |
CN110019067B (en) | Log analysis method and system | |
CN108459850B (en) | Method, device and system for generating test script | |
CN109408371A (en) | Software defect analyzes input method, device, computer equipment and storage medium | |
CN112115005B (en) | Test data acquisition method and device, computer equipment and storage medium | |
CN112395202B (en) | Interface automation test method and device, computer equipment and storage medium | |
CN105068935B (en) | Method and device for processing software test result | |
CN111124894B (en) | Code coverage rate processing method and device and computer equipment | |
CN110750443A (en) | Webpage testing method and device, computer equipment and storage medium | |
CN112486824B (en) | Case code generation method, device, computer equipment and storage medium | |
CN115048257A (en) | System service function verification method and device, computer equipment and storage medium | |
CN112597016A (en) | Recording method, device and equipment of automatic test script and storage medium | |
CN112463620B (en) | Coverage rate test method and device in android software integration test | |
CN114385485A (en) | Interface test method, device, equipment and storage medium | |
CN113553088A (en) | Patch package distribution method and device, computer equipment and storage medium | |
CN111061610B (en) | Generation method and device of cluster system performance test report and computer equipment | |
CN115685959A (en) | Diagnostic write configuration test method, device, equipment and storage medium | |
CN112416781B (en) | Cross-system interface determination method, device, computer equipment and storage medium | |
CN110737549A (en) | Application testing method, device, server and system | |
CN114500348A (en) | CDN gateway test method and system | |
CN115866357A (en) | Data transmission method, system and device, server, client and storage medium | |
CN114528213A (en) | Automatic baffle plate testing method, device, equipment and storage medium |
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 | ||
GR01 | Patent grant | ||
GR01 | Patent grant |