Method, apparatus, and device for testing consumer objects
By obtaining and assigning target parameters, the problem of the Dubbo framework's inability to handle consumer annotations was solved, enabling successful unit testing of consumer objects.
Patent Information
- Application Number
- CN202210109445.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-28
- Publication Date
- 2025-10-21
- Estimated Expiration
- 2042-01-28
AI Technical Summary
In distributed systems based on the Spring Boot and Dubbo frameworks, when unit testing consumer objects, it is necessary to create mock objects to replace service objects. However, the Dubbo framework cannot handle annotations set in the consumer, causing calls to the mock objects to fail.
By obtaining the target parameters corresponding to the consumer object and the service object, assigning the values of the simulated object to the target parameters, and using the assigned target parameters to complete the test, the Spring framework can ensure that it can handle the annotations of the consumer.
This demonstrates how to successfully invoke a mock object and complete unit tests on the consumer object without relying on the Dubbo framework.
Smart Images

Figure CN114490398B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to unit testing technology, and more particularly to a method, apparatus, and device for testing consumer objects. Background Art
[0002] Currently, after code is written, it is typically tested using unit testing. Unit testing is a testing method that examines and verifies the smallest testable unit in the software. Unit testing can help quickly identify defects in the program, improving coding efficiency and program robustness.
[0003] When performing unit testing, you can test each object as a unit. In addition, during the testing process, you usually use the return values of other objects to test the target object. To facilitate testing, you usually create mock objects to replace other objects that are unrelated to the target object.
[0004] Currently, some system architectures include consumers and servers, where consumers can call functions provided by the servers. For example, in a distributed system developed using Spring Boot, where consumers use the Dubbo framework to remotely call servers, objects are defined and annotated on the consumer side. When the consumer uses Dubbo to make a remote service call to the server, the Dubbo framework processes the annotated object and returns the data to the consumer.
[0005] However, if you unit test the consumer side of this system, you need to create a mock object to replace the server object, and have the mock object return data directly to the consumer. In this case, when the consumer calls the server object, it will call the mock object, shielding the Dubbo framework. Therefore, the Spring framework needs to process the annotations set on the consumer side. However, this annotation is only recognized by the Dubbo framework and not the Spring framework, which leads to the failure of calling the mock object. Summary of the Invention
[0006] The present disclosure provides a method, apparatus, and device for testing consumer objects to address the problem in the prior art where, when unit testing the consumer of a system, a mock object needs to be created to replace the server object, with the mock object returning data directly to the consumer. In this case, when the consumer calls the server object, the mock object is called, shielding the Dubbo framework. Therefore, the Spring framework needs to process the annotations set in the consumer. However, these annotations can only be recognized by the Dubbo framework and not by the Spring framework, which leads to a failure in calling the mock object.
[0007] According to a first aspect of the present disclosure, a method for testing a consumer object is provided, wherein the consumer object is developed based on Spring and the consumer object uses the Dubbo framework to call a service object;
[0008] The method comprises:
[0009] Obtain information about a consumer object to be tested, information about a service object called by the consumer object, and information about a simulation object used to simulate the service object;
[0010] According to the information of the consumer object and the information of the service object called by the consumer object, obtaining the target parameters corresponding to the consumer object and the service object;
[0011] assigning the value of the simulation object to the target parameter according to the information of the simulation object;
[0012] The consumer object is run according to the target parameters to obtain an operation result, the operation result is compared with a preset accurate result, and a test result of the consumer object is determined based on the comparison result.
[0013] In an implementable manner, the information of the consumer object includes the name of the consumer object; the information of the service object includes the name of the service object called by the consumer object;
[0014] The acquiring target parameters corresponding to the consumer object and the server object according to the information of the consumer object and the information of the server object called by the consumer object includes:
[0015] According to the name of the consumer object, obtain the proxy object of the consumer object from the preset object pool;
[0016] Obtain the consumer object according to the proxy object of the consumer object;
[0017] According to the name of the server object, a target parameter corresponding to the server object is obtained from multiple parameters of the consumer object.
[0018] In one implementable manner, before obtaining information of a consumer object to be tested, information of a service object called by the consumer object, and information of a simulation object for simulating the service object, the method further includes:
[0019] In response to the object creation instruction, create the simulation object for simulating the service object;
[0020] In response to the assignment instruction, a value is assigned to the simulation object.
[0021] In one implementable manner, the creating the simulation object for simulating the service object includes:
[0022] Get the name of the service object called by the consumer object;
[0023] A simulation object is created according to the name of the service object, where the name of the simulation object is the same as the name of the service object.
[0024] In one implementable manner, assigning the value of the simulation object to the target parameter according to the information of the simulation object includes:
[0025] Setting the access permission of the target parameter to be accessible;
[0026] Set the value of the simulation object to the value of the target parameter of the consumer object.
[0027] According to a second aspect of the present disclosure, a device for testing a consumer object is provided, wherein the consumer object is developed based on Spring and uses the Dubbo framework to call a service object;
[0028] The device comprises:
[0029] An information acquisition unit, configured to acquire information about a consumer object to be tested, information about a service object called by the consumer object, and information about a simulation object used to simulate the service object;
[0030] a target parameter acquiring unit, configured to acquire target parameters corresponding to the consumer object and the service object according to information of the consumer object and information of the service object called by the consumer object;
[0031] an assignment unit, configured to assign the value of the simulation object to the target parameter according to the information of the simulation object;
[0032] A testing unit is used to run the consumer object according to the target parameters, obtain an operation result, compare the operation result with a preset accurate result, and determine a test result of the consumer object based on the comparison result.
[0033] In an implementable manner, the information of the consumer object includes the name of the consumer object; the information of the service object includes the name of the service object called by the consumer object;
[0034] The target parameter acquisition unit includes:
[0035] A proxy object acquisition module, configured to acquire a proxy object of a consumer object from a preset object pool according to the name of the consumer object;
[0036] A consumer object acquisition module, configured to acquire the consumer object according to the proxy object of the consumer object;
[0037] The target parameter acquisition module is used to acquire the target parameter corresponding to the service object from the multiple parameters of the consumer object according to the name of the service object.
[0038] According to a third aspect of the present disclosure, an electronic device is provided, comprising a memory and a processor; wherein,
[0039] The memory is used to store computer programs;
[0040] The processor is configured to read the computer program stored in the memory and execute the method for testing a consumer object as described in the first aspect according to the computer program in the memory.
[0041] According to a fourth aspect of the present disclosure, a computer-readable storage medium is provided, in which computer-executable instructions are stored. When a processor executes the computer-executable instructions, the method for testing a consumer object as described in the first aspect is implemented.
[0042] According to a fifth aspect of the present disclosure, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the method for testing a consumer object as described in the first aspect.
[0043] The method, device, and equipment for testing consumer objects provided by the present disclosure include: obtaining information about the consumer object to be tested, information about the service object called by the consumer object, and information about the simulation object used to simulate the service object; obtaining target parameters corresponding to the consumer object and the service object based on the information about the consumer object and the service object called by the consumer object; assigning the value of the simulation object to the target parameter based on the information about the simulation object; running the consumer object according to the target parameter to obtain the running result, comparing the running result with the preset accurate result, and determining the test result of the consumer object based on the comparison result. In the method, device, and equipment for testing consumer objects provided by this solution, according to the information about the consumer object and the service object called by the consumer object, the target parameters corresponding to the consumer object and the service object are obtained, the value of the simulation object is assigned to the target parameter, and the test is completed using the assigned target parameter. This allows the annotations set in the consumer to be processed without relying on the Dubbo framework, and the simulation object can be successfully called to complete the test. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Figure 1 A flowchart of a method for testing a consumer object according to an exemplary embodiment of the present disclosure is shown;
[0045] Figure 2 A flowchart of a method for testing a consumer object according to another exemplary embodiment of the present disclosure is shown;
[0046] Figure 3 A schematic diagram of a process of calling a simulation object according to an exemplary embodiment of the present disclosure;
[0047] Figure 4 This is a structural diagram of an apparatus for testing a consumer object according to an exemplary embodiment of the present disclosure;
[0048] Figure 5 This is a structural diagram of an apparatus for testing a consumer object according to another exemplary embodiment of the present disclosure;
[0049] Figure 6 This is a structural diagram of an electronic device according to an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION
[0050] Currently, after code is written, it is typically tested using unit testing. Unit testing is a testing method that examines and verifies the smallest testable unit in software. Unit testing can help quickly identify defects in programs, improving coding efficiency and program robustness. Unit testing can be performed on an object-by-object basis. Furthermore, during testing, the target object is often tested using the return values of other objects. To facilitate testing, mock objects are often created to replace unrelated objects. Currently, some system architectures include consumers and servers, where consumers can call functionality provided by the server. For example, a distributed system developed using Spring Boot and where consumers use the Dubbo framework to remotely call services from the server, may define and annotate objects in the consumer. When the consumer uses the Dubbo framework to make a remote service call to the server, the Dubbo framework processes the annotated object and returns the data to the consumer.
[0051] However, if you unit test the consumer side of this system, you need to create a mock object to replace the server object, and have the mock object return data directly to the consumer. In this case, when the consumer calls the server object, it will call the mock object, shielding the Dubbo framework. Therefore, the Spring framework needs to process the annotations set on the consumer side. However, this annotation is only recognized by the Dubbo framework and not the Spring framework, which leads to the failure of calling the mock object.
[0052] To address the aforementioned technical issues, the solution provided by this disclosure obtains the target parameters corresponding to the consumer and service objects based on information about the consumer object and the service object it calls. The target parameters are then assigned the values of the mock objects, and the test is completed using the assigned target parameters. This allows annotations set in the consumer to be processed without relying on the Dubbo framework, enabling the mock objects to be successfully called and the test to be completed.
[0053] Figure 1 The flowchart of a method for testing a consumer object according to an exemplary embodiment of the present disclosure is shown in FIG. The consumer object is developed based on Spring and uses the Dubbo framework to call a service object.
[0054] Among them, Spring is an open source application framework on the Java platform, providing a container with inversion of control features. Among them, Java is an object-oriented programming language.
[0055] Among them, Spring Boot is an extension of the Spring framework and integrates a unit testing framework.
[0056] Unit testing refers to checking and verifying the smallest testable unit of software. In the solution provided by the present disclosure, the smallest testable unit refers to a Java method.
[0057] Dubbo is a distributed service framework dedicated to providing high-performance and transparent remote procedure call (RPC) solutions. The solution provided in this disclosure divides the system into consumers and servers based on the Dubbo framework, and uses a registration center within the Dubbo framework to process service calls from consumers to servers.
[0058] The distributed system is a collection of several independent computers, which is like accessing a single computer to the user. The distributed system in the solution provided by the present disclosure can deploy the consumer and the service provider on different servers.
[0059] like Figure 1As shown, the method for testing a consumer object provided in this embodiment includes:
[0060] Step 101 : Obtain information about a consumer object to be tested, information about a server object called by the consumer object, and information about a simulation object used to simulate the server object.
[0061] The method provided in the present disclosure can be performed by an electronic device with computing capabilities, such as a computer, etc. The electronic device can obtain information about the consumer object to be tested, information about the service object called by the consumer object, and information about the simulation object used to simulate the service object.
[0062] Specifically, consumer objects differ from service objects in that consumer objects often need to invoke services from service objects. For example, a shopping app that provides payment services often requires payment information from a banking app. In this case, the shopping app can be the consumer object, and the banking app can be the service object.
[0063] During unit testing, the service object that the consumer object needs to call will not give feedback to the consumer object, so a mock object needs to be created in advance to simulate the service object in order to complete the test.
[0064] Among them, the information of the consumer object to be tested may include the name of the consumer object to be tested, the code corresponding to the consumer object to be tested and other information; the information of the service object called by the consumer object may include the name of the service object and other information; the information of the simulation object used to simulate the service object may include the name of the simulation object, the code of the simulation object and other information.
[0065] Step 102: Obtain target parameters corresponding to the consumer object and the server object according to the information of the consumer object and the information of the server object called by the consumer object.
[0066] The target parameter may be an attribute in the consumer object, and the target parameter corresponds to the service object.
[0067] Specifically, the information of the consumer object may include the name of the consumer object, and the information of the service object called by the consumer object may include the name of the service object, wherein the name of the service object is the same as the name of the target parameter.
[0068] Specifically, the consumer object can be obtained from a preset object pool according to the name of the consumer object; and then the target parameters can be obtained from the consumer object according to the name of the service object called by the consumer.
[0069] Step 103: assign the value of the simulation object to the target parameter according to the information of the simulation object.
[0070] The information of the simulation object may include the value of the simulation object and the name of the simulation object.
[0071] Specifically, a simulation object may be created in advance and a value may be assigned to the simulation object.
[0072] The name of the mock object is the same as the name of the target object.
[0073] Specifically, the value of the simulation object having the same name as the target parameter may be assigned to the target parameter.
[0074] Step 104 , running the consumer object according to the target parameters, obtaining an operation result, comparing the operation result with a preset accurate result, and determining a test result of the consumer object based on the comparison result.
[0075] Specifically, the consumer object can be tested based on the assigned target parameters.
[0076] Specifically, the consumer object can be run according to the assigned target parameters to obtain a run result. The run result is compared with a preset accurate result to obtain a comparison result. The test result of the consumer object is then determined based on the comparison result.
[0077] Among them, the preset accurate result is pre-set according to the actual situation, and the accurate running result will be obtained when the consumer object is run.
[0078] The method for testing a consumer object provided by the present disclosure includes: obtaining information about the consumer object to be tested, information about the service object called by the consumer object, and information about the simulation object used to simulate the service object; obtaining target parameters corresponding to the consumer object and the service object based on the information about the consumer object and the service object called by the consumer object; assigning the value of the simulation object to the target parameter based on the information about the simulation object; running the consumer object according to the target parameter to obtain the running result, comparing the running result with the preset accurate result, and determining the test result of the consumer object based on the comparison result. In the method adopted by the present disclosure, according to the information about the consumer object and the service object called by the consumer object, the target parameters corresponding to the consumer object and the service object are obtained, the value of the simulation object is assigned to the target parameter, and the test is completed using the assigned target parameter. This allows the annotations set in the consumer to be processed without relying on the Dubbo framework, and the simulation object can be successfully called to complete the test.
[0079] Figure 2This is a flow chart of a method for testing a consumer object according to another exemplary embodiment of the present disclosure, wherein the consumer object is developed based on Spring and uses the Dubbo framework to call the service object.
[0080] like Figure 2 As shown, the method for testing a consumer object provided in this embodiment includes:
[0081] Step 201: In response to an object creation instruction, a simulation object for simulating a service object is created.
[0082] Specifically, during unit testing, the service object that the consumer object needs to call will not give feedback to the consumer object, so a mock object needs to be created in advance to simulate the service object in order to complete the test.
[0083] Specifically, it responds to the object creation instruction and can create a simulation object for simulating the service object according to the object creation instruction.
[0084] In one achievable manner, obtaining the name of the service object called by the consumer object;
[0085] Create a mock object based on the name of the servant object. The name of the mock object is the same as the name of the servant object.
[0086] The object creation instruction may include the name of the service object called by the consumer object. The name of the service object called by the consumer object may be obtained based on the object creation instruction. Then, a simulation object is created so that the name of the simulation object is the same as the name of the service object.
[0087] Step 202: respond to the assignment instruction and assign a value to the simulation object.
[0088] Specifically, a value may be determined according to actual conditions and assigned to the simulation object.
[0089] Step 203: Obtain information about the consumer object to be tested, information about the server object called by the consumer object, and information about the simulation object used to simulate the server object.
[0090] Specifically, the principle and implementation of step 203 are similar to those of step 101 and will not be described in detail.
[0091] Step 204: The information of the consumer object includes the name of the consumer object; the information of the service object includes the name of the service object called by the consumer object; and according to the name of the consumer object, a proxy object of the consumer object is obtained from a preset object pool.
[0092] The preset object pool is a pre-set object pool, which may include software code (including proxy objects of consumer objects) and test code for testing the software.
[0093] Specifically, the object pool stores proxy objects for consumer objects wrapped by the Spring Boot framework. You can retrieve the proxy object for the consumer object from the preset object pool based on the name of the consumer object.
[0094] Alternatively, you can use the getBean() method to retrieve an object proxy for the consumer object named by the consumer object from the local Spring IoC container. However, the object obtained by the getBean() method has been wrapped by the Spring Boot framework, so this method is the only way to get the dynamic proxy object of the consumer.
[0095] Step 205: Obtain the consumer object according to the proxy object of the consumer object.
[0096] Specifically, the proxy object of the consumer object can be removed from the Spring Boot framework packaging to obtain the consumer object.
[0097] Optionally, you can use the getTarge() method to obtain the consumer object. Proxy types are categorized as cglib proxies and jdk dynamic proxies. getTarge() uses different methods to obtain the consumer object depending on the proxy type.
[0098] Step 206 : According to the name of the server object, obtain the target parameter corresponding to the server object from the multiple parameters of the consumer object.
[0099] Specifically, the consumer object may include multiple parameters, wherein the parameter with the same name as the server object is the target parameter.
[0100] Specifically, the target parameters can be obtained from the consumer object according to the name of the service object called by the consumer.
[0101] Optionally, you can use the getDeclaredField() method based on reflection to retrieve a property named after the server object in the class corresponding to the consumer object. This property is the target parameter. Properties are components of a class, also known as member variables. Class instances are objects.
[0102] Reflection refers to the process of dynamically loading classes and obtaining detailed information about them during program execution, allowing you to manipulate the properties and methods of a class or object. Essentially, the JVM decompiles a class object after obtaining it, thereby obtaining various information about the object.
[0103] Step 207: Set the access permission of the target parameter to be accessible.
[0104] Optionally, you can change the access rights of the target parameter to accessible through the field.setAccessible(True) method based on the reflection mechanism.
[0105] Step 208: Set the value of the simulation object to the value of the target parameter of the consumer object.
[0106] Specifically, the mock object is injected into the consumer object. Specifically, the consumer class calls the server's service through the server's object. Therefore, the consumer class needs to declare a server object. If a server object b is defined in consumer class A, then b is an attribute of A. The mock object c simulates the server object b and is assigned a value during the simulation. Assigning the mock object c with data to b is called injecting a property, which can also be understood as injecting the mock object into the consumer object.
[0107] Step 209 , running the consumer object according to the target parameters, obtaining the running result, comparing the running result with the preset accurate result, and determining the test result of the consumer object according to the comparison result.
[0108] Specifically, the principle and implementation of step 209 are similar to those of step 104 and will not be described in detail.
[0109] Figure 3 This is a schematic diagram of the process of calling a simulation object according to an exemplary embodiment of the present disclosure.
[0110] like Figure 3 As shown, the object proxy of the consumer object named by the name of the consumer object can be obtained from the local Spring IoC container using the getBean() method according to the name of the consumer object.
[0111] Then, the consumer object is obtained according to the object proxy and getTarge() method of the consumer object.
[0112] Then, according to the reflection mechanism, the attribute named as the name of the service object in the class corresponding to the consumer object can be obtained through the getDeclaredField() method, that is, the target parameter.
[0113] Then, based on the reflection mechanism, you can change the access rights of the target parameter to accessible through the field.setAccessible(True) method. Set the value of the mock object to the value of the target parameter of the consumer object.
[0114] Figure 4 This is a structural diagram of an apparatus for testing a consumer object according to an exemplary embodiment of the present disclosure, wherein the consumer object is developed based on Spring and uses the Dubbo framework to call the service object.
[0115] like Figure 4 As shown, the present disclosure provides an apparatus 400 for testing a consumer object, the apparatus comprising:
[0116] An information acquisition unit 410 is used to acquire information about the consumer object to be tested, information about the service object called by the consumer object, and information about the simulation object used to simulate the service object;
[0117] The target parameter acquisition unit 420 is used to acquire target parameters corresponding to the consumer object and the server object according to the information of the consumer object and the information of the server object called by the consumer object;
[0118] an assignment unit 430 for assigning the value of the simulation object to the target parameter according to the information of the simulation object;
[0119] The testing unit 440 is used to run the consumer object according to the target parameters, obtain the running result, compare the running result with the preset accurate result, and determine the test result of the consumer object according to the comparison result.
[0120] Figure 5 This is a structural diagram of an apparatus for testing a consumer object according to another exemplary embodiment of the present disclosure, wherein the consumer object is developed based on Spring and uses the Dubbo framework to call the service object.
[0121] like Figure 5 As shown, based on the above embodiment, in the apparatus 500 for testing a consumer object provided by the present disclosure, the target parameter acquisition unit 420 further includes:
[0122] The proxy object acquisition module 421 is used to obtain the proxy object of the consumer object from a preset object pool according to the name of the consumer object;
[0123] The consumer object acquisition module 422 is used to acquire the consumer object according to the proxy object of the consumer object;
[0124] The target parameter acquisition module 423 is used to acquire the target parameter corresponding to the service object from the multiple parameters of the consumer object according to the name of the service object;
[0125] The information of the consumer object includes the name of the consumer object; the information of the server object includes the name of the server object called by the consumer object.
[0126] Before obtaining the information of the consumer object to be tested, the information of the service object called by the consumer object, and the information of the simulation object used to simulate the service object, it also includes: a simulation object creation unit 450, which is used to respond to the object creation instruction to create a simulation object used to simulate the service object; and respond to the assignment instruction to assign a value to the simulation object.
[0127] The simulation object creation unit 450 is specifically used to obtain the name of the service object called by the consumer object;
[0128] Create a mock object based on the name of the servant object. The name of the mock object is the same as the name of the servant object.
[0129] The assignment unit 430 is specifically configured to set the access permission of the target parameter to be accessible;
[0130] Sets the value of the consumer object's target parameter to the value of the mock object.
[0131] Figure 6 This is a structural diagram of an electronic device according to an exemplary embodiment of the present disclosure.
[0132] like Figure 6 As shown, the electronic device provided in this embodiment includes:
[0133] Memory 601;
[0134] Processor 602; and
[0135] computer programs;
[0136] The computer program is stored in the memory 601 and is configured to be executed by the processor 602 to implement any of the above methods for testing a consumer object.
[0137] This embodiment further provides a computer-readable storage medium having a computer program stored thereon. The computer program is executed by a processor to implement any of the above methods for testing a consumer object.
[0138] This embodiment further provides a computer program product, including a computer program. When the computer program is executed by a processor, it implements any of the above methods for testing a consumer object.
[0139] Those skilled in the art will appreciate that all or part of the steps in the above-described method embodiments can be implemented using hardware associated with program instructions. The aforementioned program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.
[0140] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for testing a consumer object, characterized in that: The consumer object is developed based on Spring, and the consumer object uses the Dubbo framework to call the service object; The method comprises: Obtain information about a consumer object to be tested, information about a service object called by the consumer object, and information about a simulation object used to simulate the service object, wherein the information about the consumer object includes the name of the consumer object; the information about the service object includes the name of the service object called by the consumer object; According to the information of the consumer object and the information of the service object called by the consumer object, the target parameters corresponding to the consumer object and the service object are obtained through the reflection mechanism, wherein the target parameters include attribute fields in the consumer object related to the service object call and access permission information thereof; According to the information of the simulation object, assigning the value of the simulation object to the target parameter through a reflection mechanism; Running the consumer object according to the target parameters to obtain an operation result, comparing the operation result with a preset accurate result, and determining a test result of the consumer object based on the comparison result; The acquiring target parameters corresponding to the consumer object and the server object through a reflection mechanism according to the information of the consumer object and the information of the server object called by the consumer object includes: According to the name of the consumer object, obtain the proxy object of the consumer object from the preset object pool; Obtain the consumer object according to the proxy object of the consumer object; According to the name of the server object, a target parameter corresponding to the server object is obtained from multiple parameters of the consumer object.
2. The method according to claim 1, characterized in that Before obtaining information of the consumer object to be tested, information of the service object called by the consumer object, and information of the simulation object used to simulate the service object, the method further includes: In response to the object creation instruction, create the simulation object for simulating the service object; In response to the assignment instruction, a value is assigned to the simulation object.
3. The method according to claim 2, characterized in that The creating of the simulation object for simulating the service object includes: Get the name of the service object called by the consumer object; A simulation object is created according to the name of the service object, where the name of the simulation object is the same as the name of the service object.
4. The method according to claim 1, wherein The assigning the value of the simulation object to the target parameter according to the information of the simulation object includes: Setting the access permission of the target parameter to be accessible; Set the value of the simulation object to the value of the target parameter of the consumer object.
5. A device for testing a consumer object, characterized in that: The consumer object is developed based on Spring, and the consumer object uses the Dubbo framework to call the service object; The device comprises: An information acquisition unit, configured to acquire information about a consumer object to be tested, information about a service object called by the consumer object, and information about a simulation object used to simulate the service object, wherein the information about the consumer object includes the name of the consumer object; the information about the service object includes the name of the service object called by the consumer object; a target parameter acquisition unit, configured to acquire target parameters corresponding to the consumer object and the server object through a reflection mechanism based on information about the consumer object and information about the server object called by the consumer object, wherein the target parameters include attribute fields in the consumer object related to the server object call and access permission information thereof; an assignment unit, configured to assign the value of the simulation object to the target parameter through a reflection mechanism according to the information of the simulation object; a testing unit, configured to run the consumer object according to the target parameters, obtain an operation result, compare the operation result with a preset accurate result, and determine a test result of the consumer object based on the comparison result; The target parameter acquisition unit includes: A proxy object acquisition module, configured to acquire a proxy object of a consumer object from a preset object pool according to the name of the consumer object; A consumer object acquisition module, configured to acquire the consumer object according to the proxy object of the consumer object; The target parameter acquisition module is used to acquire the target parameter corresponding to the service object from the multiple parameters of the consumer object according to the name of the service object.
6. An electronic device, characterized in that: comprising a memory and a processor; wherein, The memory is used to store computer programs; The processor is configured to read the computer program stored in the memory and execute the method according to any one of claims 1 to 4 above according to the computer program in the memory.
7. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer-executable instructions, and when the processor executes the computer-executable instructions, the method according to any one of claims 1 to 4 is implemented.
8. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.