A testing method and a testing device

Through Java Agent and bytecode enhancement technology, the target class to be tested is modified bytecode to obtain the running data of the target method, which solves the problem that black box testing cannot penetrate into the program and improves the testing efficiency and applicability.

CN113076253BActive Publication Date: 2025-06-17BEIJING JINGDONG TUOXIAN TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110413114.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-04-16
Publication Date
2025-06-17
Estimated Expiration
2041-04-16

AI Technical Summary

Technical Problem

The existing black box testing methods cannot be tested in depth within the program, resulting in the inability to fully locate the problem, and the test efficiency is low, the cost is high, and it is not suitable for complex scenarios.

Method used

Through Java Agent and bytecode enhancement technology, the target class to be tested is modified bytecode to obtain the running data of the target method, and in-depth testing within the program is realized.

Benefits of technology

Improves testing efficiency, reduces testing costs, is suitable for testing in complex scenarios, and can generate automated test code and white box test code for subsequent regression tests or iterative tests.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113076253B_ABST
    Figure CN113076253B_ABST
Patent Text Reader

Abstract

The present invention discloses a testing method and a testing device, relating to the field of computer technology. A specific embodiment of the method includes: receiving a test request, obtaining a to-be-tested application and test cases according to the test request, and adding a Java Agent to the virtual machine parameters corresponding to the to-be-tested application; before loading the class files of the to-be-tested application, modifying the bytecode of the target classes of the to-be-tested application according to the Java Agent and based on the bytecode enhancement technology, wherein the target classes include: classes for remote calls and classes involved in persistent data; during the process of testing the to-be-tested application using the test cases, calling the target methods included in the target classes, and obtaining the running data corresponding to the target methods; determining the test data corresponding to the test cases according to the obtained running data, and storing the test data. This embodiment can conduct tests deep into the program, improve the testing efficiency, have a low testing cost, and is also applicable to the testing of complex scenarios.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular, to a testing method and a testing device. Background Art

[0002] Current testing methods mainly include black-box testing and white-box testing. White-box testing is a code-level test that needs to be completed by developers, with relatively high testing costs. Moreover, white-box testing is not applicable to complex scenarios. Therefore, most tests are mainly black-box tests.

[0003] Black-box testing, also known as functional testing, detects whether each function can be used normally through test cases. Black-box testing only focuses on the external structure of the program and does not consider the implementation of internal logic. It mainly tests the software interface and software interfaces. However, black-box testing can only perform coverage testing through a large amount of data, consuming a lot of time and not guaranteeing that there are no omissions; black-box testing cannot fully locate the problem and it is difficult to locate the specific class or method where the problem occurs; in addition, black-box testing cannot save the testing process and can only be recorded manually. Summary of the Invention

[0004] In view of this, embodiments of the present invention provide a testing method and a testing device, which can perform in-depth testing inside the program, improve the testing efficiency, have low testing costs, and are also applicable to testing complex scenarios.

[0005] To achieve the above object, according to one aspect of the embodiments of the present invention, a testing method is provided.

[0006] The testing method of the embodiments of the present invention includes: receiving a test request, obtaining a tested application and test cases according to the test request, and adding a Java Agent to the virtual machine parameters corresponding to the tested application; before loading the class files of the tested application, modifying the bytecode of the target classes of the tested application according to the Java Agent and based on bytecode enhancement technology, where the target classes include: classes for remote calls and classes involved in persistent data; during the process of testing the tested application using the test cases, calling the target methods included in the target classes to obtain the running data corresponding to the target methods; determining the test data corresponding to the test cases according to the obtained running data, and storing the test data.

[0007] Optionally, according to the Java Agent and based on bytecode enhancement technology, bytecode modification of the target class of the application under test includes: before the class loader loads the class file of the application under test, obtaining the class file of the application under test through the Java Agent; obtaining the target class from the class file of the application under test; adding an interceptor to the target class to implement bytecode modification of the target class based on bytecode enhancement technology.

[0008] Optionally, calling the target method included in the target class to obtain the running data corresponding to the target method includes: when calling the target method, calling the before and after methods of the interceptor to obtain the input parameter data, output parameter data, and data type corresponding to the target method.

[0009] Optionally, before obtaining the input parameter data, output parameter data, and data type corresponding to the target method, the method further includes: defining a data acquisition rule corresponding to the Java Agent so as to obtain the input parameter data, output parameter data, and data type corresponding to the target method according to the data acquisition rule.

[0010] Optionally, the method further includes: during the process of testing the application under test using the test case, if a class called remotely or a method included in the class called remotely is monitored, collecting the call chain corresponding to the test case.

[0011] Optionally, storing the test data includes: storing the test data in a database; and, in the case where the test data is real-time data, storing the test data in a message queue so as to display the test data or use the test data to perform runtime monitoring on the application under test.

[0012] Optionally, the method further includes: if the number of applications is multiple, adding the Java Agent corresponding to each application to the virtual machine parameters corresponding to each application; and storing the Java Agent information corresponding to each application in a database.

[0013] To achieve the above object, according to another aspect of the embodiments of the present invention, a testing device is provided.

[0014] The test device according to an embodiment of the present invention includes: a deployment module, configured to receive a test request, obtain a to-be-tested application and test cases according to the test request, and add a Java Agent to the virtual machine parameters corresponding to the to-be-tested application; a proxy module, configured to, before loading the class file of the to-be-tested application, modify the bytecode of the target class of the to-be-tested application according to the Java Agent and based on bytecode enhancement technology, where the target class includes: classes for remote calls and classes involved in persistent data; a call module, configured to, during the process of testing the to-be-tested application using the test cases, call the target methods included in the target class and obtain the running data corresponding to the target methods; a determination module, configured to determine the test data corresponding to the test cases according to the obtained running data and store the test data.

[0015] Optionally, the proxy module is further configured to: before the class loader loads the class file of the to-be-tested application, obtain the class file of the to-be-tested application through the Java Agent; obtain the target class from the class file of the to-be-tested application; add an interceptor to the target class to implement modification of the bytecode of the target class based on bytecode enhancement technology.

[0016] Optionally, the call module is further configured to: when calling the target method, call the before and after methods of the interceptor to obtain the input parameter data, output parameter data, and data type corresponding to the target method.

[0017] Optionally, the proxy module is further configured to: define a data acquisition rule corresponding to the Java Agent, so as to acquire the input parameter data, output parameter data, and data type corresponding to the target method according to the data acquisition rule.

[0018] Optionally, the call module is further configured to: during the process of testing the to-be-tested application using the test cases, if a class for remote calls or a method included in the class for remote calls is monitored, collect the call link corresponding to the test cases.

[0019] Optionally, the determination module is further configured to: store the test data in a database; and, in the case where the test data is real-time data, store the test data in a message queue for displaying the test data or using the test data to perform running monitoring on the to-be-tested application.

[0020] Optionally, the deployment module is further configured to: if the number of applications is multiple, add the JavaAgent corresponding to each application to the virtual machine parameters corresponding to each application; and store the Java Agent information corresponding to each application in a database.

[0021] To achieve the above object, according to another aspect of the embodiments of the present invention, an electronic device is provided.

[0022] An electronic device according to an embodiment of the present invention includes: one or more processors; a storage device for storing one or more programs, which when executed by the one or more processors cause the one or more processors to implement the test method of the embodiment of the present invention.

[0023] To achieve the above object, according to still another aspect of the embodiments of the present invention, a computer-readable medium is provided.

[0024] A computer-readable medium according to an embodiment of the present invention has a computer program stored thereon, and when the program is executed by a processor, the test method of the embodiment of the present invention is implemented.

[0025] One embodiment of the above invention has the following advantages or beneficial effects: The target class of the application under test can be modified through Java Agent and bytecode enhancement technology, so that during the execution of the test case, if the target method of the target class is called, the running data corresponding to the target method can be obtained, that is, the context information of the target method running can be obtained. These context information are equivalent to opening a cut surface for testing. Without modifying the program source code of the application under test, the data during the test process can be obtained, so that the test can be carried out deep into the program interior, solving the technical problems that black box testing cannot fully locate the problem and it is difficult to locate the specific class or method where the problem occurs, and also solving the defect that black box testing can only locate the problem through large-scale data coverage testing, improving the test efficiency. And, compared with white box testing, the test method of the embodiment of the present invention has low test cost and is also applicable to testing complex scenarios. In addition, the generated test data can be used to generate automated test code and white box test code, which can be further used for subsequent regression testing or iterative testing.

[0026] The further effects of the above non-conventional optional manner will be described in conjunction with specific embodiments below. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] The drawings are used to better understand the present invention and do not constitute an improper limitation to the present invention. Among them:

[0028] Figure 1 is a schematic diagram of the main steps of the test method according to an embodiment of the present invention;

[0029] Figure 2 is a schematic diagram of the overall architecture of the test system according to an embodiment of the present invention;

[0030] Figure 3It is a schematic structural diagram of the main modules of the test device according to an embodiment of the present invention;

[0031] Figure 4 It is an exemplary system architecture diagram to which the embodiments of the present invention can be applied;

[0032] Figure 5 It is a schematic structural diagram of a computer system of a terminal device or a server suitable for implementing the embodiments of the present invention. Detailed implementation manners

[0033] The following describes exemplary embodiments of the present invention with reference to the accompanying drawings. Various details of the embodiments of the present invention are included to facilitate understanding, and they should be considered merely exemplary. Therefore, those of ordinary skill in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted below.

[0034] Figure 1 It is a schematic diagram of the main steps of the test method according to an embodiment of the present invention. As Figure 1 shown, the main steps of the test method may include:

[0035] Step S101, receiving a test request, obtaining the application under test and test cases according to the test request, and adding JavaAgent to the virtual machine parameters corresponding to the application under test;

[0036] Step S102, before loading the class file of the application under test, modifying the bytecode of the target class of the application under test according to the Java Agent and based on the bytecode enhancement technology;

[0037] Step S103, during the process of testing the application under test using the test cases, calling the target method included in the target class to obtain the running data corresponding to the target method;

[0038] Step S104, determining the test data corresponding to the test cases according to the obtained running data, and storing the test data.

[0039] To be able to open the aspect of the application under test, a Java Agent needs to be defined. This Java Agent can be understood as a Java proxy. Its proxy mode is to provide a proxy object for a certain object, and the proxy object controls the reference to the original object. The Java Agent can intercept before loading the Java file, and thus can modify the bytecode. In the test method provided by the embodiments of the present invention, during the process of testing the application under test using test cases, the bytecode of the application under test can be modified through the JavaAgent, and thus the running data of the application under test can be obtained, that is, the test data corresponding to the test cases can be obtained, and a test report can be generated.

[0040] In step S101, after receiving the test request, the application under test and the test cases in the test request are obtained, and the Java Agent is added to the virtual machine parameters corresponding to the application under test. The Java Agent is a program developed in the Java language. When running, the Java Agent needs to be packaged into a war package or a jar package, and then the package is added to the virtual machine parameters corresponding to the application under test so that the Java Agent can run together with the application under test. It should be noted that the application under test can be the system under test, that is, the functions of the system are tested. Adding the Java Agent to the virtual machine parameters corresponding to the system under test can enable the system and the Java Agent corresponding to the system to run together in the virtual machine. Obviously, the virtual machine corresponding to the system under test refers to the running environment corresponding to the application system under test. In addition, the application under test can also be the function under test. At this time, the Java Agent is added to the virtual machine parameters corresponding to the function under test. Among them, the virtual machine corresponding to the function under test can be understood as the virtual machine corresponding to the system to which the function under test belongs. For example, if the function under test is a function of system A, the virtual machine corresponding to the function under test is the running environment corresponding to system A. In addition, if the application under test is a Web application, the Java Agent can be added to the virtual machine parameters corresponding to the application under test, so that the Java Agent can run in the Web container together with the application under test.

[0041] In step S102, before the class files of the application under test are loaded through the Java Agent, the required classes are obtained, and then based on bytecode enhancement technology, the bytecodes of the required classes are modified. Among them, the required classes refer to the target classes of the application under test, which may include: classes for remote calls and classes involved in persistent data. The classes for remote calls refer to the classes involved in the interaction between systems. Since a complex environment involves the interaction between systems, and the interaction between systems is the focus of testing. Therefore, it is necessary to monitor the classes for remote calls, that is, when a method in a class for remote calls is called, the running situation of this method needs to be monitored. In addition, the classes involved in persistent data refer to the classes where the data in the system falls into the database, which is also the focus of testing. Therefore, it is necessary to monitor the classes involved in persistent data, that is, when a method in a class involved in persistent data is called, the running situation of this method needs to be monitored. Of course, the target classes may also include other classes of the application under test, and the target classes can also be determined according to actual needs.

[0042] Bytecode is an intermediate code that has been compiled and needs to be translated into machine language. Bytecode enhancement technology is a technology for modifying existing bytecodes or dynamically generating new bytecode files. Or rather, bytecode enhancement means that after Java bytecodes are generated, they are modified to enhance their functions, and this method is equivalent to modifying the binary files of the application program. In the embodiments of the present invention, based on bytecode enhancement technology, the bytecodes of the application under test are modified, that is, the bytecodes of the target classes are modified, so that the running situation of the application under test can be monitored without modifying the program source code of the application under test.

[0043] In step S102, based on bytecode enhancement technology, the bytecodes of the target classes of the application under test are modified. In this technical solution, modifying the bytecodes of the target classes means adding methods without modifying the program source code. Specifically, at the beginning and end positions of the methods under the target classes, a before method and an after method are added respectively. Therefore, in the process of using test cases to test the application under test in step S103, when the target methods included in the target classes are called, the running data corresponding to the target methods can be obtained, that is, the internal data during the execution of the test cases. Then, in step S104, according to the obtained running data, the test data corresponding to the test cases is determined, that is, the test data generated by executing the test cases, and finally the generated test data is stored. It should be noted that the test data corresponding to the test cases may include the test process data generated by executing the test cases.

[0044] Currently, the following problems exist in black-box testing: Only large quantities of data can be used for coverage testing, which consumes a lot of time and cannot guarantee that there are no omissions; it cannot fully locate the problem, and it is very difficult to locate the specific class or method where the problem occurs; moreover, the test process cannot be saved and can only be recorded manually. White-box testing has the problems of high testing costs and is not applicable to complex scenarios.

[0045] However, the testing method provided by the embodiments of the present invention can modify the target class of the application under test through Java Agent and bytecode enhancement technology, so that during the execution of test cases, if the target method of the target class is called, the running data corresponding to the target method can be obtained, that is, the context information of the target method running can be obtained. These context information are equivalent to opening a cross-cutting aspect for testing. Without modifying the program source code of the application under test, the data during the test process can be obtained, so that the test can be carried out deep into the program interior, solving the technical problems existing in black-box testing that it cannot fully locate the problem and it is very difficult to locate the specific class or method where the problem occurs, and also solving the defect of black-box testing that only large quantities of data can be used for coverage testing to locate problems, improving the testing efficiency. Moreover, compared with white-box testing, the testing method of the embodiments of the present invention has low testing costs and is also applicable to complex scenario testing. In addition, the generated test process data can be used to generate automated test code and white-box test code, which can then be used for subsequent regression testing or iterative testing. That is to say, the test process can be saved in a coded manner for use when changes or modifications occur in the future.

[0046] Modifying the bytecode is an important part of the testing method provided by the embodiments of the present invention. As an embodiment of the present invention, according to Java Agent and based on bytecode enhancement technology, modifying the bytecode of the target class of the application under test may include: before the class loader loads the class file of the application under test, obtaining the class file of the application under test through Java Agent; obtaining the target class from the class file of the application under test; adding an interceptor to the target class to implement modifying the bytecode of the target class based on bytecode enhancement technology.

[0047] Before the class loader of the Java Agent loads the class files of the application under test, the class files of the application under test can be obtained. Then, as needed, the required classes, i.e., the target classes, are selected from the obtained class files of the application under test. Next, the bytecode of the target classes is modified based on bytecode enhancement technology. Considering that bytecode enhancement technology processes bytecode, there is a tendency to increase development risks and also reduce efficiency. Therefore, the efficiency and reachability are improved by abstracting interceptors. Specifically, at the beginning and end positions of the target methods included in the target classes, the before method and after method of the interceptor are added respectively. The Java Agent injects necessary tracing code for distributed transactions and performance information by intervening in the application code during class loading. For tracing, interceptors are added to the target methods so that the before method and after method are called, and the recording of performance data is implemented in the before method and after method.

[0048] As an embodiment of the present invention, calling the target method included in the target class to obtain the running data corresponding to the target method may include: when calling the target method, calling the before and after methods of the interceptor to obtain the input parameter data, output parameter data, and data types corresponding to the target method.

[0049] As learned from the above, modifying the bytecode of the target class can specifically be: at the beginning and end positions of the target methods included in the target class, the before method and after method of the interceptor are added respectively. Therefore, during the process of testing the application under test using test cases, if it is monitored that the target method is called, the before and after methods of the interceptor need to be called, and thus the input parameter data, output parameter data, and data types corresponding to the target method can be obtained. That is, the data before the target method runs, the data after the target method runs, and the data types can be obtained.

[0050] In addition, as an embodiment of the present invention, before obtaining the input parameter data, output parameter data, and data types corresponding to the target method, the test method may further include: defining the data acquisition rules corresponding to the Java Agent so as to obtain the input parameter data, output parameter data, and data types corresponding to the target method according to the data acquisition rules. Among them, the data acquisition rules may be rules for obtaining data such as HTTP, MySQL, and log. And, the data acquisition rules can be in the form of plugins and start with the startup of the JavaAgent.

[0051] In the embodiments of the present invention, a Java Agent can add interceptors by using callback functions. A general function is a pre-prepared function that the program can execute. However, some functions require a function to be passed to them first and then called at an appropriate time. This function that is passed in and then called is called a callback function. A callback function is not directly called by the implementer of the function, but is called by another party when a specific event or condition occurs to respond to the event or condition. The running process of the Java Agent can be as follows: Add the Java Agent to the virtual machine parameters corresponding to the application under test so that the Java Agent runs along with the application under test; When the Java Agent starts, it loads the plug-in, that is, loads the defined data acquisition rules, and, when the Java Agent starts, it can register callback functions, that is, register the functions for bytecode enhancement; When the application under test starts, before loading the class file of the application under test, the Java Agent intercepts, scans, and registers the target class of the application under test; When the target class of the application under test is loaded, the Java Agent looks for the callback function of the registered class; Then, the callback function calls its own method to initialize and modify the bytecode of the target class, such as adding interceptors; Then, the modified bytecode is returned to the virtual machine, and when the class is loaded, the modified bytecode is executed. When the target method included in the target class is called, that is, when the modified method is called, the before and after methods of the interceptor are also called, so that the data before running the target method, the data after running the target method, and the data type can be obtained.

[0052] In the process of testing the application under test using test cases, not only the running data of the target method needs to be obtained, but also the call links of each node need to be collected, so that the overall business test can be completed. Therefore, as an embodiment of the present invention, the test method may further include: In the process of testing the application under test using test cases, if a remotely called class or a method included in the remotely called class is monitored, collect the call link corresponding to the test case. Specifically, when each node of the service calls each other, record and pass an application-level tag, which can be used to associate the relationships between each service node. For example, if HTTP is used as the request protocol between two nodes, then these tags will be added to the HTTP header. When the Java Agent of each application reports, the tag and the corresponding upper and lower level applications are reported to the link collector. By identifying the request with the tag, each application is concatenated into a complete call link.

[0053] As an embodiment of the present invention, storing test data may include: storing the test data in a database; and, when the test data is real-time data, storing the test data in a message queue so as to display the test data or use the test data to monitor the operation of the tested application.

[0054] All test data needs to be stored in the database. Considering the complex environment of the application and the uncertainty of the application being tested, the non-relational database Hbase is preferred for data storage. Of course, other non-relational databases, such as ES database, can also be selected, but ES database is not as suitable as Hbase database in terms of performance and scalability. Of course, if the data format corresponding to the application being tested is certain, a relational database, such as MySQL database, can also be used.

[0055] In addition, after the test data is stored in the database, the test dependency function can be determined according to the test data, that is, the stored test data can play an auxiliary role in other test scenarios. For example, the boundary information corresponding to the regression test scenario is determined according to the stored test data. Among them, regression testing refers to retesting after modifying the old code to confirm that the modification does not introduce new errors or cause errors in other codes. For example, the interface test data of the three systems A, B, and C are obtained. If the interface of one of the systems needs to be modified or optimized, it is known that the modification affects the three systems A, B, and C. Therefore, in the regression test scenario, the auxiliary information of the boundary can be confirmed to be the three systems A, B, and C, that is, the three systems A, B, and C are analyzed. In addition, the impact can be displayed in the form of a Web page. For example, a requirement change will affect the three systems A, B, and C, and the impact can be displayed on the Web page, and if the interface of one of the systems is changed, the change can also be displayed through the Web page, that is, the change can be displayed through the Web page. Where it will affect.

[0056] And, if the test data is real-time data, the test data can be stored in the message queue, so that the running status of the tested application can be displayed in real time, achieving the effect of monitoring the running of the tested application. In other words, the test data can be displayed on the page through client consumption. For example, the tester initiates a call according to the test case, and the test data generated by this call can be directly stored in the message queue, and then the test data is displayed, realizing real-time call and real-time display of the test data generated by the call, thereby avoiding storing the data in the database and then querying it, reducing the pressure on the database. In addition, it should be noted that in addition to judging whether the test data is currently generated, it is also possible to judge whether the test data is data that needs to be viewed in real time.

[0057] Considering that complex scenarios involve interactions between multiple systems, i.e., scenarios with multiple applications, it is necessary to bind each application to the corresponding Java Agent of that application. That is, in the virtual machine parameters corresponding to that application, add the Java Agent corresponding to that application, so that the Java Agent corresponding to that application can run with that application, and then the running situation of that application can be obtained. Therefore, as an embodiment of the present invention, the testing method may further include: if the number of applications is multiple, add the Java Agent corresponding to each application to the virtual machine parameters corresponding to that application.

[0058] In addition, the Java Agent information corresponding to each application can also be stored in the database, that is, store the name and ID of the Java Agent corresponding to each application in the data, so that the Web page can display the applications that have been bound to the Java Agent by reading the database. Among them, the name of the JavaAgent can be the application name. For the applications that have been bound to the JavaAgent, the running situation of that application can be obtained through the Java Agent. Then, during the process of testing the applications that have been bound to the Java Agent using test cases, the running situation of that application can be displayed through the Web page. Therefore, testers can switch between multiple systems to observe the test running situation of each application. For example, a certain business involves three systems A, B, and C, and these three systems are all bound to the corresponding Java Agent, and the name and ID of the Java Agent are stored in the database. During the process of testing this business using test cases, the running situations of the three systems A, B, and C can be observed on the Web page by loading the database. Testers can switch between systems A, B, and C according to their needs to observe the running situation of the systems they are interested in.

[0059] Figure 2 It is a schematic diagram of the overall architecture of the testing system according to an embodiment of the present invention. As Figure 2 shown, the testing system may include: the application under test, a plug-in, a Java Agent, a Collector, a message queue, an Hbase database, and a Web application service.

[0060] Among them, the application under test can be the system under test or the function under test. It should be noted that in the case of a multi-system interaction scenario, the application under test in the embodiments of the present invention is the system under test.

[0061] The Java Agent can be added to the virtual machine parameters. When the application under test starts, the Java Agent starts along with the application under test. Moreover, before the class loader loads the class files of the application under test, the Java Agent obtains the class files of the application under test, and then obtains the target classes, namely, the classes involved in remote calls and the classes related to persistent data. Then, based on bytecode enhancement technology, the bytecode of the target classes can be modified. Specifically, by adding interceptors, the before method and after method of the interceptor can be added at the start and end positions of the target methods included in the target classes respectively. In this way, during the process of testing the application under test using test cases, if a target method is called, the before method and after method of the interceptor can also be called, so as to obtain the data before and after the execution of the target method, realizing the monitoring of the running status of the application under test. In addition, the Java Agent can also be used to perform link collection if a remote call class or method is monitored, and finally the call link can be collected.

[0062] In addition, the data acquisition rules corresponding to the Java Agent can be defined and stored in the form of a plugin, so that the plugin starts when the Java Agent starts.

[0063] The Collector is mainly used to collect the test data sent by the Java Agent and send the test data to the message queue and the Hbase database. The message queue is mainly used to store real-time data in the asynchronous mechanism of the message queue for subscription and consumption by the foreground Web page. The Hbase is mainly used to store all the test data.

[0064] In addition, the test system can also include a Web service. The Web page of the Web service can display the running status of the application under test. For the scenario of multiple systems, the Web page can also display the systems that have been bound with the Java Agent by reading the database. Moreover, testers can switch between systems on the Web page.

[0065] The test method provided by the embodiments of the present invention can modify the target classes of the application under test through Java Agent and bytecode enhancement technology, so that during the execution of test cases, if the target method of the target class is called, the running data corresponding to the target method can be obtained, that is, the context information of the target method running can be obtained. This context information is equivalent to opening a section for testing. Without modifying the program source code of the application under test, the data during the test can be obtained, so that the test can be carried out deep into the program, solving the technical problems of black box testing that the problem location cannot be fully determined and it is difficult to locate the specific class or method where the problem occurs. It also solves the defect of black box testing that only mass data coverage testing can be used to locate problems, improving the test efficiency. Moreover, compared with white box testing, the test method of the embodiments of the present invention has low test cost and is also applicable to testing complex scenarios. In addition, the generated test process data can be used to generate automated test code and white box test code, which can then be used for subsequent regression testing or iterative testing. That is, the test process is saved in a coded manner for use when changes or modifications occur in the future.

[0066] Figure 3 It is a schematic structural diagram of the main modules of the test device according to the embodiments of the present invention. As Figure 3 shown, the main modules of the test device 300 may include: a deployment module 301, a proxy module 302, a call module 303, and a determination module 304.

[0067] Among them, the deployment module 301 can be used to: receive a test request, obtain the application under test and test cases according to the test request, and add Java Agent to the virtual machine parameters corresponding to the application under test; the proxy module 302 can be used to: before loading the class file of the application under test, according to Java Agent and based on bytecode enhancement technology, modify the bytecode of the target class of the application under test; the call module 303 can be used to: during the process of testing the application under test using test cases, call the target method included in the target class and obtain the running data corresponding to the target method; the determination module 304 can be used to: determine the test data corresponding to the test case according to the obtained running data and store the test data. Among them, the target class may include: classes for remote calls and classes involved in persistent data.

[0068] As an embodiment of the present invention, the proxy module 302 can also be used to: before the class loader loads the class file of the application under test, obtain the class file of the application under test through Java Agent; obtain the target class from the class file of the application under test; add an interceptor to the target class to implement the modification of the bytecode of the target class based on bytecode enhancement technology.

[0069] As an embodiment of the present invention, the invocation module 303 can also be used to: when invoking a target method, invoke the before and after methods of the interceptor to obtain the input parameter data, output parameter data, and data type corresponding to the target method.

[0070] As an embodiment of the present invention, the proxy module 302 can also be used to: define the data acquisition rules corresponding to the Java Agent, so as to obtain the input parameter data, output parameter data, and data type corresponding to the target method according to the data acquisition rules.

[0071] As an embodiment of the present invention, the invocation module 303 can also be used to: during the process of testing the application under test using test cases, if a class called remotely or a method included in the class called remotely is monitored, collect the call link corresponding to the test case.

[0072] As an embodiment of the present invention, the determination module 304 can also be used to: store the test data in a database; and, in the case where the test data is real-time data, store the test data in a message queue, so as to display the test data or use the test data to perform runtime monitoring on the application under test.

[0073] As an embodiment of the present invention, the deployment module 301 can also be used to: if the number of applications is multiple, add the Java Agent corresponding to each application to the virtual machine parameters corresponding to each application; and store the JavaAgent information corresponding to each application in a database.

[0074] According to the test device of the embodiments of the present invention, the target class of the application under test can be modified through Java Agent and bytecode enhancement technology, so that during the execution of test cases, if the target method of the target class is called, the runtime data corresponding to the target method can be obtained, that is, the context information of the target method running can be obtained. These context information are equivalent to opening a section for testing. Without modifying the program source code of the application under test, the data during the test process can be obtained, so that the test can be carried out deep into the program internal, solving the technical problems of black box testing that it cannot fully locate the problem and it is difficult to locate the specific class or method where the problem appears, and also solving the defect of black box testing that it can only locate the problem through large-scale data coverage testing, improving the test efficiency. And, compared with white box testing, the test device of the embodiments of the present invention has low test cost and is also applicable to the testing of complex scenarios. In addition, the generated test process data can be used to generate automated test code and white box test code, and then used for subsequent regression testing or iterative testing.

[0075] Figure 4 An exemplary system architecture 400 is shown to which the test method or test device of the embodiments of the present invention can be applied.

[0076] like Figure 4 As shown, system architecture 400 may include terminal devices 401, 402, 403, network 404 and server 405. Network 404 is used to provide a medium for communication links between terminal devices 401, 402, 403 and server 405. Network 404 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.

[0077] Users can use terminal devices 401, 402, 403 to interact with server 405 through network 404 to receive or send messages, etc. Terminal devices 401, 402, 403 can be various electronic devices with display screens and supporting web browsing, including but not limited to smart phones, tablet computers, laptops, desktop computers, etc.

[0078] Server 405 may be a server that provides various services, such as a background management server that provides support when a user uses terminal devices 401, 402, and 403 to perform tests (only as an example); for another example, server 405 may complete the test of an embodiment of the present invention.

[0079] It should be noted that the testing method provided in the embodiment of the present invention is generally executed by the server 405 , and accordingly, the testing device is generally disposed in the server 405 .

[0080] It should be understood that Figure 4 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to the implementation requirements.

[0081] Reference below Figure 5 , which shows a schematic diagram of the structure of a computer system 500 of a terminal device suitable for implementing an embodiment of the present invention. Figure 5 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0082] like Figure 5 As shown, the computer system 500 includes a central processing unit (CPU) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage part 508 into a random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the system 500 are also stored. The CPU 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.

[0083] The following components are connected to the I / O interface 505: an input section 506 including a keyboard, a mouse, etc.; an output section 507 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc. and a speaker, etc.; a storage section 508 including a hard disk, etc.; and a communication section 509 including a network interface card such as a LAN card, a modem, etc. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the I / O interface 505 as required. A removable medium 511 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc. is installed on the drive 510 as required so that a computer program read therefrom is installed into the storage section 508 as required.

[0084] Specifically, according to the embodiments disclosed by the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, the embodiments disclosed by the present invention include a computer program product which includes a computer program carried on a computer-readable medium, and the computer program includes program codes for performing the methods shown in the flowcharts. In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 509, and / or installed from the removable medium 511. When the computer program is executed by a central processing unit (CPU) 501, the above functions defined in the system of the present invention are performed.

[0085] It should be noted that the computer-readable medium shown in the present invention can be a computer-readable signal medium, a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples of a computer-readable storage medium can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium can be any tangible medium that contains or stores a program, and this program can be used by or in conjunction with an instruction execution system, apparatus, or device. In the present invention, a computer-readable signal medium can include a data signal propagated in a baseband or as part of a carrier wave, in which the computer-readable program code is carried. Such a propagated data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium, and this computer-readable medium can send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on a computer-readable medium can be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0086] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagram can represent a module, a program segment, or a part of code, and the above module, program segment, or part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks can occur in a different order than that marked in the accompanying drawings. For example, two consecutive blocks shown can actually be executed substantially in parallel, and they can sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram or flowchart, and the combination of blocks in the block diagram or flowchart, can be implemented by a dedicated hardware-based system for performing the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.

[0087] The modules involved in the embodiments of the present invention can be implemented in software or in hardware. The described modules can also be provided in a processor. For example, it can be described as: a processor includes a deployment module, an agent module, an invocation module, and a determination module. Among them, the names of these modules do not constitute a limitation to the module itself in some cases. For example, the deployment module can also be described as "a module that receives a test request, obtains a tested application and test cases according to the test request, and adds a Java Agent to the virtual machine parameters corresponding to the tested application".

[0088] As another aspect, the present invention also provides a computer-readable medium, which can be included in the device described in the above embodiments; or can exist alone without being assembled into the device. The above computer-readable medium carries one or more programs. When the one or more programs are executed by a device, the device includes: receiving a test request, obtaining a tested application and test cases according to the test request, and adding a Java Agent to the virtual machine parameters corresponding to the tested application; before loading the class file of the tested application, modifying the bytecode of the target class of the tested application according to the Java Agent and based on bytecode enhancement technology, where the target class includes: classes for remote invocation and classes involved in persistent data; during the process of testing the tested application with test cases, invoking the target method included in the target class and obtaining the running data corresponding to the target method; determining the test data corresponding to the test cases according to the obtained running data, and storing the test data.

[0089] According to the technical solution of the embodiments of the present invention, the target class of the tested application can be modified through Java Agent and bytecode enhancement technology, so that during the execution of test cases, if the target method of the target class is invoked, the running data corresponding to the target method can be obtained, that is, the context information of the target method running can be obtained. These context information are equivalent to opening a section for testing. Without modifying the program source code of the tested application, the data during the testing process can be obtained, so that the testing can be carried out deep into the program interior, solving the technical problems that black box testing cannot fully locate the problem and it is difficult to locate the specific class or method where the problem appears, and also solving the defect that black box testing can only locate the problem through a large number of data for coverage testing, improving the testing efficiency. And, compared with white box testing, the testing method of the embodiments of the present invention has a low testing cost and is also applicable to testing in complex scenarios. In addition, the generated test data can be used to generate automated test code and white box test code, which can then be used for subsequent regression testing or iterative testing.

[0090] The above specific embodiments do not constitute a limitation on the protection scope of the present invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations and substitutions can occur depending on design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.

Claims

1. A testing method, characterized in that, Including: Receiving a test request, obtaining a tested application and test cases according to the test request, and adding a Java Agent to the virtual machine parameters corresponding to the tested application; Before loading the class files of the tested application, modifying the bytecode of the target classes of the tested application according to the Java Agent and based on bytecode enhancement technology, where the target classes include: classes for remote calls and classes involved in persistent data; adding interceptors to the target classes to implement modifying the bytecode of the target classes based on bytecode enhancement technology, including: adding the before method and after method of the interceptor at the start and end positions of the target methods included in the target classes respectively; the running process of the Java Agent includes: when the Java Agent starts, loading plugins to load the defined data acquisition rules and registering callback functions; when the tested application starts, before loading the class files of the tested application, the Java Agent intercepts, scans, and registers the target classes of the tested application; when the target classes of the tested application are loaded, the Java Agent looks for the callback functions of the registered classes, and then the callback functions call their own methods to initialize and modify the bytecode of the target classes; then, the modified bytecode is returned to the virtual machine, and when the class is loaded, the modified bytecode is executed; During the process of testing the tested application using the test cases, calling the target methods included in the target classes and obtaining the running data corresponding to the target methods, including: when calling the target methods, calling the before and after methods of the interceptor to obtain the input parameter data, output parameter data, and data types corresponding to the target methods; Determining the test data corresponding to the test cases according to the obtained running data and storing the test data; During the process of testing the tested application using the test cases, if a class for remote calls or a method included in the class for remote calls is monitored, collecting the call chain corresponding to the test cases.

2. The method according to claim 1, characterized in that, The modifying the bytecode of the target classes of the tested application according to the Java Agent and based on bytecode enhancement technology includes: Before the class loader loads the class files of the tested application, obtaining the class files of the tested application through the Java Agent; Obtaining the target classes from the class files of the tested application; Adding interceptors to the target classes to implement modifying the bytecode of the target classes based on bytecode enhancement technology.

3. The method according to claim 1, characterized in that, Before obtaining the input parameter data, output parameter data, and data types corresponding to the target methods, the method further includes: Defining the data acquisition rules corresponding to the Java Agent so as to obtain the input parameter data, output parameter data, and data types corresponding to the target methods according to the data acquisition rules.

4. The method according to claim 1, characterized in that, The storing the test data includes: Storing the test data into a database; and, When the test data is real-time data, store the test data in a message queue so as to display the test data or use the test data to perform running monitoring on the application under test.

5. The method according to any one of claims 1 to 4, characterized in that, The method further includes: If there are multiple applications, add the Java Agent corresponding to each application to the virtual machine parameters corresponding to each application; and, Store the Java Agent information corresponding to each application in a database.

6. A testing device, characterized in that, It includes: A deployment module, configured to receive a test request, obtain an application under test and test cases according to the test request, and add a Java Agent to the virtual machine parameters corresponding to the application under test; An agent module, configured to, before loading the class file of the application under test, modify the bytecode of the target class of the application under test according to the Java Agent and based on bytecode enhancement technology, where the target class includes: classes for remote calls, classes involved in persistent data; add interceptors to the target class to implement modifying the bytecode of the target class based on bytecode enhancement technology, including: adding the before method and after method of the interceptor at the start and end positions of the target method included in the target class respectively; the running process of the Java Agent includes: when the Java Agent starts, it loads a plugin to load the defined data acquisition rules and registers a callback function; when the application under test starts, before loading the class file of the application under test, the Java Agent intercepts, scans, and registers the target class of the application under test; when the target class of the application under test is loaded, the Java Agent looks for the callback function of the registered class, and then, the callback function calls its own method to initialize and modify the bytecode of the target class; then, the modified bytecode returns to the virtual machine, and when the class is loaded, the modified bytecode is executed; A call module, configured to, during the process of testing the application under test using the test cases, call the target method included in the target class to obtain the running data corresponding to the target method, including: when calling the target method, call the before and after methods of the interceptor to obtain the input parameter data, output parameter data, and data type corresponding to the target method; During the process of testing the application under test using the test cases, if a class for remote calls or a method included in the class for remote calls is monitored, collect the call link corresponding to the test case; A determination module, configured to determine the test data corresponding to the test case according to the obtained running data and store the test data.

7. An electronic device, characterized in that, It includes: One or more processors; A storage device, configured to store one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 - 5.

8. A computer-readable medium, on which a computer program is stored, characterized in that, When the program is executed by the processor, it implements the method according to any one of claims 1 - 5.

Citation Information

Patent Citations

  • Performance data log obtaining method and device

    CN108228147A

  • Automatic test code generation method and device

    CN110858172A