CN112486824A - Use case code generation method and device, computer equipment and storage medium - Google Patents

Use case code generation method and device, computer equipment and storage medium Download PDF

Info

Publication number
CN112486824A
CN112486824A CN202011376578.9A CN202011376578A CN112486824A CN 112486824 A CN112486824 A CN 112486824A CN 202011376578 A CN202011376578 A CN 202011376578A CN 112486824 A CN112486824 A CN 112486824A
Authority
CN
China
Prior art keywords
network request
response information
request
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.)
Granted
Application number
CN202011376578.9A
Other languages
Chinese (zh)
Other versions
CN112486824B (en
Inventor
陈奕群
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangzhou Pinwei Software Co Ltd
Original Assignee
Guangzhou Pinwei Software Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Guangzhou Pinwei Software Co Ltd filed Critical Guangzhou Pinwei Software Co Ltd
Priority to CN202011376578.9A priority Critical patent/CN112486824B/en
Publication of CN112486824A publication Critical patent/CN112486824A/en
Application granted granted Critical
Publication of CN112486824B publication Critical patent/CN112486824B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases

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, computer equipment and a storage medium for generating case codes of test cases, 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 fed back by a server and network request response information of the first network request; acquiring a first code template of a first test case of a preset 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

Use case code generation method and device, computer equipment and storage medium
Technical Field
The present application relates to the field of code processing technologies, and in particular, to a method and an apparatus for generating a case code of a test case, a computer device, and a storage medium.
Background
The testing phase of the current application generally includes a functional test and a regression test. The traditional test mode is as follows: the method comprises the steps of firstly realizing the functional test of a front-end application program, then compiling the case codes of the automatic test cases, and carrying out regression test in a mode of replaying the case codes of the automatic test cases. In the traditional test of the application program, functional test and writing of case code codes of automatic test cases belong to two stages, and writing of case codes of automatic test cases takes time, so that the test efficiency of the application program is low.
Disclosure of Invention
In view of the above, it is desirable to provide a method, an apparatus, a computer device, and a storage medium for generating a case code of a test case, which shorten the time for generating the case code of an automated test case to improve the test efficiency of an application program.
A case code generation method of a test case 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 fed back by a server and network request response information of the first network request; acquiring a first code template of a first test case of a preset 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 a first test case according to a first code template, a first location, a second location, a third location, a first request parameter, interface response information, and 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 parameter 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 method for generating a test case code further includes: receiving a first network request sent by a test application, and acquiring a service method value and a method value 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 so that the server 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 sends 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 the intermediate request is sent to the server, the method further comprises the following steps: receiving network request response information of a first network request fed back by a server; and sending 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 method for generating a test case code further includes: 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 fed back by the server; 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; and 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 the 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.
In one embodiment, a method for generating a test case code further includes: 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 second test case according to the first time stamp and the second time stamp, and obtaining the automatic test case of the test application after sequencing.
In one embodiment, a method for generating a test case code further includes: generating a class file of a test case of the test application; generating a listener in the class file, wherein the listener is used for monitoring a network request sent by the test application; when the listener listens to a first network request sent by the test application, the step of acquiring a first request parameter in the first network request sent by the test application is executed.
A case code generating device for a test case, the device comprising: the first acquisition module is used for acquiring a first request parameter in a first network request sent by a test application; the second acquisition module is used for acquiring interface response information of the first network request fed back by the server and network request response information of the first network request; the identification module is used for acquiring a first code template of a first test case of a preset 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 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 the method of any of the above embodiments when executing the computer program.
A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of the method of any of the above embodiments.
The test case generation equipment obtains a first request parameter, interface response information of a first network request and network request response information of the first network request in the first network request sent by the test application, also obtains a first code template of a first test case of the first network request which is preset, 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 a case code of the first test case according to the first code template, the first position, the second position and the third position as well as 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 first request parameter of the first network request sent by the test application in the functional test stage, the interface response information of the first network request fed back by the server and the network request response information of the first network request can be directly obtained, the case code of the corresponding first test case is directly generated by combining the preset first code template, the case code corresponding to the automatic test can be automatically generated in the functional test stage without writing the case code of the test case of the automatic test after the functional test is finished, the generation time of the case code of the automatic test case is shortened, and the test efficiency of the application program is improved.
Drawings
FIG. 1 is a diagram of an application environment of a method for generating case code of a test case according to an embodiment;
FIG. 2 is a flowchart illustrating a method for generating case code of a test case according to an embodiment;
FIG. 3 is a data flow diagram of a method for generating case code for a test case in one embodiment;
FIG. 4 is a schematic diagram illustrating the display of interface code written in the local mock server in one embodiment;
FIG. 5 is a display diagram illustrating code for a method of implementing a reflection mechanism in one embodiment;
FIG. 6 is a display diagram illustrating codes for recording traffic of a first network request, interface response information of the first network request, and network request response information of the first network request in one embodiment;
FIG. 7 is a schematic diagram illustrating the display of case code for an automated test case generated in one embodiment;
FIG. 8 is a schematic diagram illustrating the display of code for implementing add-listener to a base class file of a test case in one embodiment;
FIG. 9 is a block diagram illustrating an exemplary embodiment of a device for generating test case code;
FIG. 10 is a diagram showing an internal structure of a computer device according to an embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
The application provides a use case code generation method of a test case, which is applied to an application environment shown in FIG. 1. The terminal 102 has a test application installed therein. In performing a functional test of an application program, the test application sends a first network request to a remote server 106 via the 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 network request response information of the first network request. The service 106 feeds back the interface response information and the network request response information to the intermediary 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 application is provided with a test case generation device 108 for executing the case code generation method of the test case of the application.
The test case generation device 108 obtains the first request parameter in the first network request sent by the test application, the interface response information of the first network request, and the network request response information of the first network request from the intermediate service 104. The method includes the steps of obtaining a first code template of a first test case of a preset first network request from a local test case generation device 108, identifying a first position of a first request parameter, a second position of interface response information and a third position of the 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 and the third position, the first request parameter, the interface response information and the network request response information. Therefore, when the functional test is performed on the test application, the test case generation device 108 may directly obtain the first request parameter of the first network request sent by the test application in the functional test stage, the interface response information of the first network request fed back by the server, and the network request response information of the first network request, and directly generate the case code of the corresponding first test case by combining with the preset first code template, and the case code corresponding to the automated test may be automatically generated in the functional test stage without writing the case code of the test case of the automated test after the functional test is completed, thereby shortening the generation time of the case code of the automated test case, and improving the test efficiency of the application program.
In an embodiment, as shown in fig. 2, a method for generating a use case code of a test case is provided, which is described by taking the method as an example applied to the test case generating device 108 in fig. 1, and includes the following steps:
s102, a first request parameter in a first network request sent by a test application is obtained.
In this embodiment, the application is an abbreviation of an application program, and the 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 functional test is executed on the test application, the test case generation equipment acquires a first request parameter in a first network request sent by the test application. The intermediate service may receive the first network request sent by the test application, and forward the first network request to the remote server. At this time, if the first request parameter in the first network request is extracted from the intermediate service, the test case generation 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 generation equipment 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 fed back by the server.
In this embodiment, when the test application performs the functional test, the server responds to the first network request. The server forwards the first network request to a corresponding interface in the server, and the corresponding interface responds to the first network request and feeds back interface response information of the first network request, which may specifically be that the corresponding interface feeds back the interface response information according to a first request parameter in the first network request. In addition, the server side obtains the 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 feeding 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 need to be 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 need to be simulated. Therefore, the test case generation device obtains the interface response information of the first network request and the network request response information of the first network request fed back by the server.
In an implementation manner, the intermediate service is configured to forward the first network request to the server, and simultaneously feed back network request response information of the first network request fed back by the server to the test application. In addition, the intermediate service stores the interface response information of the first network request fed back by the server. The test case generation equipment acquires interface response information of the first network request fed back by the server side and network request response information of the first network request from the intermediate service.
S106, a first code template of a first test case of a preset first network request is obtained, and 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 are identified.
In this embodiment, the test case generation device obtains a first code template of a first test case of a preset first network request. The first code template of the first test case may be configured through the external terminal, and the configured first code template may be sent to the test case generation device for storage. The first code template of the first test case is preset with the universal code of the first test case. The universal code refers to code used for generating a test case corresponding to any network request. For example, in the method for implementing a network request in a test case, codes other than a request parameter corresponding to the network request are general codes. Such as other codes 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 side are different. During the function test, the request parameters of the network requests of different test applications, and the corresponding interface response information and network request response information need to be recorded. And compiling an automatic test case according to different request parameters and corresponding interface response information and 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.
And 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 the test case generating device obtains the first request parameter, the interface response information, and the network request response information, the use case code of the first test case may be generated according to the first position of the first request parameter, the second position of the interface response information, the third position information of the network request response information, and the first code template. Specifically, the case code of the first test case is obtained after the first request parameter, the interface response information, and the network request response information are filled into the first position, the second position, and the third position of the first code template.
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 sent by the test application in the function test stage, the interface response information of the first network request fed back by the server and the network request response information of the first network request can be directly obtained, the case code of the corresponding first test case is directly generated by combining the preset first code template, the case code corresponding to the automatic test can be automatically generated in the function test stage without writing the case code of the test case of the automatic test after the function test is finished, the generation time of the case code of the automatic test case is shortened, and the test efficiency of the application program is improved.
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 parameter 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 generation device stores the acquired first request parameter, the interface response information, and the network request response information, and records the first path information of the first request parameter, the second path information of the interface response information, and the third path information of the network request response information. When executing a case code for generating a first test case, the test case generating device fills the acquired first request parameter into a first position of the first code template according to the first path information, fills the acquired interface response information into a second position of the first code template according to the second path information, and fills the acquired network request response information into a 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 case code of the first test case can be automatically generated.
In an embodiment, S102 further includes: receiving a first network request sent by a test application, and acquiring a service method value and a method value 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 so that the server feeds back the interface response information of the first network request and the network request response information of the first network request.
Preferably, the receiving a first network request sent by the test application includes: and receiving a first network request sent by the mock server, wherein the mock server is used for receiving the first network request sent by the test application and forwarding the first network request. After the intermediate request is sent to the server, the method further comprises the following steps: receiving network request response information of a first network request fed back by a server; and sending 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, the configured Vmock is used to receive and forward the first network request sent by the test application. Wherein Vmock is a server based on mcok service settings. The method for generating the case code of the test case is executed by adopting the local mcok. Wherein the local mcok is a server based on the mcok service setting. 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 referred to as an mcok object.
And configuring and writing codes of interfaces needing recording in the local mock server, wherein the codes are used for generating response and request files. The interface needing recording comprises an interface used for receiving a first network request, and an interface used for receiving interface response information fed back by a server and network request response information. The code to configure and program the interface to be recorded is shown in fig. 4. And after the configuration is completed, starting a method in a recording program com.qa.vca.RecordCaseTest in the local mock server. Then the function test is completed at the APP terminal or H5 terminal. When the local mock server monitors the first network request sent by the Vdock server, the service method and the method of the first network request are obtained through analysis. The value of the service method and the value of the method are obtained, and the local method logic is executed through the reflection mechanism of java, as shown in FIG. 5. In the logic of the local method, the sent first network request of the Vmock is forwarded to the real service of the temporary remote agent, and the return value of the corresponding server 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 to an interface of a corresponding system of the third party platform through a third party interface of the third party platform. And returning interface response information of the first network request by the 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 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 locally through a tool class, so as to realize the admission of traffic, as shown in fig. 6. In addition, the local mock server sends network request response information to the Vdock server, so that the Vdock server sends the network request response information to the test application. Therefore, the recording 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 in the functional test process is realized, and a data basis is provided for automatically generating the case code of the first test case.
In an embodiment, after S104, the method further includes: 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 fed back by the server; 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; and 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 the 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.
In this embodiment, the test case generation device performs deduplication processing on a network request sent by a test application. If the network request sent by the test application and the corresponding feedback information are the same, the use case code generation processing is not required to be carried out on the repeated network request. For example, a local mock server is adopted to record the flow and generate the use case code for the network request sent by the test application and the corresponding feedback information. When the network request sent by the test application is an HTTP request, a case folder is generated for each received HTTP request after the recording flow begins. The use 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 treatment method comprises the following steps: comparing request parameters of the two received HTTP requests, if the request parameters of the two HTTP requests are different, it can be judged that the two HTTP requests are different, and deduplication processing is not needed. If the request parameters of the two HTTP requests are the same, comparing whether the information fed back by the server corresponding to the two HTTP requests is the same. When the fed back information is the same, the two HTTP requests are judged to be the same, and the second received HTTP request is subjected to deduplication processing. If the fed back information is different, the information fed back by the server side of the HTTP request received for the second time is obtained without carrying out deduplication processing on the HTTP request received for the second time, and corresponding use case code generation processing is carried out. Therefore, when the case code of the test case of the test application is generated, the generation of repeated case codes is reduced, and the accuracy of the finally generated case code of the test case of the test application is improved.
In an embodiment, after generating a case code of a second test case according to a second code template, a second request parameter of a second network request, interface feedback information of the second network request, and network request feedback information of the second network request, the method further includes: 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 second test case according to the first time stamp and the second time stamp, and obtaining the automatic test case of the test application after sequencing.
In the embodiment, the test case generation device sequences the test cases according to the timestamps of the test cases, and obtains the automated test cases of the test application according to the sequenced test cases. The time stamp of each test case represents the scene dependency relationship among the test cases. And generating a first time stamp of the first test case and a second time stamp of the second test case, wherein the first time stamp and the second time stamp respectively represent the dependency relationship of the first test case and the second test case among all scenes in the automatic test case. And sequencing 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, so that the generated automatic test case can more accurately describe the dependency relationship of each scene in the functional test process. For example, the case code in the finally generated executable automation test case is shown in fig. 7.
In an embodiment, before S102, the method further includes: generating a class file of a test case of the test application; and generating a listener in the class file, wherein the listener is used for listening to the network request sent by the test application. When the listener listens for the first network request sent by the test application, the step S102 is executed.
In this embodiment, the test case generation device 108 generates a class file of the test case, and adds a listener to the class file to listen to a network request sent by the test application. Specifically, as shown in fig. 8, a listener of a Vmock server is added to the @ beforeset method in the base class file of the test case, and the listener has 3 methods to be implemented, which are respectively: onStubPrepared/onstubtohit/onStubHit. The main logic for recording the first network request and the flow of the server feedback information is implemented in the onstrubhit method. Therefore, the network request sent by the test application during the dynamic monitoring function test can be realized, so that the network request sent by the test application, the interface response information and the network request response information fed back by the server side can be automatically obtained.
The method for generating the case code of the test case can automatically generate the case code of the test case when the function test of the application program is executed, the generated case code of the test case can quickly return to a tested project, and the time for compiling the test case code is reduced.
It should be understood that, although the steps in the flowchart are shown in order as indicated by the arrows, the steps are not necessarily performed in order as indicated by the arrows. The steps are not performed in the exact order shown and described, and may be performed in other orders, unless explicitly stated otherwise. Moreover, at least some of the steps in the figures may include multiple sub-steps or multiple stages that are not necessarily performed at the same time, but may be performed at different times, and the order of performance of the sub-steps or stages is not necessarily sequential, but may be performed in turn or alternately with other steps or at least some of the sub-steps or stages of other steps.
The present application further provides a device for generating a case code of a test case, as shown in fig. 9, the device includes a first obtaining module 10, a second obtaining module 20, a recognition module 30, and a generating module 40. A first obtaining module 10, configured to obtain a first request parameter in a first network request sent by a test application; a second obtaining module 20, 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 identification module 30 is configured to obtain a first code template of a first test case of a preset first network request, and identify 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 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 parameter 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 use case code generation device for a test case may include an agent module. The agent module is used for receiving a first network request sent by the test application and acquiring a service method value and a method value 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 so that the server 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 receiving a first network request sent by the mock server, wherein the mock server is used for receiving the first network request sent by the test application and forwarding the first network request. After the intermediate request is sent to the server, the method further comprises the following steps: receiving network request response information of a first network request fed back by a server; and sending 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 device 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 fed back by the server; 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; and 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 the 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.
In one embodiment, a use case code generation device for a test case may include a sorting 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 second test case according to the first time stamp and the second time stamp, and obtaining the automatic test case of the test application after sequencing.
In one embodiment, a case code generation device 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 listener in the class file, wherein the listener is used for monitoring a network request sent by the test application; when the listener listens to a first network request sent by the test application, the step of acquiring a first request parameter in the first network request sent by the test application is executed.
For specific limitations of the use case code generation apparatus for test cases, reference may be made to the above limitations of the use case code generation method for test cases, which are not described herein again. All or part of each module in the case code generation device of the test case can be realized by software, hardware and a combination thereof. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
In one embodiment, a computer device is provided, and the computer device may be a server supporting the operation of a test case generation device, and the internal structure diagram of the computer device 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 comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. The network interface of the computer device is used for connecting with an external device to acquire the relevant information of the first network request sent by the test application. The computer program is executed by a processor to implement a method for generating case code for a test case.
Those skilled in the art will appreciate that the architecture shown in fig. 10 is merely a block diagram of some of the structures associated with the disclosed aspects and is not intended to limit the computing devices to which the disclosed aspects apply, as particular computing devices may include more or less components than those shown, or may combine certain 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 following steps 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 fed back by a server and network request response information of the first network request; acquiring a first code template of a first test case of a preset 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 parameter 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 service method value and a method value 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 so that the server 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 receiving a first network request sent by the mock server, wherein 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 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 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 fed back by the server; 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; and 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 the 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.
In one embodiment, the processor, when executing the computer program, performs the steps of: 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 second test case according to the first time stamp and the second time stamp, 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 listener in the class file, wherein the listener is used for monitoring a network request sent by the test application; when the listener listens to a first network request sent by the test application, the step of acquiring a first request parameter in the first network request sent by the test application is executed.
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 fed back by a server and network request response information of the first network request; acquiring a first code template of a first test case of a preset 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 parameter 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 the processor performs the steps of: receiving a first network request sent by a test application, and acquiring a service method value and a method value 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 so that the server 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 receiving a first network request sent by the mock server, wherein 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 implements the steps of: receiving network request response information of a first network request fed back by a server; and sending 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 the processor performs the steps of: 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 fed back by the server; 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; and 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 the 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.
In one embodiment, the computer program when executed by the processor performs the steps of: 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 second test case according to the first time stamp and the second time stamp, and obtaining the automatic test case of the test application after sequencing.
In one embodiment, the computer program when executed by the processor performs the steps of: generating a class file of a test case of the test application; generating a listener in the class file, wherein the listener is used for monitoring a network request sent by the test application; when the listener listens to a first network request sent by the test application, the step of acquiring a first request parameter in the first network request sent by the test application is executed.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware instructions of a computer program, which can be stored in a non-volatile computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in the embodiments provided herein may include non-volatile and/or volatile memory, among others. Non-volatile 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 DRAM (SLDRAM), Rambus Direct RAM (RDRAM), direct bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
The technical features of the above embodiments can be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the above embodiments are not described, but should be considered as the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above-mentioned embodiments only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present patent shall be subject to the appended claims.

Claims (10)

1. A use case code generation method of a test case comprises the following steps:
acquiring a first request parameter in a first network request sent by a test application;
acquiring interface response information of the first network request and network request response information of the first network request fed back by a server;
acquiring a first code template of a preset 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;
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.
2. The method of claim 1, wherein the generating case code for 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 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;
filling the acquired first request parameter 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 the information is filled.
3. The method of claim 1, further comprising:
receiving the first network request sent by the test application, and acquiring a service method value and a method value 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 the intermediate request to the server, so that the server feeds back interface response information of the first network request and network request response information of the first network request.
4. The method of claim 3, wherein the receiving the first network request sent by the test application comprises:
receiving the first network request sent by a mock server, wherein 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.
5. The method of claim 1, further comprising:
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 fed back by the server;
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, determining 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 the 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.
6. The method of claim 5, further comprising:
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 second test case according to the first time stamp and the second time stamp, and obtaining the automatic test case of the test application after sequencing.
7. The method of claim 1, further comprising:
generating a class file of a test case of the test application;
generating a listener in the class file, wherein the listener is used for monitoring a network request sent by the test application;
and when the listener monitors the first network request sent by the test application, executing the step of acquiring the first request parameter in the first network request sent by the test application.
8. A use case code generation apparatus for a test case, the apparatus comprising:
the first acquisition module is used for acquiring a first request parameter in a first network request sent by a test application;
the second obtaining module is used for obtaining interface response information of the first network request and network request response information of the first network request fed back by the server;
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;
and the generating module is used for generating the 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.
9. 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 steps of the method of any of claims 1 to 7 are implemented when the computer program is executed by the processor.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the method of any one of claims 1 to 7.
CN202011376578.9A 2020-11-30 2020-11-30 Case code generation method, device, computer equipment and storage medium Active CN112486824B (en)

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 true CN112486824A (en) 2021-03-12
CN112486824B 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)

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20150254173A1 (en) * 2014-03-07 2015-09-10 Ca, Inc. Automated generation of test cases for regression testing
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

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20150254173A1 (en) * 2014-03-07 2015-09-10 Ca, Inc. Automated generation of test cases for regression testing
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
CN112486824B (en) 2024-05-03

Similar Documents

Publication Publication Date Title
CN109460527B (en) Product data configuration method, device, computer equipment and storage medium
CN108427613B (en) Abnormal interface positioning method and device, computer equipment and storage medium
CN112115005B (en) Test data acquisition method and device, computer equipment and storage medium
CN108400978B (en) Vulnerability detection method and device, computer equipment and storage medium
CN113282513B (en) Interface test case generation method and device, computer equipment and storage medium
CN112395202A (en) Interface automation test method and device, computer equipment and storage medium
CN110750443A (en) Webpage testing method and device, computer equipment and storage medium
CN108399125B (en) Automatic testing method and device, computer equipment and storage medium
CN112597016A (en) Recording method, device and equipment of automatic test script and storage medium
CN115048257A (en) System service function verification method and device, computer equipment and storage medium
CN114385485A (en) Interface test method, device, equipment and storage medium
CN110609792A (en) Interface testing method and device, computer equipment and storage medium
CN113377669A (en) Automatic testing method and device, computer equipment and storage medium
CN111159025B (en) Application program interface testing method and device, computer equipment and storage medium
CN112346981A (en) Joint debugging test coverage rate detection method and system
CN112612706A (en) Automated testing method, computer device and storage medium
CN112486824B (en) Case code generation method, device, computer equipment and storage medium
CN110309057B (en) Automatic script-based flow project testing method and related equipment
CN109240906B (en) Database configuration information adaptation method and device, computer equipment and storage medium
CN111061610B (en) Generation method and device of cluster system performance test report and computer equipment
CN114500348A (en) CDN gateway test method and system
CN112486838A (en) Interface testing method and device, computer equipment and storage medium
CN113704114A (en) Automatic testing method, device, equipment and medium for functional interface
CN113094258A (en) Precise test method and device, computer equipment and medium
CN111209187B (en) Service request processing method, device, computer 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