WO2020211360A1 - Mock测试方法、系统、电子设备及计算机非易失性可读存储介质 - Google Patents

Mock测试方法、系统、电子设备及计算机非易失性可读存储介质 Download PDF

Info

Publication number
WO2020211360A1
WO2020211360A1 PCT/CN2019/118066 CN2019118066W WO2020211360A1 WO 2020211360 A1 WO2020211360 A1 WO 2020211360A1 CN 2019118066 W CN2019118066 W CN 2019118066W WO 2020211360 A1 WO2020211360 A1 WO 2020211360A1
Authority
WO
WIPO (PCT)
Prior art keywords
mock
test
target
return data
return
Prior art date
Application number
PCT/CN2019/118066
Other languages
English (en)
French (fr)
Inventor
文琦
Original Assignee
平安普惠企业管理有限公司
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 平安普惠企业管理有限公司 filed Critical 平安普惠企业管理有限公司
Publication of WO2020211360A1 publication Critical patent/WO2020211360A1/zh

Links

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
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/18Multiprotocol handlers, e.g. single devices capable of handling multiple protocols

Definitions

  • This application relates to the field of testing technology, and in particular to a mock testing method, system, electronic device, and computer non-volatile readable storage medium.
  • Software testing is a process of operating a program under prescribed conditions to find program errors, measure software quality, and evaluate whether it can meet design requirements. It can help identify the completed computer software (whole or part) ) Accuracy, completeness and quality.
  • test objects often cannot run independently and need to rely on other types of objects or external services to run to complete the test.
  • financial applications APP
  • systems of related parties such as banks and courts. If the systems of related parties are unstable, it will have a greater impact on the testing of financial apps.
  • Mock testing can create a virtual object to replace some related party objects during the testing process, and enable the virtual object to simulate return Features.
  • Hyper Text Transfer Protocol HTTP
  • HTTPS Hyper Text Transfer Protocol Secure
  • Transmission Control Protocol/Internet Protocol Transmission Control Protocol/Internet Protocol
  • an object of the present application is to provide a mock test method, system, electronic device, and computer non-volatile readable storage medium.
  • a Mock test method includes: creating a Mock class object in a Mock test system according to a test interface document, the test interface document including at least test request parameters, return parameters, communication protocols supported by the test interface, and The session object corresponding to the test interface; generate return data of the Mock object in the Mock test system; receive a test interface call request sent by the test object in the target communication mode corresponding to the target communication protocol; wherein, the test The interface call request carries a target Mock class object, and the target Mock class object is any one of the Mock class objects; returning target return data to the test object in the target communication mode to complete the mock test, The target return data is the return data of the target Mock class object.
  • a Mock test system includes: a creation unit for creating a mock object in the Mock test system according to a test interface document, where the test interface document at least includes test request parameters, return parameters, and test The communication protocol supported by the interface and the session object corresponding to the test interface; a generating unit for generating return data of the Mock class object in the mock test system; a receiving unit for receiving the test object corresponding to the target communication protocol
  • the test interface call request sent by the target communication mode of the test interface; wherein the test interface call request carries a target Mock class object, and the target Mock class object is any one of the Mock class objects; the return unit is used to The target communication method returns target return data to the test object to complete the mock test, and the target return data is the return data of the target Mock class object.
  • an electronic device includes: a processor; and
  • the memory is used to store the mock test program of the processor; wherein, the processor is configured to execute the mock test method as described above by executing the mock test program.
  • a computer non-volatile readable storage medium having a mock test program stored thereon is characterized in that the mock test method described above is implemented when the mock test program is executed by a processor
  • a computer program product includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to cause a computer to execute operations as described in the first embodiment of the present invention. The method described in the aspect or any possible implementation of the first aspect.
  • the mock test system can support multiple communication protocols, and can return target return data to the test object in a target communication mode, thereby simulating various test scenarios, and making software testing more convenient.
  • FIG. 1 is a schematic structural diagram of a device disclosed in an embodiment of the present application.
  • FIG. 2 is a flowchart of a mock test method disclosed in an embodiment of the present application.
  • FIG. 3 is a flowchart of another mock test method disclosed in an embodiment of the present application.
  • FIG. 4 is a flowchart of yet another mock test method disclosed in an embodiment of the present application.
  • FIG. 5 is a schematic structural diagram of a mock test system disclosed in an embodiment of the present application.
  • FIG. 6 is a schematic structural diagram of another mock test system disclosed in an embodiment of the present application.
  • the implementation environment of this application may be an electronic device, such as a smart phone, a tablet computer, or a desktop computer.
  • FIG. 1 is a schematic structural diagram of a device disclosed in an embodiment of the present application.
  • the device 100 may be the aforementioned electronic device.
  • the device 100 may include one or more of the following components: a processing component 102, a memory 104, a power supply component 106, a multimedia component 108, an audio component 110, a sensor component 114, and a communication component 116.
  • the processing component 102 generally controls the overall operations of the device 100, such as operations associated with display, telephone calls, data communications, camera operations, and recording operations.
  • the processing component 102 may include one or more processors 118 to execute instructions to complete all or part of the steps of the following method.
  • the processing component 102 may include one or more modules to facilitate the interaction between the processing component 102 and other components.
  • the processing component 102 may include a multimedia module to facilitate the interaction between the multimedia component 108 and the processing component 102.
  • the memory 104 is configured to store various types of data to support operations in the device 100. Examples of these data include instructions for any application or method operating on the device 100.
  • the memory 104 may be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (Static Random Access Memory, SRAM for short), electrically erasable programmable read-only memory (Electrically Erasable). Programmable Read-Only Memory, EEPROM for short)
  • Erasable Programmable Read Only Memory Erasable Programmable Read Only Memory
  • One or more modules are also stored in the memory 104, and the one or more modules are configured to be executed by the one or more processors 118 to complete all or part of the steps in the method shown below.
  • the power supply component 106 provides power to various components of the device 100.
  • the power supply component 106 may include a power management system, one or more power supplies, and other groups associated with the generation, management, and distribution of power for the device 100 Pieces.
  • the multimedia component 108 includes a screen that provides an output interface between the device 100 and the user.
  • the screen may include a liquid crystal display (Liquid Crystal Display, LCD for short) and a touch panel. If the screen includes a touch panel, the screen can be implemented as a touch screen to receive input signals from the user.
  • the touch panel includes one or more touch sensors to sense touch, swipe, and gestures on the touch panel. The touch sensor can not only sense the boundary of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation.
  • the screen may also include an Organic Light Emitting Display (OLED for short).
  • OLED Organic Light Emitting Display
  • the audio component 110 is configured to output and/or input audio signals.
  • the audio component 110 includes a microphone (Microphone, MIC for short).
  • the microphone is configured to receive an external audio signal.
  • the received audio signal may be further stored in the memory 104 or transmitted via the communication component 116.
  • the audio component 110 further includes a speaker for outputting audio signals.
  • the sensor assembly 114 includes one or more sensors for providing the device 100 with various aspects of status evaluation.
  • the sensor component 114 can detect the on/off status of the device 100 and the relative positioning of the components.
  • the sensor component 114 can also detect the position change of the device 100 or one component of the device 100 and the temperature change of the device 100.
  • the sensor component 114 may also include a magnetic sensor, a pressure sensor or a temperature sensor.
  • the communication component 116 is configured to facilitate wired or wireless communication between the apparatus 100 and other devices.
  • the device 100 can access wireless networks based on communication standards, such as WiFi (Wireless-Fidelity, wireless fidelity).
  • WiFi Wireless-Fidelity, wireless fidelity
  • the communication component 116 receives a broadcast signal or broadcast related information from an external broadcast management system via a broadcast channel.
  • the communication component 116 further includes near field communication
  • the NFC module can be based on radio frequency identification (Radio Frequency Identification, RFID) technology, infrared Data Association (IrDA) technology, ultra-wideband (Ultra), radio frequency identification (Radio Frequency Identification, RFID) technology, infrared Data Association (IrDA) technology, ultra-wideband (Ultra), radio frequency identification (Radio Frequency Identification, RFID) technology, infrared Data Association (IrDA) technology, ultra-wideband (Ultra) technology, and ultra-wideband (Ultra).
  • RFID Radio Frequency Identification
  • IrDA infrared Data Association
  • Ultra ultra-wideband
  • UWB Wideband
  • Bluetooth Bluetooth technology
  • the apparatus 100 may be implemented by one or more application specific integrated circuits (Application Specific Integrated Circuits). Specific Integrated Circuit, referred to as ASIC), digital signal processor, digital signal processing equipment, programmable logic device, field programmable gate array, controller, microcontroller, microprocessor or other electronic components for implementation, used to perform the following method.
  • ASIC Application Specific Integrated Circuit
  • digital signal processor digital signal processing equipment
  • programmable logic device programmable logic device
  • field programmable gate array controller
  • microcontroller microprocessor or other electronic components for implementation, used to perform the following method.
  • FIG. 2 is a schematic flowchart of a mock test method disclosed in an embodiment of the present application. As shown in Figure 2, the mock test method can include the following steps:
  • test interface document at least including test request parameters, return parameters, communication protocols supported by the test interface, and session objects corresponding to the test interface.
  • the Mock class object is mainly used to simulate the related party system, that is, the external environment system associated with the test object. Developers build test interface documents based on the characteristics of all aspects of the test interface, and then the test system can create mock objects with the characteristics of all aspects of the related party system in the test system according to the test interface documents.
  • each Mock class object created in the Mock test system has its own corresponding test interface, and each test interface has its own corresponding test request parameters, return parameters, and tests.
  • the communication protocol supported by the interface and the session object corresponding to the test interface is not limited to the test interface.
  • the Mock test system may adopt the SSM framework set (Spring+SpringMVC+M yBatis), which integrates mainstream protocol frameworks, and loads jar packages of different service frameworks and the sending method in advance. Therefore, when the user is in After the front desk has selected different communication methods, the Mock test system can send the target return data according to the user according to the communication method selected by the user.
  • the communication protocol supported by the above test interface may include at least one of the communication protocols such as HTTP, HTTPS, TCP/IP, and JavaEE server-side component model (Enterprise JavaBean, EGB).
  • each mock object has its own corresponding return data, which is used to feed back to the test object after being accessed by the test object so that the test object can complete the software test.
  • test interface call request sent by the test object in the target communication mode corresponding to the target communication protocol; wherein the test interface call request carries a target Mock class object, and the target Mock class object is Any of the above Mock class objects.
  • test interface call request sent by the test object is mainly used to access the target Mock class object by calling the test interface corresponding to the target Mock class object.
  • the Mock test method is based on the Mock technology, which can reduce the dependence on the external system environment during the test process. By constructing reasonable return data, any test scenario can be covered and the response is fast, and external interference can be reduced. Communication costs.
  • step 204 may include:
  • the response delay is determined according to the system type corresponding to the system simulated by the target Mock object; and after the response delay, the target communication method is used to return the target return data to the test object to complete Mock test, the target return data is the return data of the target Mock class object
  • the response delay can be set according to the system simulated by the Mock class object. For example, if the feedback time of the simulated system is 20s, then the response delay of the Mock class object can be set to 18s based on experience, combined with the response time required by the Mock class object itself, the time to finally get the returned data can also be approximately Keep it around 20s. It can be seen that by implementing this embodiment, the simulated test environment can be closer to reality.
  • the Mock class object can simulate the external environment system, where the test interface document includes the communication protocol supported by the test interface, That is, the communication protocol supported by the Mock test system is not limited to HTTP. Therefore, the Mock test system can support multiple communication protocols, and can return target return data to the test object in the target communication mode, thereby simulating various test scenarios, enabling software testing More convenient.
  • FIG. 3 is a schematic flowchart of another mock test method disclosed in an embodiment of the present application. As shown in Fig. 3, the mock test method may include the following steps:
  • test interface document including at least test request parameters, return parameters, communication protocols supported by the test interface, and session objects corresponding to the test interface.
  • each Mock class object has a fixed return data, and for any test interface call request, all the test interface calls are returned. Request the fixed return data corresponding to the corresponding Mock class object.
  • test interface call request sent by the test object in the target communication mode corresponding to the target communication protocol; wherein the test interface call request carries a target Mock class object, and the target Mock class object is any of the above Mock class objects.
  • [0059] 304 Generate a Mock task according to the test interface call request, where the Mock task is used to instruct to access the target Mock class object corresponding to the test interface call request.
  • a certain execution node matches a certain mock task, specifically, the task type processed by the execution node matches the task type of the mock task.
  • the task type may include a performance test type and a common test type, where the performance test may include test resource occupancy rate, task processing time, etc., and the common test may include test code logic.
  • step 304 and step 305 can distinguish the task type of the test, generate a mock task, and assign the mock task to the first execution node that matches the mock task so that the first execution node can access the target Mock class object corresponding to the test interface call request , Can improve the versatility of Mock test system.
  • the method may further include: [0064] Set performance test execution nodes and ordinary test execution nodes in the mock test system; divide performance test execution nodes into at least resource occupancy test execution nodes and task processing time test execution nodes; and, divide ordinary test execution nodes at least It is the code logic test node and the code integrity test node.
  • Step 305 may include:
  • the execution nodes in the mock test system are classified according to task types, and the corresponding types of mock tasks are processed, which can avoid the occurrence of multiple test objects sending test interface call requests to the mock test system at the same time. Of chaos.
  • step 305 may include:
  • the Mock task is assigned to the first execution node that matches the Mock task, if the target return data returned by the first execution node is not received within the preset time period, The mock task is assigned to the second execution node, which can prevent the test interruption or delay caused by the failure of the first execution node and other factors that affect the test.
  • step 306 may include:
  • the above test interface call request may also include the identity of the test object, and the Mock task generated according to the test interface call request includes the identity. Assign the Mock task to the execution node that matches the Mock task, so that the execution node executes the Mock task to generate the target return data of the target Mock class object, and assigns the target Mock class to the target Mock class according to the identity of the test object The target return data of the object is returned to the corresponding test object.
  • the traditional Mock test method does not distinguish between the type of test object and the requesting party requesting the Mock test. Therefore, in the implementation of this embodiment, the mock test system can also distinguish multiple test objects through the identification, so that the versatility of the mock test system can be further improved.
  • the Mock class object is created in the Mock test system through the test interface document, the Mock class object can simulate the external environment system, and the test interface document includes the communication protocol supported by the test interface, That is, the communication protocol supported by the Mock test system is not limited to HTTP.
  • the Mock test system can support multiple communication protocols, and can return target return data to the test object in the target communication mode, thereby simulating various test scenarios, enabling software testing More convenient;
  • generate mock tasks according to the test interface call request and assign the mock tasks to the first execution node that matches the mock task, which can distinguish the types of test objects and avoid the need to perform tests on multiple test objects simultaneously
  • it can prevent the interruption or delay of the test caused by the failure of the first execution node and other factors that affect the test.
  • multiple test objects can be distinguished by identification, which can further improve The versatility of the Mock test system.
  • FIG. 4 is a schematic flowchart of another mock test method disclosed in an embodiment of the present application.
  • the mock test method can include the following steps:
  • test interface document at least includes test request parameters, return parameters, communication protocols supported by the test interface, and session objects corresponding to the test interface.
  • the code is compiled on the Web page.
  • the code specification can be set, and the user needs to follow the code specification when writing the code, where the return data generation code input by the user on the Web page may be
  • the java code may also be js code, etc., which is not limited in the embodiment of the present application.
  • test interface call request sent by the test object in the target communication mode corresponding to the target communication protocol; wherein the test interface call request carries a target Mock class object, and the target Mock class object is any of the above Mock class objects.
  • target test interface corresponding to the call request is called by the test interface, call the return data corresponding to the target test interface from the foregoing database to generate code, where the target test interface is any one of the test interfaces.
  • the tomcat container can compile and return data generation code to obtain member classes.
  • a tomcat container is used to return corresponding target return data through code logic.
  • step 403 the following steps may be further included:
  • step 406 the following steps may be further included:
  • test result returned by the test object where the test result includes at least the test value of the target test index, where the target test index is at least one of the above-mentioned software test indexes; determine whether the test values of the target test index are all greater than the target test The preset compliance value of the indicator; if not, obtain the test indicators that do not meet the criteria in the target test indicators, and output the preset associated factors corresponding to the test indicators that do not meet the criteria.
  • the substandard test index is a test index in the target test index whose test value is less than the preset standard value
  • the preset correlation factor refers to the factor that will cause the test value of the software test index to change. It can be understood as the dependent variable of the numerical value of the software test index. It can be seen that by implementing this embodiment, the test values of the target test indicators are not all greater than the preset compliance values of the target test indicators, that is, when the software test results fail, the preset associated factors corresponding to the test indicators that do not meet the standards are output, and then Provide developers with reference information on how to optimize the software.
  • the user-defined return parameter and/or the user-defined communication that the user can input on the Web interface Communication protocol to modify information such as return parameters and/or communication protocol without modifying the code, which can reduce the workload of developers.
  • the implementation of the method described in FIG. 4 creates a Mock class object in the Mock test system through the test interface document.
  • the Mock class object can simulate the external environment system, and the test interface document includes the communication protocol supported by the test interface. That is, the communication protocol supported by the Mock test system is not limited to HTTP.
  • the Mock test system can support multiple communication protocols, and can return target return data to the test object in the target communication mode, thereby simulating various test scenarios, enabling software testing More convenient;
  • the user can write the return data generation code on the Web page, and return the corresponding target return data through the code logic when receiving the test interface call request, so that the target return data is more in line with the test requirements;
  • the user can use the Web interface
  • the custom return parameter and/or custom communication protocol entered on the above can be used to modify the return parameter and/or communication protocol and other information without modifying the code, which can reduce the workload of the developer.
  • FIG. 5 is a schematic structural diagram of a mock test system disclosed in an embodiment of the present application.
  • the mock test system may include: a creating unit 501, a generating unit 502, a receiving unit 503, and a returning unit 504, where
  • the creating unit 501 is configured to create a Mock class object in the Mock test system according to the test interface document, the test interface document including at least test request parameters, return parameters, communication protocols supported by the test interface, and session objects corresponding to the test interface ;
  • the generating unit 502 is used to generate the return data of the Mock class object in the Mock test system
  • the receiving unit 503 is configured to receive a test interface call request sent by the test object in the target communication mode corresponding to the target communication protocol; wherein the test interface call request carries a target Mock class object, and the target Mock class object is a Mock class object Any of
  • the returning unit 504 is configured to return target return data to the test object in a target communication mode to complete the mock test, and the target return data is the return data of the target mock class object.
  • the return unit 504 is configured to return target return data to the test object in a target communication mode to complete the mock test.
  • the target return data is the return data of the target Mock class object.
  • the specific method may be :
  • the returning unit 504 is configured to, when receiving the test interface call request, according to the target Mock class object
  • the system type corresponding to the simulated system determines the response delay; and after the response delay, the target return data is returned to the test object in the target communication mode to complete the mock test, and the target return data is the return data of the target Mock class object.
  • the Mock test system described in FIG. 5 is implemented, and Mock class objects are created in the Mock test system through the test interface document.
  • the Mock class object can simulate the external environment system, and the test interface document includes the communication supported by the test interface.
  • Protocol that is, the communication protocol supported by the Mock test system is not limited to HTTP. Therefore, the Mock test system can support a variety of communication protocols, can return target return data to the test object in the target communication mode, and can simulate various test scenarios to make the software Testing is more convenient
  • FIG. 5 is a schematic structural diagram of another mock test system disclosed in an embodiment of the present application.
  • the mock test system shown in the sixth embodiment is optimized by the mock test system shown in the fifth embodiment. Compared with the mock test system shown in the fifth embodiment, in the mock test system shown in the sixth embodiment
  • the way that the generating unit 502 is used to generate the return data of the Mock class object in the Mock test system can be specifically:
  • the generating unit 502 is configured to configure fixed data in the Mock test system as the return data of the Mock class object.
  • the return unit 504 is used to return the target return data to the test object in the target communication mode to complete the mock test.
  • the specific method is:
  • the returning unit 504 is configured to generate a Mock task according to the test interface call request, where the Mock task is used to instruct to access the target Mock class object corresponding to the test interface call request; and assign the Mock task to the first execution that matches the mock task Node, so that the first execution node returns the target return data after accessing the target Mock class object; returns the target return data to the test object in a target communication mode to complete the mock test;
  • the returning unit 504 is configured to assign the Mock task to the first execution node that matches the Mock task, so that the first execution node returns to the target after accessing the target Mock class object
  • the specific method of returning data can be:
  • the returning unit 504 is configured to allocate the Mock task to the first execution node that matches the Mock task; detect whether the target return data returned by the first execution node is received within a preset time period; if not, set Moc The k task is assigned to the second execution node matching the Mock task, so that the second execution node returns the target return data after accessing the target Mock class object.
  • the Mock task is assigned to the first execution node that matches the Mock task, if the target return data returned by the first execution node is not received within the preset time period, The mock task is assigned to the second execution node, which can prevent the test interruption or delay caused by the failure of the first execution node and other factors that affect the test.
  • the generating unit 502 is further configured to set the performance in the mock test system before the receiving unit 503 receives the test interface call request sent by the test object in the target communication mode corresponding to the target communication protocol.
  • Test execution nodes and ordinary test execution nodes divide performance test execution nodes into at least resource occupancy test execution nodes and task processing time test execution nodes; and, divide ordinary test execution nodes into at least code logic test nodes and code integrity tests node.
  • the returning unit 504 is used to assign the Mock task to the first execution node that matches the Mock task, so that the first execution node returns the target return data after accessing the target Mock class object.
  • the returning unit 504 is used to obtain the task type of the Mock task, and select an execution node matching the Mock task from the execution nodes in the Mock test system as the first execution node; assign the Mock task to the first execution node Node, so that the first execution node returns the target return data after accessing the target Mock class object.
  • the execution nodes in the mock test system are classified according to task types, and the corresponding types of mock tasks are processed, which can avoid the occurrence of multiple test objects sending test interface call requests to the mock test system at the same time. Of chaos.
  • the return unit 504 is configured to return the target return data to the test object in the target communication mode to complete the mock test.
  • the specific method may be:
  • the returning unit 504 is configured to obtain the identity of the test object according to the Mock task; and return target return data to the test object in a target communication mode according to the identity to complete the mock test.
  • the test interface call request may also include the identity of the test object, and the Mock task generated according to the test interface call request includes the identity. Assign the Mock task to the execution node that matches the Mock task, so that the execution node executes the Mock task to generate the target return data of the target Mock class object, and returns the target return data of the target Mock class object according to the identity of the test object To the corresponding test object.
  • the traditional Mock test method does not distinguish between the type of test object and the requesting party requesting the Mock test. Therefore, in the implementation of this embodiment, the mock test system can also distinguish multiple test objects through the identification, so that the versatility of the mock test system can be further improved.
  • the Mock test system described in the sixth embodiment creates a Mock class object in the Mock test system through a test interface document, and the Mock class object can simulate an external environment system, wherein the test interface document includes the communication supported by the test interface Protocol, that is, the communication protocol supported by the Mock test system is not limited to HTTP.
  • the Mock test system can support a variety of communication protocols, and can return target return data to the test object in the target communication mode, thereby simulating various test scenarios and making the software Testing is more convenient; in addition, the Mock task is generated according to the test interface call request, and the Mock task is assigned to the first execution node that matches the M ock task, which can distinguish the types of test objects and avoid the need for synchronization among multiple test objects Confusion occurs during the test; in addition, it can prevent the interruption or delay of the test caused by the failure of the first execution node and other factors that affect the test. In addition, multiple test objects can be distinguished by identification, so as to further Can improve the versatility of the Mock test system.
  • FIG. 6 is a schematic structural diagram of another mock test system disclosed in an embodiment of the present application.
  • the Mock test system shown in Figure 6 is optimized by the Mock test system shown in Figure 5.
  • the mock test system shown in Fig. 6 may further include: a configuration unit 505, a detection unit 506, and an update unit 507, where
  • the way that the generating unit 502 is used to generate the return data of the Mock class object in the Mock test system can be specifically:
  • the generating unit 502 is used to obtain the return data generating code corresponding to the test interface input by the user in the Web page, and store it in the database of the mock test system.
  • the return unit 504 is used to return the target return data to the test object in the target communication mode to complete the mock test.
  • the specific way to try is:
  • the return unit 504 is configured to retrieve the return data corresponding to the target test interface from the database to generate code when the target test interface corresponding to the test interface call request is called, and the target test interface is any one of the test interfaces; Reflection loads the return data generation code corresponding to the target test interface into the tomcat container, and compiles it to obtain a member class; obtains the target return data according to the member class, and returns the target return data to the test object in the target communication mode to complete the mock test.
  • the generating unit 502 is further configured to obtain the software test index before the receiving unit 503 receives the test interface call request sent by the test object in the target communication mode corresponding to the target communication protocol, and determine each The preset compliance value corresponding to a software test index and the preset associated factors corresponding to each software test index;
  • the returning unit 504 After the returning unit 504 is used to return the target return data to the test object in the target communication mode to complete the mock test, it may also be used to receive the test result returned by the test object.
  • the test result is at least the test value of the target test index.
  • the target test index is at least one of the above software test indexes; judge whether the test values of the target test index are all greater than the preset compliance value of the target test index; if not, obtain the test index that does not meet the standard in the target test index, and output the non-compliant
  • the test indicators correspond to the preset correlation factors.
  • the preset correlation factor refers to a factor that causes the test value of the software test index to change, and can be understood as a dependent variable of the value of the software test index. It can be seen that by implementing this embodiment, the test values of the target test indicators are not all greater than the preset compliance values of the target test indicators, that is, when the software test results fail, the preset associated factors corresponding to the test indicators that do not meet the standards are output, and then Provide developers with reference information on how to optimize the software.
  • the configuration unit 505 is used to configure the return parameters and communication protocols in the test interface document on the Web page
  • the detection unit 506 is configured to detect the custom return parameters and/or custom communication protocols input by the user in the Web page;
  • the update unit 507 is configured to update the test interface document according to the custom return parameters and/or the custom communication protocol, and update the Mock class object according to the updated test interface document.
  • test interface document is used in the Mock test system Create Mock class objects.
  • Mock class objects can simulate the external environment system.
  • the test interface document includes the communication protocol supported by the test interface, that is, the communication protocol supported by the Mock test system is not limited to HTTP.
  • the Mock test system can support multiple communications
  • the protocol can return the target return data to the test object in the target communication mode, which can simulate various test scenarios, making software testing more convenient;
  • the user can write the return data generation code on the Web page, and after receiving the test interface call request The corresponding target return data is returned through the code logic, so that the target return data is more in line with the test requirements;
  • the user can input custom return parameters and/or custom communication protocols on the web interface to modify the return parameters and/or communication Protocol and other information without modifying the code can reduce the developer's workload.
  • the present application also provides an electronic device, which includes:
  • the electronic device may be the apparatus 100 shown in FIG. 1.
  • the present application further provides a computer non-volatile readable storage medium, on which a computer program is stored, and when the computer program is executed by the processor, the Mock testing method.
  • the present application also provides a computer program product
  • the computer program product includes a non-transitory computer-readable storage medium storing a computer program
  • the computer program is operable to make a computer Execute the Mock test method as shown before.
  • the computer program product includes program code, and when the program product runs on a terminal device, the program code is used to make the terminal device execute the various methods described in the “Exemplary Method” section of this specification. Steps of an exemplary embodiment.

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)
  • Computer Security & Cryptography (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Debugging And Monitoring (AREA)

Abstract

本申请提供了一种Mock测试方法、系统、电子设备及计算机非易失性可读存储介质,属于测试技术领域,该方法包括:根据测试接口文档在Mock测试系统中创建Mock类对象,该测试接口文档至少包括测试请求参数、返回参数、测试接口支持的通讯协议以及该测试接口对应的会话对象;在Mock测试系统中生成上述Mock类对象的返回数据;接收测试对象以目标通讯协议对应的目标通讯方式发送的测试接口调用请求;以上述目标通讯方式向测试对象返回目标返回数据,该目标返回数据为测试接口调用请求对应的目标Mock类对象的返回数据。可见, Mock测试系统能够支持多种通讯协议,从而能够模拟各种测试场景,使得软件测试更加方便。

Description

发明名称: Mock测试方法、 系统、 电子设备及计算机非易失性可读 存储介质
技术领域
[0001] 本申请要求 2019年 04月 19日递交、 发明名称为“Mock测试方法及系统、 电子设 备及可读存储介质”的中国专利申请 201910318274.8的优先权, 在此通过引用将 其全部内容合并于此。
[0002] 本申请涉及测试技术领域, 尤其涉及一种 Mock测试方法、 系统、 电子设备及 计算机非易失性可读存储介质。
背景技术
[0003] 软件测试是在规定的条件下对程序进行操作, 以发现程序错误, 衡量软件质量 , 并对其是否能满足设计要求进行评估的过程, 能够帮助识别开发完成的计算 机软件 (整体或部分) 的正确度、 完全度和质量。
[0004] 在软件开发的过程中, 需要对已开发的工程代码进行测试。 然而, 测试对象往 往不能独立运行, 需要依赖于其他类对象或者外部服务运行以完成测试。 比如 说, 金融应用程序 (Application, APP) 经常需要与银行、 法院等关联方的系统 进行对接, 如果关联方系统不稳定, 将会对金融 APP的测试造成较大影响。
[0005] 为了减少关联方的系统对软件测试造成的影响, 可以采用 Mock技术进行测试 , Mock测试可以在测试过程中创建一个虚拟对象来代替某些关联方对象, 并使 得该虚拟对象能够模拟返回功能。
发明概述
技术问题
[0006] 本申请的发明人意识到, 目前市面上的 Mock工具提供的测试方法, 仅仅能支 持超文本传输协议 (Hyper Text Transfer Protocol, HTTP), 而实际工程中不同对 象之间还可能通过超文本传输安全协议 (Hypertext Transfer Protocol Secure , HTTPS) 或传输控制协议 /因特网互联协议 (Transmission Control
Protocol/Internet Protocol, TCP/IP ) 等通讯协议进行通信, 目前的 Mock测试方法 无法支持多种通讯协议, 为软件测试带来不便。
问题的解决方案
技术解决方案
[0007] 为了解决上述技术问题, 本申请的一个目的在于提供一种 Mock测试方法、 系 统、 电子设备及计算机非易失性可读存储介质。
[0008] 其中, 本申请所采用的技术方案为:
[0009] 第一方面, 一种 Mock测试方法, 包括: 根据测试接口文档在 Mock测试系统中 创建 Mock类对象, 所述测试接口文档至少包括测试请求参数、 返回参数、 测试 接口支持的通讯协议以及所述测试接口对应的会话对象; 在所述 Mock测试系统 中生成所述 Mock类对象的返回数据; 接收测试对象以目标通讯协议对应的目标 通讯方式发送的测试接口调用请求; 其中, 所述测试接口调用请求携带有目标 M ock类对象, 所述目标 Mock类对象为所述 Mock类对象中的任一个; 以所述目标 通讯方式向所述测试对象返回目标返回数据以完成 Mock测试, 所述目标返回数 据为所述目标 Mock类对象的返回数据。
[0010] 第二方面, 一种 Mock测试系统, 包括: 创建单元, 用于根据测试接口文档在 M ock测试系统中创建 Mock类对象, 所述测试接口文档至少包括测试请求参数、 返 回参数、 测试接口支持的通讯协议以及所述测试接口对应的会话对象; 生成单 元, 用于在所述 Mock测试系统中生成所述 Mock类对象的返回数据; 接收单元, 用于接收测试对象以目标通讯协议对应的目标通讯方式发送的测试接口调用请 求; 其中, 所述测试接口调用请求携带有目标 Mock类对象, 所述目标 Mock类对 象为所述 Mock类对象中的任一个; 返回单元, 用于以所述目标通讯方式向所述 测试对象返回目标返回数据以完成 Mock测试, 所述目标返回数据为所述目标 Mo ck类对象的返回数据。
[0011] 第三方面, 一种电子设备, 包括: 处理器; 以及
[0012] 存储器, 用于存储所述处理器的 Mock测试程序; 其中, 所述处理器配置为经 由执行所述 Mock测试程序来执行如上所述的 Mock测试方法。
[0013] 第四方面, 一种计算机非易失性可读存储介质, 其上存储有 Mock测试程序, 其特征在于, 所述 Mock测试程序被处理器执行时实现如上所述的 Mock测试方法 [0014] 第五方面, 一种计算机程序产品, 所述计算机程序产品包括存储了计算机程序 的非瞬时性计算机可读存储介质, 所述计算机程序可操作来使计算机执行如本 发明实施例第一方面所述的方法或第一方面任意可能实现方式中的方法。
[0015] 在上述技术方案中, Mock测试系统能够支持多种通讯协议, 能够实现以目标 通讯方式向测试对象返回目标返回数据, 从而能够模拟各种测试场景, 使得软 件测试更加方便。
[0016] 应当理解的是, 以上的一般描述和后文的细节描述仅是示例性和解释性的, 并 不能限制本申请。
发明的有益效果
对附图的简要说明
附图说明
[0017] 此处的附图被并入说明书中并构成本说明书的一部分, 示出了符合本申请的实 施例, 并于说明书一起用于解释本申请的原理。
[0018] 图 1是本申请实施例公开的一种装置的结构示意图;
[0019] 图 2是本申请实施例公开的一种 Mock测试方法的流程图;
[0020] 图 3是本申请实施例公开的另一种 Mock测试方法的流程图;
[0021] 图 4是本申请实施例公开的又一种 Mock测试方法的流程图;
[0022] 图 5是本申请实施例公开的一种 Mock测试系统的结构示意图;
[0023] 图 6是本申请实施例公开的另一种 Mock测试系统的结构示意图。
[0024] 通过上述附图, 已示出本申请明确的实施例, 后文中将有更详细的描述, 这些 附图和文字描述并不是为了通过任何方式限制本申请构思的范围, 而是通过参 考特定实施例为本领域技术人员说明本申请的概念。
发明实施例
本发明的实施方式
[0025] 这里将详细地对示例性实施例执行说明, 其示例表示在附图中。 下面的描述涉 及附图时, 除非另有表示, 不同附图中的相同数字表示相同或相似的要素。 以 下示例性实施例中所描述的实施方式并不代表与本申请相一致的所有实施方式 。 相反, 它们仅是与如所附权利要求书中所详述的、 本申请的一些方面相一致 的装置和方法的例子。
[0026] 实施例一
[0027] 本申请的实施环境可以是电子设备, 例如智能手机、 平板电脑或台式电脑。
[0028] 图 1是本申请实施例公开的一种装置的结构示意图。 装置 100可以是上述电子设 备。 如图 1所示, 装置 100可以包括以下一个或多个组件: 处理组件 102 , 存储器 104 , 电源组件 106 , 多媒体组件 108 , 音频组件 110 , 传感器组件 114以及通信组 件 116。
[0029] 处理组件 102通常控制装置 100的整体操作, 诸如与显示, 电话呼叫, 数据通信 , 相机操作以及记录操作相关联的操作等。 处理组件 102可以包括一个或多个处 理器 118来执行指令, 以完成下述的方法的全部或部分步骤。 此外, 处理组件 10 2可以包括一个或多个模块, 用于便于处理组件 102和其他组件之间的交互。 例 如, 处理组件 102可以包括多媒体模块, 用于以方便多媒体组件 108和处理组件 1 02之间的交互。
[0030] 存储器 104被配置为存储各种类型的数据以支持在装置 100的操作。 这些数据的 示例包括用于在装置 100上操作的任何应用程序或方法的指令。 存储器 104可以 由任何类型的易失性或非易失性存储设备或者它们的组合实现, 如静态随机存 取存储器 (Static Random Access Memory, 简称 SRAM) 电可擦除可编程只读 存储器 (Electrically Erasable Programmable Read-Only Memory , 简称 EEPROM)
, 可擦除可编程只读存储器 (Erasable Programmable Read Only
Memory , 简称 EPROM) , 可编程只读存储器 (Programmable Red- Only Memory , 简称 PROM) , 只读存储器 (Read-Only Memory, 简称 ROM) , 磁存储器, 快闪存储器, 磁盘或光盘。 存储器 104中还存储有一个或多个模块, 用于该一个 或多个模块被配置成由该一个或多个处理器 118执行, 以完成如下所示方法中的 全部或者部分步骤。
[0031] 电源组件 106为装置 100的各种组件提供电力。 电源组件 106可以包括电源管理 系统, 一个或多个电源, 及其他与为装置 100生成、 管理和分配电力相关联的组 件。
[0032] 多媒体组件 108包括在装置 100和用户之间的提供一个输出接口的屏幕。 在一些 实施例中, 屏幕可以包括液晶显示器 (Liquid Crystal Display, 简称 LCD) 和触 摸面板。 如果屏幕包括触摸面板, 屏幕可以被实现为触摸屏, 以接收来自用户 的输入信号。 触摸面板包括一个或多个触摸传感器以感测触摸、 滑动和触摸面 板上的手势。 触摸传感器可以不仅感测触摸或滑动动作的边界, 而且还检测与 触摸或滑动操作相关的持续时间和压力。 屏幕还可以包括有机电致发光显示器 (Organic Light Emitting Display, 简称 OLED) 。
[0033] 音频组件 110被配置为输出和 /或输入音频信号。 例如, 音频组件 110包括一个 麦克风 (Microphone, 简称 MIC) , 当装置 100处于操作模式, 如呼叫模式、 记 录模式和语音识别模式时, 麦克风被配置为接收外部音频信号。 所接收的音频 信号可以被进一步存储在存储器 104或经由通信组件 116发送。 在一些实施例中 , 音频组件 110还包括一个扬声器, 用于输出音频信号。
[0034] 传感器组件 114包括一个或多个传感器, 用于为装置 100提供各个方面的状态评 估。 例如, 传感器组件 114可以检测到装置 100的打开 /关闭状态, 组件的相对定 位, 传感器组件 114还可以检测装置 100或装置 100—个组件的位置改变以及装置 100的温度变化。 在一些实施例中, 该传感器组件 114还可以包括磁传感器, 压 力传感器或温度传感器。
[0035] 通信组件 116被配置为便于装置 100和其他设备之间有线或无线方式的通信。 装 置 100可以接入基于通信标准的无线网络, 如 WiFi (Wireless-Fidelity, 无线保真 ) 。 在本申请实施例中, 通信组件 116经由广播信道接收来自外部广播管理系统 的广播信号或广播相关信息。 在本申请实施例中, 通信组件 116还包括近场通信
(Near Field
Communication, 简称 NFC) 模块, 用于以促进短程通信。 例如, 在 NFC模块可 基于射频识别 (Radio Frequency Identification, 简称 RFID) 技术, 红外数据协会 (infrared Data Association, 简称 IrDA) 技术, 超宽带 (Ultra
Wideband, 简称 UWB) 技术, 蓝牙技术和其他技术来实现。
[0036] 在示例性实施例中, 装置 100可以被一个或多个应用专用集成电路 (Application Specific Integrated Circuit, 简称 ASIC) 、 数字信号处理器、 数字信号处理设备、 可编程逻辑器件、 现场可编程门阵列、 控制器、 微控制器、 微处理器或其他电 子元件实现, 用于执行下述方法。
[0037] 实施例二
[0038] 请参阅图 2, 图 2是本申请实施例公开的一种 Mock测试方法的流程示意图。 如 图 2所示该 Mock测试方法可以包括以下步骤:
[0039] 201、 根据测试接口文档在 Mock测试系统中创建 Mock类对象, 该测试接口文档 至少包括测试请求参数、 返回参数、 测试接口支持的通讯协议以及该测试接口 对应的会话对象。
[0040] 本申请实施例中, Mock类对象主要是用于模拟关联方系统, 即与测试对象相 关联的外部环境系统。 开发人员根据测试接口的各方面的特征构建测试接口文 档, 进而测试系统能够在测试系统中根据测试接口文档创建具有关联方系统各 方面特征的 Mock类对象。
[0041] 本申请实施例中, 可以理解的是 Mock测试系统中创建的每一个 Mock类对象都 有自身对应的测试接口, 而每一个测试接口都有自身对应的测试请求参数、 返 回参数、 测试接口支持的通讯协议以及该测试接口对应的会话对象。
[0042] 本申请实施例中, Mock测试系统可以采用 SSM框架集 (Spring+SpringMVC+M yBatis) , 其集成主流协议框架, 提前装载了不同服务框架的 jar包和发送方式, 因此, 当用户在前台选择了不同的通讯方式之后, Mock测试系统可以根据用户 按照用户选择的通讯方式发送目标返回数据。 可见, 基于 Mock测试系统装载的 协议框架, 上述测试接口支持的通讯协议可以包括 HTTP、 HTTPS、 TCP/IP、 和 J avaEE服务器端组件模型 (Enterprise JavaBean, EGB) 等通讯协议中的至少一种
[0043] 202、 在 Mock测试系统中生成上述 Mock类对象的返回数据。
[0044] 可以理解, 每一个 Mock类对象都有自身对应的返回数据, 用于在被测试对象 访问后反馈给测试对象以使测试对象能够完成软件测试。
[0045] 203、 接收测试对象以目标通讯协议对应的目标通讯方式发送的测试接口调用 请求; 其中, 测试接口调用请求携带有目标 Mock类对象, 该目标 Mock类对象为 上述 Mock类对象中的任一个。
[0046] 可以理解, 测试对象发送测试接口调用请求主要用于通过调用目标 Mock类对 象对应测试接口来访问目标 Mock类对象。
[0047] 204、 以目标通讯方式向测试对象返回目标返回数据以完成 Mock测试, 该目标 返回数据为目标 Mock类对象的返回数据。
[0048] 本申请实施例中, Mock测试方法基于 Mock技术, 可以减少测试过程中对外部 系统环境的依赖, 通过构建合理的返回数据, 可以覆盖任意的测试场景且响应 快速, 可以减少和外部的沟通成本。
[0049] 作为一种可选的实施方式, 在步骤 204可以包括:
[0050] 在接收到上述测试接口调用请求时, 根据目标 Mock类对象模拟的系统对应的 系统类型确定响应延时; 并在经过响应延时后以目标通讯方式向测试对象返回 目标返回数据以完成 Mock测试, 该目标返回数据为目标 Mock类对象的返回数据
[0051] 本实施方式中, 可以理解的是, 由于外部环境系统的性能及架构各不相同, 在 实际的应用场景中, 调用外部环境系统获得返回信息所需的时间也不相同。 有 些系统的返回信息的返回时间较长, 而模拟该系统的 Mock类对象响应测试接口 调用请求的速度是比较快的。 因此, 为了使得模拟的线上场景更接近实际的应 用场景, 可以根据 Mock类对象模拟的系统来设定响应延时。 比如说, 如果模拟 的系统的反馈时间为 20s, 那么可以根据经验将 Mock类对象的响应延时设置为 18 s , 结合 Mock类对象自身所需的响应时间, 最终得到返回数据的时间也可以大概 保持在 20s左右。 可见, 实施本实施方式, 模拟的测试环境能够更接近现实。
[0052] 可见, 实施图 2所描述的方法, 通过测试接口文档在 Mock测试系统中创建 Mock 类对象, Mock类对象可以模拟外部环境系统, 其中测试接口文档中包括了测试 接口支持的通讯协议, 即 Mock测试系统支持的通讯协议不限于 HTTP, 从而, M ock测试系统能够支持多种通讯协议, 能够实现以目标通讯方式向测试对象返回 目标返回数据, 进而能够模拟各种测试场景, 使得软件测试更加方便。
[0053] 实施例三
[0054] 请参阅图 3, 图 3是本申请实施例公开的另一种 Mock测试方法的流程示意图。 如图 3所示, 该 Mock测试方法可以包括以下步骤:
[0055] 301、 根据测试接口文档在 Mock测试系统中创建 Mock类对象, 该测试接口文档 至少包括测试请求参数、 返回参数、 测试接口支持的通讯协议以及该测试接口 对应的会话对象。
[0056] 302、 在 Mock测试系统中配置固定的数据作为 Mock类对象的返回数据。
[0057] 可以理解, 实施这种返回数据构建方式, 在 Mock测试系统中, 每一个 Mock类 对象对应的都有一个固定的返回数据, 对于任意一个测试接口调用请求, 返回 的都是测试接口调用请求对应的 Mock类对象对应的固定的返回数据。
[0058] 303、 接收测试对象以目标通讯协议对应的目标通讯方式发送的测试接口调用 请求; 其中, 测试接口调用请求携带有目标 Mock类对象, 该目标 Mock类对象为 上述 Mock类对象中的任一个。
[0059] 304、 根据测试接口调用请求生成 Mock任务, 该 Mock任务用于指示访问测试接 口调用请求对应的目标 Mock类对象。
[0060] 305、 将 Mock任务分配至与该 Mock任务相匹配的第一执行节点, 以使该第一执 行节点在访问目标 Mock类对象后返回目标返回数据。
[0061] 本申请实施例中, 某一执行节点与某一 Mock任务相匹配, 具体为该执行节点 处理的任务类型与该 Mock任务的任务类型相匹配。 任务类型可以包括性能测试 类型和普通测试类型, 其中, 性能测试可以包括测试资源占用率、 任务处理时 长等, 普通测试可以包括测试代码逻辑。 通过将不同类型的 Mock任务分配至不 同类型的执行节点, 可以提高 Mock测试系统的通用性。
[0062] 本申请实施例中, 可以理解的是, 在实际的测试过程中, 可能同时存在多个测 试对象向 Mock测试系统发起测试接口调用请求, 然而, 传统的 Mock测试方法不 区分测试的任务类型, 因此, 只适用于针对单个应用进行测试, 而在多个测试 端需要同步进行测试时, 容易造成混乱。 而实施步骤 304以及步骤 305能够区分 测试的任务类型, 生成 Mock任务, 并将 Mock任务分配至 Mock任务相匹配的第 一执行节点以使第一执行节点访问测试接口调用请求对应的目标 Mock类对象, 可以提高 Mock测试系统的通用性。
[0063] 作为一种可选的实施方式, 在步骤 303之前, 该方法还可以包括, [0064] 在 Mock测试系统中设置性能测试执行节点和普通测试执行节点; 将性能测试 执行节点至少划分为资源占用率测试执行节点和任务处理时长测试执行节点; 以及, 将普通测试执行节点至少划分为代码逻辑测试节点和代码完整度测试节 点。
[0065] 步骤 305可以包括:
[0066] 获取 Mock任务的任务类型, 从 Mock测试系统中的执行节点中选取一个与该 Mo ck任务相匹配的执行节点作为第一执行节点; 将 Mock任务分配至第一执行节点 , 以使该第一执行节点在访问目标 Mock类对象后返回目标返回数据。
[0067] 可见, 实施本实施方式, Mock测试系统中的执行节点按照任务类型进行分类 , 并处理对应类型的 Mock任务, 能够避免由于多个测试对象同时向 Mock测试系 统发出测试接口调用请求而出现的混乱现象。
[0068] 作为一种可选的实施方式, 步骤 305可以包括:
[0069] 将 Mock任务分配至与该 Mock任务相匹配的第一执行节点; 在预设时长内检测 是否接收到第一执行节点返回的目标返回数据; 若否, 将 Mock任务分配至与该 Mock任务相匹配的第二执行节点, 以使该第二执行节点在访问目标 Mock类对象 后返回目标返回数据。
[0070] 可见, 实施本实施方式, 在将 Mock任务分配至与该 Mock任务相匹配的第一执 行节点后, 若在预设时长内未能接收到第一执行节点返回的目标返回数据, 将 M ock任务分配至第二执行节点, 能够防止由于第一执行节点故障等因素带来的测 试中断或延时的等影响测试的情况。
[0071] 306、 以上述目标通讯方式向测试对象返回目标返回数据以完成 Mock测试。
[0072] 作为一种可选的实施方式, 步骤 306可以包括:
[0073] 根据 Mock任务获取测试对象的身份标识; 根据该身份标识以上述目标通讯方 式向测试对象返回目标返回数据以完成 Mock测试。
[0074] 本实施方式中, 可以理解的是, 上述测试接口调用请求还可以包含测试对象的 身份标识, 依据测试接口调用请求生成的 Mock任务中包含该身份标识。 将 Mock 任务分配至与该 Mock任务相匹配的执行节点, 以使执行节点执行该 Mock任务生 成目标 Mock类对象的目标返回数据, 并根据测试对象的身份标识将目标 Mock类 对象的目标返回数据返回至对应的测试对象。 传统的 Mock测试方法除了不区分 测试的对象类型, 也不区分请求 Mock测试的请求方。 因此, 实施本实施方式, Mock测试系统还可以通过身份标识对多个测试对象进行区分, 从而进一步可以 提高 Mock测试系统的通用性。
[0075] 可见, 实施图 3所描述的方法, 通过测试接口文档在 Mock测试系统中创建 Mock 类对象, Mock类对象可以模拟外部环境系统, 其中测试接口文档中包括了测试 接口支持的通讯协议, 即 Mock测试系统支持的通讯协议不限于 HTTP, 从而, M ock测试系统能够支持多种通讯协议, 能够实现以目标通讯方式向测试对象返回 目标返回数据, 进而能够模拟各种测试场景, 使得软件测试更加方便; 此外, 根据测试接口调用请求生成 Mock任务, 并将 Mock任务分配至与该 Mock任务相 匹配的第一执行节点, 能够区分测试对象的类型, 能够避免在多个测试对象需 要同步进行测试时造成混乱; 此外, 能够防止由于第一执行节点故障等因素带 来的测试中断或延时的等影响测试的情况, 此外, 还可以通过身份标识对多个 测试对象进行区分, 从而进一步可以提高 Mock测试系统的通用性。
[0076] 实施例四
[0077] 请参阅图 4, 图 4是本申请实施例公开的又一种 Mock测试方法的流程示意图。
如图 4所示该 Mock测试方法可以包括以下步骤:
[0078] 401、 根据测试接口文档在 Mock测试系统中创建 Mock类对象, 该测试接口文 档至少包括测试请求参数、 返回参数、 测试接口支持的通讯协议以及该测试接 口对应的会话对象。
[0079] 402、 获取用户在 Web页面中输入的上述测试接口对应的返回数据生成代码, 并存储至 Mock测试系统的数据库。
[0080] 本申请实施例中, 实现了在 Web页面编译代码, 此外, 可以设定代码规范, 用 户写入代码时需要遵循该代码规范, 其中, 用户在 Web页面输入的返回数据生成 代码可以是 java代码, 也可以是 js代码等, 本申请实施例不作限定。
[0081] 403、 接收测试对象以目标通讯协议对应的目标通讯方式发送的测试接口调用 请求; 其中, 测试接口调用请求携带有目标 Mock类对象, 该目标 Mock类对象为 上述 Mock类对象中的任一个。 [0082] 404、 在调用测试接口调用请求对应的目标测试接口时, 从上述数据库中调取 目标测试接口对应的返回数据生成代码, 该目标测试接口为测试接口中的任一 个。
[0083] 405、 通过反射将目标测试接口对应的返回数据生成代码加载进 tomcat容器, 并 进行编译以获得成员类。
[0084] 本申请实施例中, tomcat容器可以编译返回数据生成代码, 并以获得成员类。
[0085] 406、 根据上述成员类获取目标返回数据, 并以目标通讯方式向测试对象返回 目标返回数据以完成 Mock测试。
[0086] 本申请实施例中, 利用 tomcat容器, 通过代码逻辑返回相应的目标返回数据。
[0087] 作为一种可选的实施方式, 在步骤 403之前, 还可以包括以下步骤:
[0088] 获取软件测试指标, 并确定每一项软件测试指标对应的预设达标数值以及每一 项软件测试指标对应的预设关联因素;
[0089] 在步骤 406之后, 还可以包括以下步骤:
[0090] 接收测试对象返回的测试结果, 该测试结果至少包括目标测试指标的测试数值 , 该目标测试指标为上述软件测试指标中的至少一项; 判断目标测试指标的测 试数值是否均大于目标测试指标的预设达标数值; 若否, 获取目标测试指标中 未达标的测试指标, 输出未达标的测试指标对应的预设关联因素。
[0091] 本实施方式中, 可以理解, 未达标的测试指标为目标测试指标中测试数值小于 预设达标数值的测试指标, 预设关联因素指会导致软件测试指标的测试数值发 生变化的因素, 可以理解为软件测试指标的数值的因变量。 可见, 实施本实施 方式, 能够在目标测试指标的测试数值不是均大于目标测试指标的预设达标数 值, 即软件测试结果不通过时, 输出未达标的测试指标对应的预设关联因素, 进而能够为开发人员提供如何优化该软件的参考信息。
[0092] 407、 将测试接口文档中的返回参数和通讯协议配置于 Web页面。
[0093] 408、 检测用户在 Web页面中输入的自定义返回参数和 /或自定义通讯协议。
[0094] 409、 根据自定义返回参数和 /或自定义通讯协议更新测试接口文档, 并根据更 新的测试接口文档更新 Mock类对象。
[0095] 本申请实施例中, 用户可以在 Web界面上输入的自定义返回参数和 /或自定义通 讯协议, 以修改返回参数和 /或通讯协议等信息, 而无需修改代码, 能够减少开 发者的工作量。
[0096] 可见, 实施图 4所描述的方法, 通过测试接口文档在 Mock测试系统中创建 Mock 类对象, Mock类对象可以模拟外部环境系统, 其中测试接口文档中包括了测试 接口支持的通讯协议, 即 Mock测试系统支持的通讯协议不限于 HTTP, 从而, M ock测试系统能够支持多种通讯协议, 能够实现以目标通讯方式向测试对象返回 目标返回数据, 进而能够模拟各种测试场景, 使得软件测试更加方便; 此外, 用户可以在 Web页面写返回数据生成代码, 在接收到测试接口调用请求时通过代 码逻辑返回相应的目标返回数据, 使得目标返回数据更符合测试需求; 此外, 用户可以在 Web界面上输入的自定义返回参数和 /或自定义通讯协议, 以修改返 回参数和 /或通讯协议等信息, 而无需修改代码, 能够减少开发者的工作量。
[0097] 实施例五
[0098] 请参阅图 5, 图 5是本申请实施例公开的一种 Mock测试系统的结构示意图。 如 图 5所示, 该 Mock测试系统可以包括: 创建单元 501、 生成单元 502、 接收单元 50 3以及返回单元 504, 其中,
[0099] 创建单元 501, 用于根据测试接口文档在 Mock测试系统中创建 Mock类对象, 该测试接口文档至少包括测试请求参数、 返回参数、 测试接口支持的通讯协议 以及该测试接口对应的会话对象;
[0100] 生成单元 502, 用于在 Mock测试系统中生成 Mock类对象的返回数据;
[0101] 接收单元 503 , 用于接收测试对象以目标通讯协议对应的目标通讯方式发送的 测试接口调用请求; 其中, 测试接口调用请求携带有目标 Mock类对象, 该目标 Mock类对象为 Mock类对象中的任一个;
[0102] 返回单元 504, 用于以目标通讯方式向测试对象返回目标返回数据以完成 Mock 测试, 该目标返回数据为目标 Mock类对象的返回数据。
[0103] 作为一种可选的实施方式, 返回单元 504用于以目标通讯方式向测试对象返回 目标返回数据以完成 Mock测试, 该目标返回数据为目标 Mock类对象的返回数据 的方式具体可以为:
[0104] 返回单元 504, 用于在接收到上述测试接口调用请求时, 根据目标 Mock类对象 模拟的系统对应的系统类型确定响应延时; 并在经过响应延时后以目标通讯方 式向测试对象返回目标返回数据以完成 Mock测试, 该目标返回数据为目标 Mock 类对象的返回数据。
[0105] 可见, 实施本实施方式, 模拟的测试环境能够更接近现实。
[0106] 可见, 实施图 5所描述的 Mock测试系统, 通过测试接口文档在 Mock测试系统中 创建 Mock类对象, Mock类对象可以模拟外部环境系统, 其中测试接口文档中包 括了测试接口支持的通讯协议, 即 Mock测试系统支持的通讯协议不限于 HTTP, 从而, Mock测试系统能够支持多种通讯协议, 能够实现以目标通讯方式向测试 对象返回目标返回数据, 进而能够模拟各种测试场景, 使得软件测试更加方便
[0107] 实施例六
[0108] 请参阅图 5, 图 5是本申请实施例公开的另一种 Mock测试系统的结构示意图。
实施例六所示的 Mock测试系统是由实施例五所示的 Mock测试系统进行优化得到 的。 与实施例五所示的 Mock测试系统相比较, 实施例六所示的 Mock测试系统中
[0109] 生成单元 502用于在 Mock测试系统中生成 Mock类对象的返回数据的方式具体可 以为:
[0110] 生成单元 502, 用于在 Mock测试系统中配置固定的数据作为 Mock类对象的返回 数据。
[0111] 返回单元 504用于以目标通讯方式向测试对象返回目标返回数据以完成 Mock测 试的方式具体为:
[0112] 返回单元 504, 用于根据测试接口调用请求生成 Mock任务, 该 Mock任务用于指 示访问测试接口调用请求对应的目标 Mock类对象; 将 Mock任务分配至与 Mock 任务相匹配的第一执行节点, 以使该第一执行节点在访问目标 Mock类对象后返 回目标返回数据; 以目标通讯方式向测试对象返回目标返回数据以完成 Mock测 试;
[0113] 作为一种可选的实施方式, 返回单元 504用于将 Mock任务分配至与 Mock任务相 匹配的第一执行节点, 以使该第一执行节点在访问目标 Mock类对象后返回目标 返回数据的方式具体可以为:
[0114] 返回单元 504, 用于将 Mock任务分配至与该 Mock任务相匹配的第一执行节点; 在预设时长内检测是否接收到第一执行节点返回的目标返回数据; 若否, 将 Moc k任务分配至与该 Mock任务相匹配的第二执行节点, 以使第二执行节点在访问目 标 Mock类对象后返回目标返回数据。
[0115] 可见, 实施本实施方式, 在将 Mock任务分配至与该 Mock任务相匹配的第一执 行节点后, 若在预设时长内未能接收到第一执行节点返回的目标返回数据, 将 M ock任务分配至第二执行节点, 能够防止由于第一执行节点故障等因素带来的测 试中断或延时的等影响测试的情况。
[0116] 作为一种可选的实施方式, 生成单元 502, 还用于在接收单元 503接收测试对象 以目标通讯协议对应的目标通讯方式发送的测试接口调用请求之前, 在 Mock测 试系统中设置性能测试执行节点和普通测试执行节点; 将性能测试执行节点至 少划分为资源占用率测试执行节点和任务处理时长测试执行节点; 以及, 将普 通测试执行节点至少划分为代码逻辑测试节点和代码完整度测试节点。
[0117] 返回单元 504用于将 Mock任务分配至与 Mock任务相匹配的第一执行节点, 以使 该第一执行节点在访问目标 Mock类对象后返回目标返回数据的方式具体可以为
[0118] 返回单元 504, 用于获取 Mock任务的任务类型, 从 Mock测试系统中的执行节点 中选取一个与该 Mock任务相匹配的执行节点作为第一执行节点; 将 Mock任务分 配至第一执行节点, 以使该第一执行节点在访问目标 Mock类对象后返回目标返 回数据。
[0119] 可见, 实施本实施方式, Mock测试系统中的执行节点按照任务类型进行分类 , 并处理对应类型的 Mock任务, 能够避免由于多个测试对象同时向 Mock测试系 统发出测试接口调用请求而出现的混乱现象。
[0120] 作为一种可选的实施方式, 返回单元 504用于以目标通讯方式向测试对象返回 目标返回数据以完成 Mock测试的方式具体可以为:
[0121] 返回单元 504, 用于根据 Mock任务获取测试对象的身份标识; 根据该身份标识 以目标通讯方式向测试对象返回目标返回数据以完成 Mock测试。 [0122] 本实施方式中, 可以理解的是, 上述测试接口调用请求还可以包含测试对象的 身份标识, 依据测试接口调用请求生成的 Mock任务中包含该身份标识。 将 Mock 任务分配至与该 Mock任务相匹配的执行节点, 以使执行节点执行该 Mock任务生 成目标 Mock类对象的目标返回数据, 并根据测试对象的身份标识将目标 Mock类 对象的目标返回数据返回至对应的测试对象。 传统的 Mock测试方法除了不区分 测试的对象类型, 也不区分请求 Mock测试的请求方。 因此, 实施本实施方式, Mock测试系统还可以通过身份标识对多个测试对象进行区分, 从而进一步可以 提高 Mock测试系统的通用性。
[0123] 可见, 实施例六所描述的 Mock测试系统, 通过测试接口文档在 Mock测试系统 中创建 Mock类对象, Mock类对象可以模拟外部环境系统, 其中测试接口文档中 包括了测试接口支持的通讯协议, 即 Mock测试系统支持的通讯协议不限于 HTTP , 从而, Mock测试系统能够支持多种通讯协议, 能够实现以目标通讯方式向测 试对象返回目标返回数据, 进而能够模拟各种测试场景, 使得软件测试更加方 便; 此外, 根据测试接口调用请求生成 Mock任务, 并将 Mock任务分配至与该 M ock任务相匹配的第一执行节点, 能够区分测试对象的类型, 能够避免在多个测 试对象需要同步进行测试时造成混乱; 此外, 能够防止由于第一执行节点故障 等因素带来的测试中断或延时的等影响测试的情况, 此外, 还可以通过身份标 识对多个测试对象进行区分, 从而进一步可以提高 Mock测试系统的通用性。
[0124] 实施例七
[0125] 请参阅图 6, 图 6是本申请实施例公开的又一种 Mock测试系统的结构示意图。
图 6所示的 Mock测试系统是由图 5所示的 Mock测试系统进行优化得到的。 与图 5 所示的 Mock测试系统相比较, 图 6所示的 Mock测试系统还可以包括: 配置单元 5 05、 检测单元 506以及更新单元 507, 其中,
[0126] 生成单元 502用于在 Mock测试系统中生成 Mock类对象的返回数据的方式具体可 以为:
[0127] 生成单元 502, 用于获取用户在 Web页面中输入的测试接口对应的返回数据生 成代码, 并存储至 Mock测试系统的数据库。
[0128] 返回单元 504用于以目标通讯方式向测试对象返回目标返回数据以完成 Mock测 试的方式具体为:
[0129] 返回单元 504, 用于在调用测试接口调用请求对应的目标测试接口时, 从数据 库中调取目标测试接口对应的返回数据生成代码, 该目标测试接口为测试接口 中的任一个; 通过反射将目标测试接口对应的返回数据生成代码加载进 tomcat容 器, 并进行编译以获得成员类; 根据该成员类获取目标返回数据, 并以目标通 讯方式向测试对象返回目标返回数据以完成 Mock测试。
[0130] 作为一种可选的实施方式, 生成单元 502, 还用于接收单元 503接收测试对象以 目标通讯协议对应的目标通讯方式发送的测试接口调用请求之前, 获取软件测 试指标, 并确定每一项软件测试指标对应的预设达标数值以及每一项软件测试 指标对应的预设关联因素;
[0131] 返回单元 504在用于以目标通讯方式向测试对象返回目标返回数据以完成 Mock 测试之后, 还可以用于接收测试对象返回的测试结果, 该测试结果至少目标测 试指标的测试数值, 该目标测试指标为上述软件测试指标中的至少一项; 判断 目标测试指标的测试数值是否均大于目标测试指标的预设达标数值; 若否, 获 取目标测试指标中未达标的测试指标, 输出未达标的测试指标对应的预设关联 因素。
[0132] 本实施方式中, 可以理解, 预设关联因素指会导致软件测试指标的测试数值发 生变化的因素, 可以理解为软件测试指标的数值的因变量。 可见, 实施本实施 方式, 能够在目标测试指标的测试数值不是均大于目标测试指标的预设达标数 值, 即软件测试结果不通过时, 输出未达标的测试指标对应的预设关联因素, 进而能够为开发人员提供如何优化该软件的参考信息。
[0133] 配置单元 505, 用于将测试接口文档中的返回参数和通讯协议配置于 Web页面
[0134] 检测单元 506, 用于检测用户在 Web页面中输入的自定义返回参数和 /或自定义 通讯协议;
[0135] 更新单元 507, 用于根据自定义返回参数和 /或自定义通讯协议更新测试接口文 档, 并根据更新的测试接口文档更新 Mock类对象。
[0136] 可见, 实施图 7所描述的 Mock测试系统, 通过测试接口文档在 Mock测试系统中 创建 Mock类对象, Mock类对象可以模拟外部环境系统, 其中测试接口文档中包 括了测试接口支持的通讯协议, 即 Mock测试系统支持的通讯协议不限于 HTTP, 从而, Mock测试系统能够支持多种通讯协议, 能够实现以目标通讯方式向测试 对象返回目标返回数据, 进而能够模拟各种测试场景, 使得软件测试更加方便 ; 此外, 用户可以在 Web页面写返回数据生成代码, 在接收到测试接口调用请求 时通过代码逻辑返回相应的目标返回数据, 使得目标返回数据更符合测试需求 ; 此外, 用户可以在 Web界面上输入的自定义返回参数和 /或自定义通讯协议, 以修改返回参数和 /或通讯协议等信息, 而无需修改代码, 能够减少开发者的工 作量。
[0137] 本申请还提供一种电子设备, 该电子设备包括:
[0138] 处理器;
[0139] 存储器, 该存储器上存储有计算机可读指令, 该计算机可读指令被处理器执行 时, 实现如前所示的 Mock测试方法。
[0140] 该电子设备可以是图 1所示装置 100。
[0141] 在一示例性实施例中, 本申请还提供一种计算机非易失性可读存储介质, 其上 存储有计算机程序, 该计算机程序被处理器执行时, 实现如前所示的 Mock测试 方法。
[0142] 在一示例性实施例中, 本申请还提供一种计算机程序产品, 所述计算机程序产 品包括存储了计算机程序的非瞬时性计算机可读存储介质, 所述计算机程序可 操作来使计算机执行如前所示的 Mock测试方法。 所述计算机程序产品包括程序 代码, 当所述程序产品在终端设备上运行时, 所述程序代码用于使所述终端设 备执行本说明书上述“示例性方法”部分中描述的根据本申请各种示例性实施方式 的步骤。
[0143] 应当理解的是, 本申请并不局限于上面已经描述并在附图中示出的精确结构, 并且可以在不脱离其范围执行各种修改和改变。 本申请的范围仅由所附的权利 要求来限制。

Claims

权利要求书
[权利要求 1] 一种 Mock测试方法, 所述方法包括:
根据测试接口文档在 Mock测试系统中创建 Mock类对象, 所述测试接 口文档至少包括测试请求参数、 返回参数、 测试接口支持的通讯协议 以及所述测试接口对应的会话对象;
在所述 Mock测试系统中生成所述 Mock类对象的返回数据; 接收测试对象以目标通讯协议对应的目标通讯方式发送的测试接口调 用请求; 其中, 所述测试接口调用请求携带有目标 Mock类对象, 所 述目标 Mock类对象为所述 Mock类对象中的任一个; 以所述目标通讯方式向所述测试对象返回目标返回数据以完成 Mock 测试, 所述目标返回数据为所述目标 Mock类对象的返回数据。
[权利要求 2] 根据权利要求 1所述的方法, 其中, 所述在所述 Mock测试系统中生成 所述 Mock类对象的返回数据, 包括:
在所述 Mock测试系统中配置固定的数据作为所述 Mock类对象的返回 数据。
[权利要求 3] 根据权利要求 1所述的方法, 其中, 所述在所述 Mock测试系统中生成 所述 Mock类对象的返回数据, 包括:
获取用户在 Web页面中输入的所述测试接口对应的返回数据生成代码 , 并存储至所述 Mock测试系统的数据库;
所述以所述目标通讯方式向所述测试对象返回目标返回数据以完成 M ock测试, 包括:
在调用所述测试接口调用请求对应的目标测试接口时, 从所述数据库 中调取所述目标测试接口对应的返回数据生成代码, 所述目标测试接 口为所述测试接口中的任一个;
通过反射将所述目标测试接口对应的返回数据生成代码加载进 tomcat 容器, 并进行编译以获得成员类;
根据所述成员类获取所述目标返回数据, 并以所述目标通讯方式向所 述测试对象返回所述目标返回数据以完成所述 Mock测试。
[权利要求 4] 根据权利要求 3所述的方法, 其中, 所述方法还包括: 将所述测试接口文档中的所述返回参数和所述通讯协议配置于所述 W eb页面;
检测所述用户在所述 Web页面中输入的自定义返回参数和 /或自定义 通讯协议;
根据所述自定义返回参数和 /或所述自定义通讯协议更新所述测试接 口文档, 并根据更新的测试接口文档更新所述 Mock类对象。
[权利要求 5] 根据权利要求 1或 2所述的方法, 其中, 所述以所述目标通讯方式向所 述测试对象返回目标返回数据以完成 Mock测试, 包括:
根据所述测试接口调用请求生成 Mock任务, 所述 Mock任务用于指示 访问所述测试接口调用请求对应的目标 Mock类对象;
将所述 Mock任务分配至与所述 Mock任务相匹配的第一执行节点, 以 使所述第一执行节点在访问所述目标 Mock类对象后返回所述目标返 回数据;
以所述目标通讯方式向所述测试对象返回所述目标返回数据以完成所 述 Mock测试。
[权利要求 6] 根据权利要求 5所述的方法, 其中, 所述以所述目标通讯方式向所述 测试对象返回所述目标返回数据以完成所述 Mock测试, 包括: 根据所述 Mock任务获取所述测试对象的身份标识; 根据所述身份标识以所述目标通讯方式向所述测试对象返回所述目标 返回数据以完成所述 Mock测试。
[权利要求 7] 根据权利要求 5或 6所述的方法, 其中, 所述将所述 Mock任务分配至 与所述 Mock任务相匹配的第一执行节点, 以使所述第一执行节点在 访问所述目标 Mock类对象后返回所述目标返回数据, 包括: 将所述 Mock任务分配至与所述 Mock任务相匹配的第一执行节点; 在预设时长内检测是否接收到所述第一执行节点返回的所述目标返回 数据;
若否, 将所述 Mock任务分配至与所述 Mock任务相匹配的第二执行节 点, 以使所述第二执行节点在访问所述目标 Mock类对象后返回所述 目标返回数据。
[权利要求 8] 一种 Mock测试系统, 所述系统包括:
创建单元, 用于根据测试接口文档在 Mock测试系统中创建 Mock类对 象, 所述测试接口文档至少包括测试请求参数、 返回参数、 测试接口 支持的通讯协议以及所述测试接口对应的会话对象;
生成单元, 用于在所述 Mock测试系统中生成所述 Mock类对象的返回 数据;
接收单元, 用于接收测试对象以目标通讯协议对应的目标通讯方式发 送的测试接口调用请求; 其中, 所述测试接口调用请求携带有目标 M ock类对象, 所述目标 Mock类对象为所述 Mock类对象中的任一个; 返回单元, 用于以所述目标通讯方式向所述测试对象返回目标返回数 据以完成 Mock测试, 所述目标返回数据为所述目标 Mock类对象的返 回数据。
[权利要求 9] 根据权利要求 8所述的系统, 所述生成单元被配置为:
在所述 Mock测试系统中配置固定的数据作为所述 Mock类对象的返回 数据。
[权利要求 10] 根据权利要求 8所述的系统, 所述生成单元被配置为:
获取用户在 Web页面中输入的所述测试接口对应的返回数据生成代码 , 并存储至所述 Mock测试系统的数据库;
所述返回单元被配置为:
在调用所述测试接口调用请求对应的目标测试接口时, 从所述数据库 中调取所述目标测试接口对应的返回数据生成代码, 所述目标测试接 口为所述测试接口中的任一个;
通过反射将所述目标测试接口对应的返回数据生成代码加载进 tomcat 容器, 并进行编译以获得成员类;
根据所述成员类获取所述目标返回数据, 并以所述目标通讯方式向所 述测试对象返回所述目标返回数据以完成所述 Mock测试。
[权利要求 11] 根据权利要求 10所述的系统, 还包括:
配置单元, 用于将所述测试接口文档中的所述返回参数和所述通讯协 议配置于所述 Web页面;
检测单元, 用于检测所述用户在所述 Web页面中输入的自定义返回参 数和 /或自定义通讯协议;
更新单元, 用于根据所述自定义返回参数和 /或所述自定义通讯协议 更新所述测试接口文档, 并根据更新的测试接口文档更新所述 Mock 类对象。
[权利要求 12] 根据权利要求 8或 9所述的系统, 所述返回单元被配置为:
根据所述测试接口调用请求生成 Mock任务, 所述 Mock任务用于指示 访问所述测试接口调用请求对应的目标 Mock类对象;
将所述 Mock任务分配至与所述 Mock任务相匹配的第一执行节点, 以 使所述第一执行节点在访问所述目标 Mock类对象后返回所述目标返 回数据;
以所述目标通讯方式向所述测试对象返回所述目标返回数据以完成所 述 Mock测试。
[权利要求 13] 根据权利要求 12所述的系统, 所述返回单元被配置为:
根据所述 Mock任务获取所述测试对象的身份标识; 根据所述身份标识以所述目标通讯方式向所述测试对象返回所述目标 返回数据以完成所述 Mock测试。
[权利要求 14] 根据权利要求 12或 13所述的系统, 所述返回单元被配置为:
将所述 Mock任务分配至与所述 Mock任务相匹配的第一执行节点; 在预设时长内检测是否接收到所述第一执行节点返回的所述目标返回 数据;
若否, 将所述 Mock任务分配至与所述 Mock任务相匹配的第二执行节 点, 以使所述第二执行节点在访问所述目标 Mock类对象后返回所述 目标返回数据。
[权利要求 15] 一种电子设备, 包括: 处理器; 以及存储器, 用于存储所述处理器的 Mock测试程序; 其中, 所述处理器配置为经由执行所述 Mock测试程 序来执行以下处理:
根据测试接口文档在 Mock测试系统中创建 Mock类对象, 所述测试接 口文档至少包括测试请求参数、 返回参数、 测试接口支持的通讯协议 以及所述测试接口对应的会话对象;
在所述 Mock测试系统中生成所述 Mock类对象的返回数据; 接收测试对象以目标通讯协议对应的目标通讯方式发送的测试接口调 用请求; 其中, 所述测试接口调用请求携带有目标 Mock类对象, 所 述目标 Mock类对象为所述 Mock类对象中的任一个; 以所述目标通讯方式向所述测试对象返回目标返回数据以完成 Mock 测试, 所述目标返回数据为所述目标 Mock类对象的返回数据。
[权利要求 16] 根据权利要求 15所述的电子设备, 其中, 所述在所述 Mock测试系统 中生成所述 Mock类对象的返回数据, 包括:
在所述 Mock测试系统中配置固定的数据作为所述 Mock类对象的返回 数据。
[权利要求 17] 根据权利要求 15所述的电子设备, 其中, 所述在所述 Mock测试系统 中生成所述 Mock类对象的返回数据, 包括:
获取用户在 Web页面中输入的所述测试接口对应的返回数据生成代码 , 并存储至所述 Mock测试系统的数据库;
所述以所述目标通讯方式向所述测试对象返回目标返回数据以完成 M ock测试, 包括:
在调用所述测试接口调用请求对应的目标测试接口时, 从所述数据库 中调取所述目标测试接口对应的返回数据生成代码, 所述目标测试接 口为所述测试接口中的任一个;
通过反射将所述目标测试接口对应的返回数据生成代码加载进 tomcat 容器, 并进行编译以获得成员类;
根据所述成员类获取所述目标返回数据, 并以所述目标通讯方式向所 述测试对象返回所述目标返回数据以完成所述 Mock测试。
[权利要求 18] 根据权利要求 17所述的电子设备, 其中, 还包括:
将所述测试接口文档中的所述返回参数和所述通讯协议配置于所述 W eb页面;
检测所述用户在所述 Web页面中输入的自定义返回参数和 /或自定义 通讯协议;
根据所述自定义返回参数和 /或所述自定义通讯协议更新所述测试接 口文档, 并根据更新的测试接口文档更新所述 Mock类对象。
[权利要求 19] 根据权利要求 15或 16所述的电子设备, 其中, 所述以所述目标通讯方 式向所述测试对象返回目标返回数据以完成 Mock测试, 包括: 根据所述测试接口调用请求生成 Mock任务, 所述 Mock任务用于指示 访问所述测试接口调用请求对应的目标 Mock类对象;
将所述 Mock任务分配至与所述 Mock任务相匹配的第一执行节点, 以 使所述第一执行节点在访问所述目标 Mock类对象后返回所述目标返 回数据;
以所述目标通讯方式向所述测试对象返回所述目标返回数据以完成所 述 Mock测试。
[权利要求 20] 根据权利要求 19所述的电子设备, 其中, 所述以所述目标通讯方式向 所述测试对象返回所述目标返回数据以完成所述 Mock测试, 包括: 根据所述 Mock任务获取所述测试对象的身份标识; 根据所述身份标识以所述目标通讯方式向所述测试对象返回所述目标 返回数据以完成所述 Mock测试。
[权利要求 21] 根据权利要求 19或 20所述的电子设备, 其中, 所述将所述 Mock任务 分配至与所述 Mock任务相匹配的第一执行节点, 以使所述第一执行 节点在访问所述目标 Mock类对象后返回所述目标返回数据, 包括: 将所述 Mock任务分配至与所述 Mock任务相匹配的第一执行节点; 在预设时长内检测是否接收到所述第一执行节点返回的所述目标返回 数据;
若否, 将所述 Mock任务分配至与所述 Mock任务相匹配的第二执行节 点, 以使所述第二执行节点在访问所述目标 Mock类对象后返回所述 目标返回数据。
[权利要求 22] —种计算机非易失性可读存储介质, 其上存储有 Mock测试程序, 所 述 Mock测试程序被处理器执行时实现以下处理: 根据测试接口文档在 Mock测试系统中创建 Mock类对象, 所述测试接 口文档至少包括测试请求参数、 返回参数、 测试接口支持的通讯协议 以及所述测试接口对应的会话对象
在所述 Mock测试系统中生成所述 Mock类对象的返回数据; 接收测试对象以目标通讯协议对应的目标通讯方式发送的测试接口调 用请求; 其中, 所述测试接口调用请求携带有目标 Mock类对象, 所 述目标 Mock类对象为所述 Mock类对象中的任一个;
以所述目标通讯方式向所述测试对象返回目标返回数据以完成 Mock 测试, 所述目标返回数据为所述目标 Mock类对象的返回数据。
PCT/CN2019/118066 2019-04-19 2019-11-13 Mock测试方法、系统、电子设备及计算机非易失性可读存储介质 WO2020211360A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910318274.8A CN110162464A (zh) 2019-04-19 2019-04-19 Mcok测试方法及系统、电子设备及可读存储介质
CN201910318274.8 2019-04-19

Publications (1)

Publication Number Publication Date
WO2020211360A1 true WO2020211360A1 (zh) 2020-10-22

Family

ID=67639869

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/118066 WO2020211360A1 (zh) 2019-04-19 2019-11-13 Mock测试方法、系统、电子设备及计算机非易失性可读存储介质

Country Status (2)

Country Link
CN (1) CN110162464A (zh)
WO (1) WO2020211360A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113791971A (zh) * 2021-08-13 2021-12-14 唯品会(广州)软件有限公司 一种Mock测试方法、装置、设备及计算机可读介质

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110162464A (zh) * 2019-04-19 2019-08-23 平安普惠企业管理有限公司 Mcok测试方法及系统、电子设备及可读存储介质
CN112181824A (zh) * 2020-09-25 2021-01-05 中国建设银行股份有限公司 系统开发辅助平台及方法
CN112383434B (zh) * 2020-11-17 2023-08-08 Oppo广东移动通信有限公司 网络请求的接口模拟方法、装置、电子设备和存储介质
CN112905432A (zh) * 2021-03-09 2021-06-04 北京大米科技有限公司 性能测试方法、装置、存储介质及终端
CN116166569A (zh) * 2023-04-26 2023-05-26 深圳市和讯华谷信息技术有限公司 一种Mock测试方法及其相关设备

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106528400A (zh) * 2016-09-22 2017-03-22 深圳峰创智诚科技有限公司 Mock测试方法和装置
CN107179984A (zh) * 2016-03-10 2017-09-19 北京京东尚科信息技术有限公司 一种接口mock方法及接口测试方法
CN108427644A (zh) * 2018-03-27 2018-08-21 深圳市买买提信息科技有限公司 服务测试方法、服务测试系统及服务测试装置
CN109522218A (zh) * 2018-10-19 2019-03-26 平安科技(深圳)有限公司 接口测试方法、装置、计算机设备和存储介质
CN110162464A (zh) * 2019-04-19 2019-08-23 平安普惠企业管理有限公司 Mcok测试方法及系统、电子设备及可读存储介质

Family Cites Families (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101576848A (zh) * 2008-05-09 2009-11-11 北京世纪拓远软件科技发展有限公司 模拟系统
CN105302721B (zh) * 2015-10-29 2018-06-19 普元信息技术股份有限公司 云计算平台中实现集中模拟服务器集成测试的系统及方法
CN106802859A (zh) * 2015-11-25 2017-06-06 北京京东尚科信息技术有限公司 一种客户端软件测试的方法及装置
CN107133160B (zh) * 2016-02-26 2020-06-30 北京京东尚科信息技术有限公司 服务器和客户端
CN107291612B (zh) * 2016-04-13 2021-01-05 创新先进技术有限公司 一种测试的方法及装置
CN107122292A (zh) * 2016-10-21 2017-09-01 北京小度信息科技有限公司 一种模拟服务的方法及系统
CN106802865B (zh) * 2017-01-17 2019-10-11 中国工商银行股份有限公司 用于软件测试的应答模拟装置及方法
CN109299010A (zh) * 2018-09-25 2019-02-01 深圳壹账通智能科技有限公司 mock测试方法、装置、计算机设备和存储介质

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107179984A (zh) * 2016-03-10 2017-09-19 北京京东尚科信息技术有限公司 一种接口mock方法及接口测试方法
CN106528400A (zh) * 2016-09-22 2017-03-22 深圳峰创智诚科技有限公司 Mock测试方法和装置
CN108427644A (zh) * 2018-03-27 2018-08-21 深圳市买买提信息科技有限公司 服务测试方法、服务测试系统及服务测试装置
CN109522218A (zh) * 2018-10-19 2019-03-26 平安科技(深圳)有限公司 接口测试方法、装置、计算机设备和存储介质
CN110162464A (zh) * 2019-04-19 2019-08-23 平安普惠企业管理有限公司 Mcok测试方法及系统、电子设备及可读存储介质

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113791971A (zh) * 2021-08-13 2021-12-14 唯品会(广州)软件有限公司 一种Mock测试方法、装置、设备及计算机可读介质

Also Published As

Publication number Publication date
CN110162464A (zh) 2019-08-23

Similar Documents

Publication Publication Date Title
WO2020211360A1 (zh) Mock测试方法、系统、电子设备及计算机非易失性可读存储介质
US20190236000A1 (en) Distributed system test device
CN110765024B (zh) 模拟测试方法、装置、电子设备和计算机可读存储介质
CN110489101A (zh) 接口模拟方法、系统、介质和电子设备
CN109359118B (zh) 一种数据写入方法及装置
CN107807841B (zh) 服务器模拟方法、装置、设备及可读存储介质
CN109815119A (zh) 一种app链接渠道的测试方法及装置
CN111399840A (zh) 一种模块开发方法及装置
CN111158465A (zh) 一种力触觉振动反馈方法及系统
KR20180061589A (ko) 소프트웨어 빌드 시스템 및 이를 이용한 소프트웨어 빌드 방법
US9582270B2 (en) Effective feature location in large legacy systems
CN112346965A (zh) 测试用例分配方法、装置及存储介质
CN107102937B (zh) 一种用户界面测试方法和装置
CN115996179A (zh) 业务节点的测试方法、装置、可读介质和电子设备
CN113778878A (zh) 接口测试方法、装置、电子设备及存储介质
CN111159033B (zh) 一种软件测试方法及装置
US10176062B2 (en) Cloud servers and methods for handling dysfunctional cloud services
CN109840109B (zh) 用于生成软件开发工具包的方法和装置
CN111414154A (zh) 前端开发的方法、装置、电子设备和存储介质
CN111026651A (zh) 测试方法、装置、存储介质及电子设备
CN111813407B (zh) 游戏开发方法、游戏运行方法、装置和电子设备
CN115407981A (zh) 一种基于中间件适配的前端数据mock方法及系统
CN113961194A (zh) 基于Flutter跨应用的工程构建方法、系统、终端及介质
CN113110846A (zh) 一种环境变量的获取方法及装置
CN112506781A (zh) 测试监控方法、装置、电子设备、存储介质及程序产品

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 19925031

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205 DATED 03/02/2022)

122 Ep: pct application non-entry in european phase

Ref document number: 19925031

Country of ref document: EP

Kind code of ref document: A1