CN115061941A - Method and device for determining test data of application interface - Google Patents

Method and device for determining test data of application interface Download PDF

Info

Publication number
CN115061941A
CN115061941A CN202210903313.2A CN202210903313A CN115061941A CN 115061941 A CN115061941 A CN 115061941A CN 202210903313 A CN202210903313 A CN 202210903313A CN 115061941 A CN115061941 A CN 115061941A
Authority
CN
China
Prior art keywords
data
test
request
interface
data source
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210903313.2A
Other languages
Chinese (zh)
Inventor
周生宁
党亚林
颜玉昆
夏爽
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Industrial and Commercial Bank of China Ltd ICBC
ICBC Technology Co Ltd
Original Assignee
Industrial and Commercial Bank of China Ltd ICBC
ICBC Technology 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 Industrial and Commercial Bank of China Ltd ICBC, ICBC Technology Co Ltd filed Critical Industrial and Commercial Bank of China Ltd ICBC
Priority to CN202210903313.2A priority Critical patent/CN115061941A/en
Publication of CN115061941A publication Critical patent/CN115061941A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites
    • 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/3692Test management for test results analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/955Retrieval from the web using information identifiers, e.g. uniform resource locators [URL]
    • G06F16/9566URL specific, e.g. using aliases, detecting broken or misspelled links

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The disclosure provides a method for determining test data of an application interface, which can be applied to the technical field of information security. The method comprises the following steps: in response to receiving a test request from a client, intercepting the test request by using a network request framework and generating intercepted data, wherein the intercepted data comprises a data source identifier, and the network request framework is used for packaging the test request; determining a target data source according to the data source identification; in response to receiving a get request, generated by the network request framework after determining the target data source, test data is determined from the target data source, the test data being used to test the application interface. The present disclosure also provides a determination apparatus, a device, a storage medium, and a program product for test data of an application interface.

Description

Method and device for determining test data of application interface
Technical Field
The present disclosure relates to the field of information security, and in particular, to the field of testing, and more particularly, to a method, an apparatus, an electronic device, a medium, and a program product for determining test data for an application interface.
Background
The development of the application product relates to the interaction between a server and a client, and the development progress of the application product is influenced due to inconsistent team development progress between the server and the client, unstable test environment on which the client depends and the like. For example, a server developer only completes interface definition and cannot provide test data for a client developer; the server is frequently crashed, connection scheduling of the client and the server cannot be completed, and test data cannot be obtained for testing.
In the related art, on one hand, a Uniform Resource Locator (URL) sent by a client may be mapped to a local file by using proxy package-grabbing tools such as Charles and Fiddler, and the data stored locally is returned by modifying the URL, so as to determine the test data. However, the debugging process of the general agent packet capturing tool is complicated, the requirement on the professional performance of a tester is high, and the agent packet capturing tool is only suitable for a specific system. And, the system adaptability of the agent packet capturing tool is low. For example, Fiddler can only be installed and used under windows; the agent Charles requires a license to function properly. Therefore, the proxy packet capturing tool has the problems of low development efficiency and poor user experience due to complex debugging process and low system adaptability.
On the other hand, the related art may also implement the application interface test using an application interface management tool. For example, the configuration and testing of the interface is performed by rap2, mockjs, yapi, apifox, or the like. However, in the process of testing the client, the configuration process of the application interface management tool is complex, and the client-side developer is relied on to provide configuration parameters, so that the testing of the client-side depends on the server-side, the workload of the server-side developer is increased, and the development efficiency is influenced.
Disclosure of Invention
In view of the foregoing, the present disclosure provides a method, apparatus, device, medium, and program product for determining test data for an application interface.
According to a first aspect of the present disclosure, there is provided a method for determining test data for an application interface, comprising: in response to receiving a test request from a client, intercepting the test request by using a network request framework and generating intercepted data, wherein the intercepted data comprises a data source identifier, and the network request framework is used for packaging the test request; determining a target data source according to the data source identification; in response to receiving a get request, generated by the network request framework after determining the target data source, test data is determined from the target data source, the test data being used to test the application interface.
According to the embodiment of the disclosure, the data source identifier includes an interface address identifier of the target server and a configuration file address identifier of the client; determining a target data source according to the data source identification, wherein the method comprises the following steps: under the condition that the configuration file address identifier comprises first parameter information, determining a configuration file corresponding to the first parameter information as a target data source; and under the condition that the interface address identifier comprises the second parameter information, determining the interface file of the target server corresponding to the second parameter information as the target data source.
According to the embodiment of the present disclosure, determining a target data source according to a data source identifier further includes: and under the condition that the address identifier of the configuration file does not comprise the first parameter information and the address identifier of the interface does not comprise the second parameter information, determining a preset file as a target data source, wherein the preset file is determined by the network request framework.
According to the embodiment of the disclosure, the test data comprises first simulation data matched with a configuration file, and the configuration file comprises a user-defined file of a user at a client; in response to receiving the fetch request, determining test data from the target data source, including: responding to a first acquisition request, and acquiring a configuration file based on a buffer reading method, wherein the buffer reading method is used for reading data from a pre-established character buffer area, and the first acquisition request is used for acquiring the configuration file from a client; first simulation data for testing the application interface is generated based on the configuration file.
According to an embodiment of the present disclosure, wherein the test data includes second simulation data matching with the interface file; in response to receiving the fetch request, determining test data from the target data source, including: responding to a second acquisition request, starting a sub thread for acquiring the interface file, wherein the second acquisition request is used for asynchronously acquiring the interface file from the target server; sending a network request to a target server; receiving an interface file returned by the target server, and ending the sub-thread; and generating second simulation data for testing the application interface according to the interface file.
According to an embodiment of the present disclosure, after determining test data from a target data source in response to receiving a get request, the method further includes: converting the test data into intermediate data in a first data format, wherein the first data format comprises a character string data format, and the data format of the test data comprises a JSON data format; and determining response data of a second data format according to the intermediate data, wherein the second data format comprises an entity object format, and the response data is used for determining the test result of the application interface.
According to the embodiment of the present disclosure, before intercepting the test request and generating the intercepted data by using the network request framework in response to receiving the test request from the client, the method further includes: calling a resource file with a preset format; and configuring a class interface in the resource file to the client according to the initialization method in the resource file, wherein the class interface is used for configuring a network request framework.
According to an embodiment of the present disclosure, further comprising: displaying the test interface under the condition that the class interface is called; and generating a test request in response to the preset operation of the user on the test interface.
A second aspect of the present disclosure provides an apparatus for determining test data for an application interface, including: the intercepting module is used for responding to a test request received from a client, intercepting the test request by utilizing a network request framework and generating intercepted data, wherein the intercepted data comprises a data source identifier, and the network request framework is used for packaging the test request; the analog data acquisition module is used for determining a target data source according to the data source identification; and a generation module to determine test data from the target data source in response to receiving an acquisition request, the acquisition request generated by the network request framework after determining the target data source, the test data for testing the application interface.
A third aspect of the present disclosure provides an electronic device, comprising: one or more processors; a memory for storing one or more programs, wherein the one or more programs, when executed by the one or more processors, cause the one or more processors to perform the above-described method for determining test data for an application interface.
A fourth aspect of the present disclosure also provides a computer-readable storage medium having stored thereon executable instructions that, when executed by a processor, cause the processor to perform the above-described method for determining test data for an application interface.
A fifth aspect of the present disclosure also provides a computer program product comprising a computer program which, when executed by a processor, implements the above-described method for determining test data for an application interface.
Drawings
The foregoing and other objects, features and advantages of the disclosure will be apparent from the following description of embodiments of the disclosure, which proceeds with reference to the accompanying drawings, in which:
fig. 1 schematically illustrates an application scenario of a determination method for test data of an application interface according to an embodiment of the present disclosure;
FIG. 2 schematically illustrates a flow chart of a method of determining test data for an application interface according to an embodiment of the present disclosure;
FIG. 3 schematically illustrates a flow chart of a method of determining a target data source according to an embodiment of the present disclosure;
FIG. 4 schematically illustrates a request flow diagram of a network request framework in accordance with a specific embodiment of the present disclosure;
FIG. 5 schematically illustrates an application diagram of a network interceptor in a network request framework according to an embodiment of the disclosure;
FIG. 6 schematically shows a schematic diagram of client application interface testing, according to an embodiment of the present disclosure;
fig. 7 schematically shows a block diagram of a structure of a determination apparatus for test data of an application interface according to an embodiment of the present disclosure; and
fig. 8 schematically shows a block diagram of an electronic device suitable for a method of determining test data for an application interface according to an embodiment of the present disclosure.
Detailed Description
Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. It should be understood that the description is illustrative only and is not intended to limit the scope of the present disclosure. In the following detailed description, for purposes of explanation, numerous specific details are set forth in order to provide a thorough understanding of the embodiments of the disclosure. It may be evident, however, that one or more embodiments may be practiced without these specific details. Moreover, in the following description, descriptions of well-known structures and techniques are omitted so as to not unnecessarily obscure the concepts of the present disclosure.
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. The terms "comprises," "comprising," and the like, as used herein, specify the presence of stated features, steps, operations, and/or components, but do not preclude the presence or addition of one or more other features, steps, operations, or components.
All terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art unless otherwise defined. It is noted that the terms used herein should be interpreted as having a meaning that is consistent with the context of this specification and should not be interpreted in an idealized or overly formal sense.
Where a convention analogous to "at least one of A, B and C, etc." is used, in general such a construction is intended in the sense one having skill in the art would understand the convention (e.g., "a system having at least one of A, B and C" would include but not be limited to systems that have a alone, B alone, C alone, a and B together, a and C together, B and C together, and/or A, B, C together, etc.).
The embodiment of the disclosure provides a method for determining test data of an application interface, which includes, in response to receiving a test request from a client, intercepting the test request by using a network request framework and generating intercepted data, where the intercepted data includes a data source identifier, and the network request framework is used for encapsulating the test request; determining a target data source according to the data source identification; in response to receiving a get request, generated by the network request framework after determining the target data source, test data is determined from the target data source, the test data being used to test the application interface.
Fig. 1 schematically shows an application scenario of a determination method for test data of an application interface according to an embodiment of the present disclosure.
As shown in fig. 1, the application scenario 100 according to this embodiment may include terminal devices 101, 102, 103, a network 104, and a server 105. The network 104 serves as a medium for providing communication links between the terminal devices 101, 102, 103 and the server 105. Network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
The user may use the terminal devices 101, 102, 103 to interact with the server 105 via the network 104 to receive or send messages or the like. The terminal devices 101, 102, 103 may be clients of application products to test the application interfaces.
The terminal devices 101, 102, 103 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 105 may be a server providing various services, such as a background management server (for example only) providing support for websites browsed by users using the terminal devices 101, 102, 103. The backend management server may analyze and process the received data such as the user request, and feed back a processing result (for example, a web page, information, or data obtained or generated according to the user request) to the terminal device.
It should be noted that the determination method for the test data of the application interface provided by the embodiment of the present disclosure may be generally executed by the server 105. Accordingly, the determination device for the test data of the application interface provided by the embodiment of the present disclosure may be generally disposed in the server 105. The determination method for the test data of the application interface provided by the embodiment of the present disclosure may also be performed by a server or a server cluster that is different from the server 105 and is capable of communicating with the terminal devices 101, 102, 103 and/or the server 105. Accordingly, the determination device for the test data of the application interface provided by the embodiment of the present disclosure may also be disposed in a server or a server cluster different from the server 105 and capable of communicating with the terminal devices 101, 102, 103 and/or the server 105.
It should be understood that the number of terminal devices, networks, and servers in fig. 1 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Fig. 2 schematically shows a flow chart of a method for determining test data for an application interface according to an embodiment of the present disclosure.
As shown in fig. 2, the method includes operations S210 to S230.
In operation S210, in response to receiving a test request from a client, intercepting the test request by using a network request framework and generating intercepted data, where the intercepted data includes a data source identifier, and the network request framework is configured to encapsulate the test request.
According to the embodiment of the disclosure, the test request from the client may be the next step of instruction information generated in the application layer of the client after the user performs the click operation on the client. For example, the test request may be "get data A," and in response to "get data A," the function may be implemented to get data A locally or to invoke a third party interface to get data A.
According to the embodiment of the disclosure, after receiving a test request of a client, a network request framework can directly configure the received test request through annotation through a dynamic agent based on Java, and then realize the network request through an execution framework packaged at the bottom layer of the network request framework.
For example, the network request framework may be Retrofit, which encapsulates okhttp underneath. The network request framework Retrofit comprises the steps of processing a test request by using an annotation method, converting the test request into a dynamic proxy in a Java interface form, and then executing the dynamic proxy through an okhttp. The network request framework Retrofit comprises a plurality of annotations, and is used for representing request modes, parameters, Url and the like of the application interface request and adapting to various test request scenes.
According to the embodiment of the disclosure, in response to receiving a test request from a client, the test request is intercepted by a network request framework and intercepted data is generated. Specifically, an interceptor is configured inside the network request framework. The interceptor can intercept the test request by calling an interception method configured by the network request framework and call a corresponding analysis method to generate intercepted data, so that the network request framework determines whether to normally send the network request according to the generated data source identifier to acquire corresponding test data.
In operation S220, a target data source is determined according to the data source identification.
According to the embodiment of the present disclosure, the generated data source identifier is a data source identifier in a preset format, for example, a Url address.
According to the embodiment of the disclosure, after the data source identifier is generated, the target data source of the test data is determined according to whether the data source identifier includes the corresponding parameter information. The target data source comprises a data format file configured locally by the client, a data format file configured by the server and a data format file defined by the network request frame.
In operation S230, test data is determined from the target data source in response to receiving a get request, the get request being generated by the network request framework after determining the target data source, the test data being for testing the application interface.
According to embodiments of the present disclosure, after determining the target data source, the network request framework may generate a fetch request that matches the target data source and then determine test data from the target data source in response to the fetch request. Specifically, in the case that the target data source is a data format file local to the client, the obtaining request generated by the network request framework may be an instruction for instructing the network request framework to call a method inside, so as to obtain the local data format file from the client.
And under the condition that the target data source is the data format file of the server, the network request framework generates a network request interacting with the server. Specifically, a network request framework Retrofit is taken as an example. And the network request framework Retrofit configures the okhttpClient according to an internal method, then generates a network request through the okhttpClient, and acquires a data format file of the server according to a returned call type response.
According to the method and the device, the interception of the test request and the generation of the data source identification are realized by utilizing the network request framework, the data interception is realized and the test data is acquired from a plurality of target data sources through the network request framework, the strong dependence of the client test on the server is eliminated, and the development efficiency is improved. Meanwhile, after the network request framework intercepts the test request, the test data is obtained according to the determined target data source, the server and the client are isolated, the client is prevented from directly obtaining and utilizing the real data of the server, and the safety and reliability of the real data of the server interface are ensured.
FIG. 3 schematically illustrates a flow chart of a method of determining a target data source according to an embodiment of the present disclosure.
As shown in fig. 3, the method of this embodiment includes operations S321 to S322, which may be a specific embodiment of operation S220.
In operation S321, in a case where it is determined that the profile address identification includes the first parameter information, a profile corresponding to the first parameter information is determined as the target data source.
In operation S322, in case that it is determined that the interface address identification includes the second parameter information, the interface file of the target server corresponding to the second parameter information is determined as the target data source.
According to the embodiment of the disclosure, the data source identifier comprises an interface address identifier of the target server and a configuration file address identifier of the client. Specifically, according to the parameter information included in the data source identifier, it may be determined whether the target data source is a data format file of the client or a data format file of the server.
According to the embodiment of the disclosure, in the case that it is determined that the profile address identifier includes the first parameter information, the profile corresponding to the first parameter information is determined as the target data source. Specifically, the first parameter information includes a file storage address or a file name of the client configuration file.
And under the condition that the interface address identifier comprises the second parameter information, determining the interface file of the target server corresponding to the second parameter information as the target data source. The second parameter information includes a service address of the interface file. After determining the target data source, jointly determining the test data according to the base address and the service address which are pre-configured in the network request framework. For example, the service address is XXX, the base address is AAA, and the address used to determine the test data is aaa.xxx.
According to the embodiment of the present disclosure, in the case that the data source identifier includes both the first parameter information and the second parameter information, the target data source may be a configuration file of the client or an interface file of the target server. Or, in the case that the configuration file address identifier includes the first parameter information and the interface address identifier includes the second parameter information, determining the interface file of the target server as the target data source. Specifically, the priority of the data generated by the target server is higher than that of the client, the data generated by the target server is preferentially determined as the target data source, the accuracy of the determined test data can be ensured to be higher, and the tests of the server and the client are jointly called, so that the test efficiency and the development efficiency of the whole application product are improved conveniently.
For example, the data source identifier includes a fixed parameter Context object Context, a JSON data format file name fileName (i.e. configured file address identifier) under the non-fixed parameter client assets directory, and a JSON data format file interface address mockdaurl (i.e. interface address identifier) of the target server. The parameter of the fileName is the first parameter information, the parameter of the mockDataUrl is the second parameter information, and the parameter information of the fileName and the mockDataUrl may be null or may include specific parameter information.
And when the fileName is empty and the mockdataUrl is not empty, indicating that the configuration file with the client JSON data format is not configured, and using the interface file with the target server JSON data format for the test data. And when the fileName is not empty and the mockDataUrl is empty, representing that the configuration file in the JSON data format of the client is configured, wherein the configuration file in the JSON data format of the client is used for the test data. When neither the fileName nor the mockDataUrl is empty, the client and the target server are both configured with JSON data, but the priority of the target server is higher than that of the client, and the test data uses the interface file of the target server. When both the fileName and mockdaurl are empty, the test data default to a preset file in JSON data format in the network request architecture.
According to the embodiment of the disclosure, in the case that it is determined that the configuration file address identifier does not include the first parameter information and the interface address identifier does not include the second parameter information, the preset file is determined as the target data source, and the preset file is determined by the network request framework. Specifically, the preset file is a JSON data format file and includes a plurality of types of information. For example, the coding information code, the prompt information message to be displayed and the custom data information data. The code information may be a specific version identifier for indicating in the test result that the test data is a preset file set in the network request frame. The message information may be set to "update the latest version apk". The data information may be modified while updating the network request framework.
The custom data information data comprises a plurality of fields, specifically, new version information, latest version information, address setting form and the like. For example, the data information includes newVersion, minVersion, aplUrl, updateDescription, isUpdate, and forceUpdate, the specific parameter for newVersion is "5.2.1", the parameter for aplUrl is "http:// xxx/xxx.apk", the specific parameter for updateDescription is "new UI experience and repair issue", and the isUpdate and forceUpdate correspond to "true" and "false", respectively.
For operation S230, determining test data from the target data source in response to receiving the get request includes, according to an embodiment of the present disclosure: in response to the first acquisition request, the configuration file is acquired based on a buffer reading method for reading data from a character buffer area established in advance. First simulation data for testing the application interface is generated based on the configuration file.
According to an embodiment of the present disclosure, the first get request is for getting a configuration file from a client. The configuration file comprises a custom file of a user at the client. The test data can be simulation data generated according to a data format file of the client, and the isolation of the test data and the real data can be ensured.
For example, the network request framework Retrofit includes an API simulation tool module including a plurality of tool classes, wherein the configuration file is obtained through a character buffer input stream BufferedReader of the AssetsUtil class. Specifically, the BufferedReader method may determine the configuration file according to the file storage path, for example, obtain the JSON data format file from the attributes folder.
According to the embodiment of the disclosure, in the case that the target data source is the target server, the child thread for acquiring the interface file may be further started in response to the second acquisition request. After the sub thread is started, the okhttp at the bottom layer of the network request framework Retrofit sends a network request to the target server. Specifically, the started child thread determines the location of the interface file through a combined address obtained by the base address and the service address, and then sends the acquisition request and the combined address included in the acquisition request to the target server.
And after receiving the network request sent by the network request frame, the target server determines an interface file corresponding to the network request and returns the interface file.
And the network request framework Retrofit finishes the sub-thread after receiving the interface file returned by the target server. Second simulation data for testing the application interface is then generated according to the interface file.
According to the embodiment of the disclosure, in the case that it is determined that the target data source is not the target server and is not the configuration file of the client, it is also possible to obtain a preset file from a preset storage address of the network request framework in response to a third obtaining request, and then generate third simulation data for testing the application interface according to the preset file.
According to the embodiment of the disclosure, in the case that the target data source is determined to be the target server, the service data may be further acquired from the target server in response to the fourth acquisition request, so as to test the service data acquired by the target server. The fourth acquisition request includes a service data storage address. Specifically, in response to the fourth acquisition request, a sub-thread for acquiring the service data is started, and a network request for acquiring the service data and an acquisition address are sent to the target server. And after receiving the service data returned by the target server, testing the application interface by using the service data.
According to an embodiment of the present disclosure, after determining the test data from the target data source, the test data may be further converted into intermediate data in a first data format, the first data format including a string data format, and the data format of the test data including a JSON data format. Then, according to the intermediate data, response data of a second data format is determined, wherein the second data format comprises an entity object format, and the response data is used for determining a test result of the application interface.
According to the embodiment of the disclosure, the intermediate data in the character string data format can be converted into the response data in the entity object format by the fromJson method of the GSON object, and the response data is called by the MockInterreceptor class.
For example, when it is determined that the interface address identifier mockDataUrl includes the second parameter data, the child thread is started to initiate a network request, an interface file returned by the target server is acquired, the interface file is converted into intermediate data in a character string data format, and then the intermediate data is transmitted to the GSON object for conversion processing. And under the condition that the configuration file address identifier fileName comprises first parameter data, directly reading a default JSON data format file in a client assets folder, converting the data stream into intermediate data in a character string data format, and transmitting the intermediate data to a GSON object for data conversion processing.
Fig. 4 schematically illustrates a request flow diagram of a network request framework according to a specific embodiment of the present disclosure.
As shown in fig. 4, the request flow of the network request framework Retrofit includes an APP application layer 401, a network request framework Retrofit402, an okhttp403, an interceptor 404, a client 405, a server 406, and a preset address 407.
The application product of the client initiates a test request at the APP application layer 401. The application products of the client comprise an application program APP and a webpage end application program. The network request framework Retrofit402 responds to a received test request from the APP application layer 401, configures a request parameter corresponding to the test request through annotation, and internally creates an http network request object okhttpparent. After determining the executor okhttp403 adapted to the created network request object, the network request object okhttpparent is sent to okhttp 403.
According to an embodiment of the present disclosure, okhttp is used to send network requests through proxy mode. After the network request is sent by the okhttp403, the interceptor 404 intercepts the network request, and after the target data source is determined, sends an obtaining request to the target data source for obtaining the file in the JSON data format.
Under the condition that the target data source is determined to be the configuration file of the client, sending a first acquisition request to the client 405, wherein the first acquisition request is used for acquiring the configuration file of the client; under the condition that the target data source is determined to be the interface file of the server, sending a second acquisition request to the server 406, wherein the second acquisition request is used for acquiring the interface file of the server; in the case of determining that the target data source is a preset file pre-configured by the network request framework, the preset file is obtained from the preset address 407.
According to the embodiment of the disclosure, after the file in the JSON data format is acquired from the target data source, the test data is returned through the interceptor 404, the okhttp403, and the Retrofit 402. After the interceptor takes the request, the interceptor can rewrite the request, add, remove, and replace the request header, and can also rewrite the response header to change the entity of the response. The network request framework Retrofit402 may call a corresponding method to generate simulation data in the interceptor and perform format conversion, and then return response data to the APP application layer 401.
Fig. 5 schematically shows an application diagram of a network interceptor in a network request framework according to an embodiment of the disclosure.
According to the embodiment of the disclosure, as shown in fig. 5, the interaction of the request and the response between the application 501 and the okhttp core 502 is normally realized, and an application interceptor is not set. The interceptor in the network request framework is a network interceptor 503, which is arranged between the http core 502 and the network 504 and is used for intercepting the request generated by the http core 502 and returning a corresponding response.
According to the embodiment of the disclosure, the network request framework Retrofit can be realized through a configured API simulation tool module, a simulation interceptor module and a simulation data management module. The API simulation tool modules include an ApiMock class, a MockUtil class, and an AssetsUtil class. The ApiMock class is used for externally packaging a calling method, initializing a target data source, initializing a Retrofit object, and configuring a mock Interreceptor class of a simulation interceptor module, namely configuring an interceptor. The MockUtil class can acquire a mockupi data stream of the target server for being called by the simulation data management module; the base address baseUrl of the Retrofit object and the server interface address mockDataUrl of the target data source can also be saved and obtained. Specifically, baseUrl and mockDataUrl may be saved and obtained by encapsulating SharedPreferces.
According to an embodiment of the present disclosure, the simulation data management module includes a management class MockDataManager class and a ResponseInfo class. The MockDataManager class is used for packaging a real-time refreshing method and is used for refreshing and acquiring an interface file of a target server in real time. A method for determining a target data source is also packaged, namely under the condition that the first parameter information is determined to exist and the second parameter information does not exist, a JSON data format file of the client is obtained; and under the condition that the first parameter information does not exist and the second parameter information exists, asynchronously obtaining the JSON data format file of the server. The ResponseInfo class is used for simulating returned response data after the test data are acquired, and the response data are entity object classes, namely entity bean classes.
The simulated interceptor modules include a mocksntercaptor class and a mocksponsebody class. And the MockInterreceptor class is used for intercepting the corresponding request, returning the first simulation data or the server data and the second simulation data generated by the client, realizing the interception method of the interceptor interface rewriting and returning the response after the secondary processing. The mocksponsebody class is used for simulating a return result object, analyzing and processing the data stream in the JSON format through the okio, and returning the JSON format data stream configured in the network request frame by default when the JSON format data stream in the remote server and the local JSON format does not exist.
According to the embodiment of the disclosure, before the test request is intercepted by using the network request framework and the intercepted data is generated in response to the test request received from the client, the resource file with the preset format can be called. And configuring a class interface in the resource file to the client according to an initialization method in the resource file, wherein the class interface is used for configuring a network request framework.
According to the embodiment of the disclosure, the constructed network request framework Retrofit uses an Android architecture, and based on an Android SDK version Android 10.0(API level 29), the Android Studio version of a development tool is 4.1.2, and the gradle version adopted by a construction tool Retrofit is 5.4.1. After the network request framework Retrofit is completed, the resource file in the aar file format is formed so that the client can directly use the resource file by calling.
According to the embodiment of the disclosure, the initialization method in the resource file is preset in the ApiMock class. The ApiMock class also includes the initialization of the Retrofit object so that the initialization method of the Retrofit object is called in response to the test request.
According to the embodiment of the disclosure, the resource file can be configured in the build.gram in the specific project file of the client, and then the initialization method in the resource file is automatically called to configure the class interface in the resource file to the client. Specifically, a JSON data format file and a Retrofit network request which are matched with the current project of the client are configured through an initialization method init, and finally, simulation service is displayed.
According to the embodiment of the disclosure, in the process of configuring the class interface in the resource file to the client according to the initialization method in the resource file, a preset file of a network request frame can be also leaked for defining or changing the custom information data.
According to the embodiment of the disclosure, the initialization method may configure a class interface to the client and may also call an execution server address for executing an operation executed by the current network request framework Retrofit.
According to an embodiment of the present disclosure, the class interface may be invoked after the resource file is to be invoked and the class interface is configured to the client. And displaying the test interface under the condition that the class interface is called. The user can generate a test request at the client by operating on the test interface.
According to the embodiment of the disclosure, the operation of the user on the test interface comprises preset operations such as clicking, sliding and double-clicking.
Fig. 6 schematically shows a schematic diagram of a client application interface test according to an embodiment of the present disclosure.
As shown in fig. 6, in the case where the class interface is called, the test interface exposed by the client 600 includes operation blocks 601, 602, and 603, and a test result exposure block 604. The operation block 601 corresponds to the target data source of the simulation test as a local configuration, the operation block 602 corresponds to the target data source of the simulation test as a remote configuration, and the operation block 603 corresponds to the target data source of the simulation test as a default. The target data source corresponds to the preset files configured by the client, the server and the network request framework.
As an example, as shown in fig. 6, a presentation result of the presentation box 404 in the case where the user clicks the operation box 601 to simulate the test (local configuration) is presented. Specifically, the display frame can display preset information and custom information. Fig. 6 shows only the custom information of the local configuration, for example, [ newVersion ═ 2.1.1 ', minVersion ═ 2.0.0', aplUrl ═ http:// xxx/xxx.apk ', updateDescription ═ JSON data format file of the local configuration,' update ═ true, forceUpdate ═ false ].
The method for determining the test data of the application interface can reduce the communication cost and time cost of the client and the server, and is beneficial to the client to realize quick troubleshooting and positioning without depending on the server; meanwhile, the client and the server can conveniently carry out development work in parallel, and the working efficiency of a team is improved. According to the method and the device, the connector is arranged in the network request framework Retrofit, so that data isolation between the client and the server and data isolation between the client and the server are achieved, and safety and reliability of real data of the server interface are guaranteed.
According to the method for determining the test data of the application interface, the configured resource file is called, so that the calling of a third party is realized, a plurality of tools do not need to be installed or debugged by a server side tester to realize the test of the application interface, the development efficiency is improved, and further, the integrated use of the project is facilitated.
Fig. 7 schematically shows a block diagram of a structure of a determination apparatus for test data of an application interface according to an embodiment of the present disclosure.
As shown in fig. 7, the apparatus 700 for determining test data of an application interface of this embodiment includes an intercepting module 710, a simulation data obtaining module 720, and a generating module 730.
The intercepting module 710 is configured to, in response to receiving a test request from a client, intercept the test request by using a network request framework and generate intercepted data, where the intercepted data includes a data source identifier, and the network request framework is configured to encapsulate the test request. In an embodiment, the intercepting module 710 may be configured to perform the operation S210 described above, which is not described herein again.
And the simulation data acquisition module 720 is configured to determine a target data source according to the data source identifier. In an embodiment, the analog data obtaining module 720 may be configured to perform the operation S220 described above, which is not described herein again.
The generating module 730 is configured to determine test data from the target data source in response to receiving an acquisition request, the acquisition request being generated by the network request framework after determining the target data source, the test data being used for testing the application interface. In an embodiment, the generating module 730 may be configured to perform the operation S230 described above, which is not described herein again.
According to an embodiment of the present disclosure, the analog data acquisition module 720 includes a first determination unit and a second determination unit.
The first determining unit is used for determining the configuration file corresponding to the first parameter information as the target data source under the condition that the configuration file address identification is determined to comprise the first parameter information. In an embodiment, the first determining unit may be configured to perform the operation S321 described above, which is not described herein again.
The second determining unit is used for determining the interface file of the target server corresponding to the second parameter information as the target data source under the condition that the interface address identifier is determined to comprise the second parameter information. In an embodiment, the second determining unit may be configured to perform the operation S322 described above, which is not described herein again.
Fig. 8 schematically shows a block diagram of an electronic device suitable for a method of determining test data for an application interface according to an embodiment of the present disclosure.
As shown in fig. 8, an electronic device 800 according to an embodiment of the present disclosure includes a processor 801 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)802 or a program loaded from a storage section 808 into a Random Access Memory (RAM) 803. The processor 801 may include, for example, a general purpose microprocessor (e.g., CPU), an instruction set processor and/or associated chipset, and/or a special purpose microprocessor (e.g., Application Specific Integrated Circuit (ASIC)), among others. The processor 801 may also include onboard memory for caching purposes. The processor 801 may include a single processing unit or multiple processing units for performing different actions of the method flows according to embodiments of the present disclosure.
In the RAM803, various programs and data necessary for the operation of the electronic apparatus 800 are stored. The processor 801, the ROM 802, and the RAM803 are connected to each other by a bus 804. The processor 801 performs various operations of the method flows according to the embodiments of the present disclosure by executing programs in the ROM 802 and/or RAM 803. Note that the programs may also be stored in one or more memories other than the ROM 802 and RAM 803. The processor 801 may also perform various operations of method flows according to embodiments of the present disclosure by executing programs stored in the one or more memories.
Electronic device 800 may also include input/output (I/O) interface 805, input/output (I/O) interface 805 also connected to bus 804, according to an embodiment of the present disclosure. Electronic device 800 may also include one or more of the following components connected to I/O interface 805: an input portion 806 including a keyboard, a mouse, and the like; an output section 807 including a signal such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 808 including a hard disk and the like; and a communication section 809 including a network interface card such as a LAN card, a modem, or the like. The communication section 809 performs communication processing via a network such as the internet. A drive 810 is also connected to the I/O interface 805 as necessary. A removable medium 811 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 810 as necessary, so that the computer program read out therefrom is mounted on the storage section 808 as necessary.
The present disclosure also provides a computer-readable storage medium, which may be contained in the apparatus/device/system described in the above embodiments; or may exist separately and not be assembled into the device/apparatus/system. The computer-readable storage medium carries one or more programs which, when executed, implement the method according to an embodiment of the disclosure.
According to embodiments of the present disclosure, the computer-readable storage medium may be a non-volatile computer-readable storage medium, which may include, for example but is not limited to: a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. For example, according to embodiments of the present disclosure, a computer-readable storage medium may include the ROM 802 and/or RAM803 described above and/or one or more memories other than the ROM 802 and RAM 803.
Embodiments of the present disclosure also include a computer program product comprising a computer program containing program code for performing the method illustrated by the flow chart. When the computer program product runs in a computer system, the program code is used for causing the computer system to realize the determination method for the test data of the application interface provided by the embodiment of the disclosure.
The computer program performs the above-described functions defined in the system/apparatus of the embodiments of the present disclosure when executed by the processor 801. The systems, apparatuses, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the present disclosure.
In one embodiment, the computer program may be hosted on a tangible storage medium such as an optical storage device, a magnetic storage device, or the like. In another embodiment, the computer program may also be transmitted in the form of a signal on a network medium, distributed, downloaded and installed via communication section 809, and/or installed from removable media 811. The computer program containing program code may be transmitted using any suitable network medium, including but not limited to: wireless, wired, etc., or any suitable combination of the foregoing.
In such an embodiment, the computer program can be downloaded and installed from a network through the communication section 809 and/or installed from the removable medium 811. The computer program, when executed by the processor 801, performs the above-described functions defined in the system of the embodiments of the present disclosure. The systems, devices, apparatuses, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the present disclosure.
In accordance with embodiments of the present disclosure, program code for executing computer programs provided by embodiments of the present disclosure may be written in any combination of one or more programming languages, and in particular, these computer programs may be implemented using high level procedural and/or object oriented programming languages, and/or assembly/machine languages. The programming language includes, but is not limited to, programming languages such as Java, C + +, python, the "C" language, or the like. The program code may execute entirely on the user computing device, partly on the user device, partly on a remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computing device (e.g., through the internet using an internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems that perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
Those skilled in the art will appreciate that various combinations and/or combinations of features recited in the various embodiments and/or claims of the present disclosure can be made, even if such combinations or combinations are not expressly recited in the present disclosure. In particular, various combinations and/or combinations of the features recited in the various embodiments and/or claims of the present disclosure may be made without departing from the spirit or teaching of the present disclosure. All such combinations and/or associations are within the scope of the present disclosure.
The above-mentioned embodiments are intended to illustrate the objects, aspects and advantages of the present disclosure in further detail, and it should be understood that the above-mentioned embodiments are only illustrative of the present disclosure and are not intended to limit the present disclosure, and any modifications, equivalents, improvements and the like made within the spirit and principle of the present disclosure should be included in the scope of the present disclosure.

Claims (12)

1. A method for determining test data for an application interface, comprising:
in response to receiving a test request from a client, intercepting the test request by using a network request framework and generating intercepted data, wherein the intercepted data comprises a data source identifier, and the network request framework is used for encapsulating the test request;
determining a target data source according to the data source identification;
in response to receiving a get request, generated by the network request framework after determining the target data source, test data is determined from the target data source, the test data being used to test an application interface.
2. The method of claim 1, wherein the data source identification comprises an interface address identification of a target server and a profile address identification of the client; determining a target data source according to the data source identification, including:
under the condition that the configuration file address identifier comprises first parameter information, determining a configuration file corresponding to the first parameter information as a target data source;
and under the condition that the interface address identifier comprises second parameter information, determining an interface file of the target server corresponding to the second parameter information as a target data source.
3. The method of claim 2, wherein the determining a target data source from the data source identification further comprises:
and under the condition that the configuration file address identification does not comprise the first parameter information and the interface address identification does not comprise the second parameter information, determining a preset file as a target data source, wherein the preset file is determined by the network request framework.
4. The method of claim 2, wherein the test data comprises first simulation data that matches the profile, the profile comprising a custom file of a user at the client; the determining test data from the target data source in response to receiving the fetch request includes:
responding to a first obtaining request, obtaining the configuration file based on a buffer reading method, wherein the buffer reading method is used for reading data from a pre-established character buffer area, and the first obtaining request is used for obtaining the configuration file from the client;
generating the first simulation data for testing an application interface based on the configuration file.
5. The method of claim 2, wherein the test data comprises second simulation data matching the interface file; the determining test data from the target data source in response to receiving the fetch request includes:
responding to a second acquisition request, and starting a sub thread for acquiring an interface file, wherein the second acquisition request is used for asynchronously acquiring the interface file from the target server;
sending a network request to the target server;
receiving the interface file returned by the target server and ending the sub-thread; and
and generating the second simulation data for testing the application interface according to the interface file.
6. The method of claim 1, wherein after said determining test data from said target data source in response to receiving a fetch request, further comprising:
converting the test data into intermediate data in a first data format, wherein the first data format comprises a character string data format, and the data format of the test data comprises a JSON data format; and
and determining response data of a second data format according to the intermediate data, wherein the second data format comprises an entity object format, and the response data is used for determining the test result of the application interface.
7. The method of claim 1, wherein prior to intercepting the test request and generating intercepted data using a network request framework in response to receiving the test request from a client, further comprising:
calling a resource file with a preset format; and
and configuring a class interface in the resource file to the client according to an initialization method in the resource file, wherein the class interface is used for configuring the network request framework.
8. The method of claim 7, further comprising:
displaying a test interface under the condition that the class interface is called;
and responding to the preset operation of the user on the test interface to generate the test request.
9. An apparatus for determining test data for an application interface, comprising:
the system comprises an interception module, a test module and a data processing module, wherein the interception module is used for responding to a test request from a client and utilizing a network request framework to intercept the test request and generate intercepted data, the intercepted data comprises a data source identification, and the network request framework is used for packaging the test request;
the analog data acquisition module is used for determining a target data source according to the data source identification; and
a generation module to determine test data from the target data source in response to receiving an acquisition request, the acquisition request generated by the network request framework after determining the target data source, the test data for testing an application interface.
10. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
wherein the one or more programs, when executed by the one or more processors, cause the one or more processors to perform the method of any of claims 1-8.
11. A computer readable storage medium having stored thereon executable instructions which, when executed by a processor, cause the processor to perform the method of any one of claims 1 to 8.
12. A computer program product comprising a computer program which, when executed by a processor, implements a method according to any one of claims 1 to 8.
CN202210903313.2A 2022-07-29 2022-07-29 Method and device for determining test data of application interface Pending CN115061941A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210903313.2A CN115061941A (en) 2022-07-29 2022-07-29 Method and device for determining test data of application interface

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210903313.2A CN115061941A (en) 2022-07-29 2022-07-29 Method and device for determining test data of application interface

Publications (1)

Publication Number Publication Date
CN115061941A true CN115061941A (en) 2022-09-16

Family

ID=83206671

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210903313.2A Pending CN115061941A (en) 2022-07-29 2022-07-29 Method and device for determining test data of application interface

Country Status (1)

Country Link
CN (1) CN115061941A (en)

Similar Documents

Publication Publication Date Title
US11188310B2 (en) Automatically generating an interface description in an interface description language
CN111176626B (en) Cross-programming-language code calling method and device, medium and equipment
US9274935B1 (en) Application testing system with application programming interface
US8239839B2 (en) Asynchrony debugging using web services interface
US9652364B1 (en) Cloud service for mobile testing and debugging
US11762763B2 (en) Orchestration for automated performance testing
US10209968B2 (en) Application compiling
US20080244062A1 (en) Scenario based performance testing
CN113778848A (en) Test code generation method, device, computer system and medium
CN112631590B (en) Component library generation method, device, electronic equipment and computer readable medium
CN111026439B (en) Application program compatibility method, device, equipment and computer storage medium
CN111338623A (en) Method, device, medium and electronic equipment for developing user interface
US9760472B2 (en) Tenant code debugging in multi-tenant systems
CN108694120B (en) Method and device for testing service component
CN113360377B (en) Test method and device
CN114237651A (en) Installation method and device of cloud native application, electronic equipment and medium
CN112988175A (en) Cross-platform application installation package generation method, device, medium and electronic equipment
US10073689B2 (en) Managing application lifecycles within a federation of distributed software applications
CN115080109A (en) Multi-cloud-end environment joint debugging method, device, system and equipment based on hybrid development
CN115061941A (en) Method and device for determining test data of application interface
CN114915565A (en) Method and system for debugging network
CN113986679A (en) Performance analysis method and device based on configuration information hot loading
CN108089899B (en) Method and device for realizing query report
CN108170557B (en) Method and apparatus for outputting information
US20220413813A1 (en) Method and system for automating development of white labeled measurement application

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