CN113076253A - Test method and test device - Google Patents

Test method and test device Download PDF

Info

Publication number
CN113076253A
CN113076253A CN202110413114.9A CN202110413114A CN113076253A CN 113076253 A CN113076253 A CN 113076253A CN 202110413114 A CN202110413114 A CN 202110413114A CN 113076253 A CN113076253 A CN 113076253A
Authority
CN
China
Prior art keywords
test
data
class
application
target
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110413114.9A
Other languages
Chinese (zh)
Inventor
王甲林
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Tuoxian Technology Co Ltd
Original Assignee
Beijing Jingdong Tuoxian Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Tuoxian Technology Co Ltd filed Critical Beijing Jingdong Tuoxian Technology Co Ltd
Priority to CN202110413114.9A priority Critical patent/CN113076253A/en
Publication of CN113076253A publication Critical patent/CN113076253A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/362Software debugging
    • G06F11/3644Software debugging by instrumenting at runtime
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/362Software debugging
    • G06F11/366Software debugging using diagnostics

Abstract

The invention discloses a test method and a test device, and relates to the technical field of computers. One embodiment of the method comprises: receiving a test request, acquiring a tested application and a test case according to the test request, and adding the Java Agent into a virtual machine parameter corresponding to the tested application; before loading a class file of an application to be tested, according to Java Agent and based on a byte code enhancement technology, carrying out byte code modification on a target class of the application to be tested, wherein the target class comprises: a remotely invoked class, a class to which persistent data relates; in the process of testing the application to be tested by using the test case, calling a target method contained in a target class to acquire running data corresponding to the target method; and determining test data corresponding to the test case according to the acquired operation data, and storing the test data. The implementation mode can be deeply tested in the program, the testing efficiency is improved, the testing cost is low, and the method is also suitable for testing complex scenes.

Description

Test method and test device
Technical Field
The invention relates to the technical field of computers, in particular to a test method and a test device.
Background
Current testing methods mainly include black box testing and white box testing. The white box test is a code level test, needs to be completed by developers, is high in test cost, and is not suitable for complex scenes, so that most tests are mainly black box tests.
The black box test is also called a functional test, and whether each function can be normally used is detected through a test case. The black box test only focuses on the external structure of the program, does not consider the realization of internal logic, and mainly tests aiming at a software interface and a software interface. However, the black box test can only perform coverage test through a large amount of data, which consumes much time and cannot ensure that there are no missing places; the black box test cannot completely locate the problem, and is difficult to locate the specific type or method of the problem; in addition, the black box test cannot preserve the test process, and only can be recorded manually.
Disclosure of Invention
In view of this, embodiments of the present invention provide a testing method and a testing apparatus, which can perform testing deep into a program, improve testing efficiency, have low testing cost, and are also suitable for testing in a complex scenario.
To achieve the above object, according to an aspect of an embodiment of the present invention, a test method is provided.
The test method of the embodiment of the invention comprises the following steps: receiving a test request, acquiring a tested application and a test case according to the test request, and adding a Java Agent into a virtual machine parameter corresponding to the tested application; before loading the class file of the tested application, according to the Java Agent and based on a byte code enhancement technology, carrying out byte code modification on a target class of the tested application, wherein the target class comprises: a remotely invoked class, a class to which persistent data relates; calling a target method contained in the target class in the process of testing the tested application by using the test case to obtain running data corresponding to the target method; and determining test data corresponding to the test case according to the acquired operation data, and storing the test data.
Optionally, the performing bytecode modification on the target class of the application under test according to the Java Agent and based on a bytecode enhancement technology includes: before a class loader loads the class file of the tested application, the class file of the tested application is obtained through the Java Agent; acquiring the target class from the class file of the tested application; adding an interceptor to the target class to enable modification of the bytecode of the target class based on bytecode enhancement techniques.
Optionally, the invoking a target method included in the target class, and obtaining operation data corresponding to the target method includes: and when the target method is called, calling the before and after methods of the interceptor, and acquiring the parameter input data, the parameter output data and the data type corresponding to the target method.
Optionally, before obtaining the parameter entry data, the parameter exit data, and the data type corresponding to the target method, the method further includes: and defining a data acquisition rule corresponding to the Java Agent so as to acquire the input parameter data, the output parameter data and the data type corresponding to the target method according to the data acquisition rule.
Optionally, the method further comprises: and in the process of testing the application to be tested by using the test case, if the remotely called class or the method contained in the remotely called class is monitored, collecting a calling link corresponding to the test case.
Optionally, the storing the test data includes: storing the test data in a database; and storing the test data into a message queue under the condition that the test data is real-time data so as to display the test data or monitor the running of the application to be tested by utilizing the test data.
Optionally, the method further comprises: if the number of the applications is multiple, adding the Java Agent corresponding to each application into the virtual machine parameter corresponding to each application; and storing the Java Agent information corresponding to each application into a database.
To achieve the above object, according to still another aspect of an embodiment of the present invention, there is provided a test apparatus.
The testing device of the embodiment of the invention comprises: the deployment module is used for receiving a test request, acquiring a tested application and a test case according to the test request, and adding Java agents into the virtual machine parameters corresponding to the tested application; the Agent module is used for modifying the bytecode of the target class of the tested application according to the Java Agent and based on a bytecode enhancement technology before loading the class file of the tested application, wherein the target class comprises: a remotely invoked class, a class to which persistent data relates; the calling module is used for calling a target method contained in the target class in the process of testing the application to be tested by using the test case to acquire running data corresponding to the target method; and the determining module is used for determining the test data corresponding to the test case according to the acquired running data and storing the test data.
Optionally, the agent module is further configured to: before a class loader loads the class file of the tested application, the class file of the tested application is obtained through the Java Agent; acquiring the target class from the class file of the tested application; adding an interceptor to the target class to enable modification of the bytecode of the target class based on bytecode enhancement techniques.
Optionally, the invoking module is further configured to: and when the target method is called, calling the before and after methods of the interceptor, and acquiring the parameter input data, the parameter output data and the data type corresponding to the target method.
Optionally, the agent module is further configured to: and defining a data acquisition rule corresponding to the Java Agent so as to acquire the input parameter data, the output parameter data and the data type corresponding to the target method according to the data acquisition rule.
Optionally, the invoking module is further configured to: and in the process of testing the application to be tested by using the test case, if the remotely called class or the method contained in the remotely called class is monitored, collecting a calling link corresponding to the test case.
Optionally, the determining module is further configured to: storing the test data in a database; and storing the test data into a message queue under the condition that the test data is real-time data so as to display the test data or monitor the running of the application to be tested by utilizing the test data.
Optionally, the deployment module is further configured to: if the number of the applications is multiple, adding the Java Agent corresponding to each application into the virtual machine parameter corresponding to each application; and storing the Java Agent information corresponding to each application into a database.
To achieve the above object, according to still another aspect of an embodiment of the present invention, there is provided an electronic apparatus.
An electronic device of an embodiment of the present invention includes: one or more processors; the storage device is used for storing one or more programs, and when the one or more programs are executed by one or more processors, the one or more processors realize the test method of the embodiment of the invention.
To achieve the above object, according to still another aspect of an embodiment of the present invention, there is provided a computer-readable medium.
A computer-readable medium of an embodiment of the present invention has a computer program stored thereon, which when executed by a processor implements a testing method of an embodiment of the present invention.
One embodiment of the above invention has the following advantages or benefits: the target class of the tested application can be modified through the Java Agent and bytecode enhancement technology, so that in the process of executing the test case, if the target method of the target class is called, the running data corresponding to the target method, namely the context information of the running of the target method, can be obtained, the context information is equivalent to opening a tangent plane for testing, the data in the testing process can be obtained without modifying the program source code of the tested application, the testing can be performed deeply in the program, the technical problems of incomplete positioning of the black box testing problem and difficult positioning of the specific class or method are solved, the defect that the problem can only be positioned through coverage testing of large batches of data in the black box testing is solved, and the testing efficiency is improved. In addition, compared with a white box test, the test method provided by the embodiment of the invention is low in test cost and is also suitable for testing complex scenes. And, the generated test data can be used to generate an automated test code and a white-box test code for subsequent regression testing or iterative testing.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a schematic diagram of the main steps of a test method according to an embodiment of the invention;
FIG. 2 is a block diagram of an overall architecture of a test system according to an embodiment of the present invention;
FIG. 3 is a schematic structural diagram of the main modules of a testing apparatus according to an embodiment of the present invention;
FIG. 4 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
fig. 5 is a schematic block diagram of a computer system suitable for use in implementing a terminal device or server of an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
FIG. 1 is a schematic diagram of the main steps of a test method according to an embodiment of the invention. As shown in fig. 1, the main steps of the test method may include:
step S101, receiving a test request, acquiring a tested application and a test case according to the test request, and adding a Java Agent into a virtual machine parameter corresponding to the tested application;
step S102, before loading the class file of the tested application, according to Java Agent and based on byte code enhancement technology, modifying the byte code of the target class of the tested application;
step S103, in the process of testing the application to be tested by using the test case, calling a target method contained in the target class to acquire running data corresponding to the target method;
and step S104, determining test data corresponding to the test case according to the acquired operation data, and storing the test data.
In order to be able to open a section of the application under test, a Java Agent needs to be defined. The Java Agent can be understood as a Java Agent whose Agent model provides an Agent object to an object, and the Agent object controls the reference to the original object. The Java Agent can intercept the Java file before loading the Java file, and further can modify the byte codes. According to the test method provided by the embodiment of the invention, in the process of testing the application to be tested by using the test case, the bytecode modification can be carried out on the application to be tested through the Java Agent, so that the operation data of the application to be tested is obtained, that is, the test data corresponding to the test case is obtained, and a test report is generated.
In step S101, after receiving the test request, obtaining the application under test and the test case in the test request, and adding the Java Agent to the virtual machine parameter corresponding to the application under test. The Java Agent is a program developed by Java language, and is required to be packaged into a war package or a jar package during running, and then the package is added into the virtual machine parameters corresponding to the tested application, so that the Java Agent can run together with the tested application. It is noted that the application under test may be a system under test, i.e. testing the functionality that the system has. Adding Java Agent t into the virtual machine parameters corresponding to the tested system, and further running the system and the Java Agent corresponding to the system in the virtual machine. Obviously, the virtual machine corresponding to the tested system refers to the running environment corresponding to the tested application system. In addition, the application to be tested can also be a function to be tested, and at this time, the Java Agent is added into the virtual machine parameter corresponding to the function to be tested. For example, if the function to be tested is a function of the system a, the virtual machine corresponding to the function to be tested is an operating environment corresponding to the system a. In addition, if the application to be tested is a Web application, the Java Agent may be added to the virtual machine parameter corresponding to the application to be tested, so that the Java Agent may run in the Web container along with the application to be tested.
In step S102, obtaining a required class by using the Java Agent before loading the class file of the application under test, and then performing bytecode modification on the required class based on the bytecode enhancement technology. The required class refers to a target class of the application to be tested, and may include: a remotely invoked class, a class to which persistent data relates. The remotely invoked class refers to a class that involves interaction between systems. The interaction between systems is involved due to complex environment, and belongs to the emphasis of test. Therefore, the remotely called class needs to be monitored, that is, when a method in the remotely called class is called, the operation condition of the method needs to be monitored. In addition, the class referred to by the persistent data refers to the class of the system in which the data falls into the database, which also belongs to the focus of the test. Therefore, there is a need to monitor the class to which the persistent data relates, i.e., when a method under the class to which the persistent data relates is called, the operation of the method needs to be monitored. Of course, the target class may also include other classes of the application to be tested, and the target class may also be determined according to actual requirements.
Bytecode is an intermediate code that has been compiled to require translation to become machine language. The bytecode enhancement technology is a technology for modifying the existing bytecode or dynamically generating a completely new bytecode file. Or, bytecode enhancement refers to modifying Java bytecode to enhance its functionality after it is generated, which is equivalent to modifying the binary file of an application. In the embodiment of the invention, the bytecode modification is carried out on the tested application based on the bytecode enhancement technology, namely, the bytecode of the target class is modified, so that the running condition of the tested application can be monitored under the condition that the program source code of the tested application is not modified.
In step S102, the bytecode of the target class of the application under test is modified based on the bytecode enhancement technique. In the technical scheme, modifying the byte codes of the target class refers to adding a new method under the condition of not modifying the program source codes. Specifically, at the beginning and end positions of the method under the target class, the before method and the after method are added respectively. Therefore, in the process of testing the application under test by using the test case in step S103, when the target method included in the target class is called, the running data corresponding to the target method, that is, the internal data in the process of executing the test case, may be obtained. Then, in step S104, according to the acquired operation data, test data corresponding to the test case, that is, test data generated by executing the test case is determined, and finally, the generated test data is stored. It should be noted that the test data corresponding to the test case may include test procedure data generated by executing the test case.
At present, the black box test has the following problems: coverage tests can only be carried out through mass data, much time is consumed, and no missing place exists; problems cannot be completely located, and specific types or methods of the problems are difficult to locate; in addition, the test process cannot be saved, and only a manual recording mode is adopted. The white box test has the problems of higher test cost and inapplicability to complex scenes.
However, the test method provided by the embodiment of the invention can modify the target class of the application to be tested through the Java Agent and the bytecode enhancement technology, so that in the process of executing the test case, if the target method of the target class is called, the running data corresponding to the target method can be acquired, namely, context information of the running of the target method is acquired, the context information is equivalent to opening a section for testing, data in the testing process can be acquired without modifying program source codes of the tested application, therefore, the test can be performed in the program, the technical problems of the black box test that the problem cannot be completely positioned and the problem is difficult to position are solved, the defect that the problem can only be positioned by performing coverage test through mass data in the black box test is overcome, and the test efficiency is improved. In addition, compared with a white box test, the test method provided by the embodiment of the invention is low in test cost and is also suitable for testing complex scenes. And, the generated test process data can be utilized to generate automatic test codes and white-box test codes for subsequent regression testing or iterative testing. That is, the test procedure may be saved in a coded manner for later use when changed or modified.
Modifying the bytecode is an important component of the testing method provided by the embodiment of the invention. As an embodiment of the present invention, according to Java Agent and based on bytecode enhancement technology, performing bytecode modification on a target class of an application under test may include: before the class loader loads the class file of the application to be tested, the class file of the application to be tested is obtained through the Java Agent; acquiring a target class from a class file of an application to be tested; and adding an interceptor to the target class to modify the bytecode of the target class based on the bytecode enhancement technology.
Before the class loader loads the class file of the tested application, the Java Agent can acquire the class file of the tested application. And then, selecting a required class, namely a target class, from the acquired class files of the tested application as required. Next, bytecode modifications are made to the target class based on bytecode enhancement techniques. Considering that the bytecode enhancement technology processes the bytecode, there is a tendency to increase the development risk and also to decrease the efficiency. Thus, efficiency and reachability are improved by abstracting out the interceptors. Specifically, at the beginning and the end of the target method contained in the target class, the before method and the after method of the interceptor are added respectively. The Java Agent injects the necessary trace code for distributed transaction and performance information through intervening application code at class loading. For tracking, an interceptor is added to the target method, so that the before method and the after method are called, and recording of performance data is realized in the before method and the after method.
As an embodiment of the present invention, invoking a target method included in a target class, and obtaining operation data corresponding to the target method may include: when the target method is called, the bef ore and after methods of the interceptors are called, and the parameter input data, the parameter output data and the data type corresponding to the target method are obtained.
As can be seen from the above, the bytecode modification on the target class may specifically be: at the beginning and the end of the target method contained in the target class, the before method and the after method of the interceptor are respectively added. Therefore, in the process of testing the application to be tested by using the test case, if the calling target method is monitored, the before and after methods of the interceptor need to be called, and then the entry parameter data, the exit parameter data and the data type corresponding to the target method can be acquired. That is, data before the target method is executed, data after execution, and a data type may be acquired.
In addition, as an embodiment of the present invention, before obtaining the entry parameter data, the exit parameter data, and the data type corresponding to the target method, the test method may further include: and defining a data acquisition rule corresponding to the Java Agent so as to acquire the parameter input data, the parameter output data and the data type corresponding to the target method according to the data acquisition rule. The data acquisition rule may be a rule for acquiring data such as HTTP, MySQL, log, and the like. And the data acquisition rule can be started in a plug-in mode along with the start of the Java Agent.
In the embodiment of the invention, the Java Agent can add the interceptor by utilizing the callback function. The general function is a function prepared in advance, and a program can be executed. However, some functions require that a function be passed to it and then called when appropriate, and this passed-in and called function is called a callback function. The 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, for responding to the event or condition. The running process of the Java Agent can be as follows: adding the Java Agent into the virtual machine parameters corresponding to the tested application so that the Java Agent runs along with the tested application; when the Java Agent is started, a plug-in is loaded, namely a defined data acquisition rule is loaded, and when the Java Agent is started, a callback function can be registered, namely a bytecode-enhanced function is registered; when the tested application is started, before the class file of the tested application is loaded, the Java Agent intercepts, scans and registers the target class of the tested application; when a target class of the application to be tested is loaded, the Java Agent searches a callback function of a registered class; then, calling a method of the call-back function to initialize and modify the byte codes of the target class, such as adding an interceptor; the modified bytecode is then returned to the virtual machine and executed at the time of class loading. When a target method contained in the target class is called, namely the modified method is called, the before and after methods of the interceptor are also called, so that data before the target method is operated, data after the target method is operated and the data type can be acquired.
In the process of testing the application to be tested by using the test case, not only the running data of the target method needs to be acquired, but also the call links of each node need to be collected, so that the test of the whole service can be completed. Therefore, as an embodiment of the present invention, the testing method may further include: in the process of testing the application to be tested by using the test case, if the remotely called class or the method contained in the remotely called class is monitored, the call link corresponding to the test case is collected. Specifically, when the service nodes invoke each other, an application-level flag is recorded and passed, and this flag can be used to correlate the relationships between the service nodes. For example, if HTTP is used as a request protocol between two nodes, these tags are added to an HTTP header, and when a Java Agent of each application reports, the tag and the corresponding upper and lower applications are reported to a link collector, and each application is connected in series to form a complete call link by the tag identification request.
As an embodiment of the present invention, storing test data may include: storing the test data in a database; and storing the test data into a message queue under the condition that the test data is real-time data so as to display the test data or monitor the running of the application to be tested by utilizing the test data.
All test data needs to be stored in the database. Considering the complex environment of the application and the uncertainty of the tested application, the non-relational database Hbase is preferentially selected for data storage. Of course, other non-relational databases, such as the ES database, may be chosen, but the ES database is not as suitable as the Hbase database in terms of performance and scalability. Of course, if the data format corresponding to the application under test is determined, a relational database, such as My SQL database, may also be used.
In addition, after the test data is stored in the database, the test dependence function can be determined according to the test data, that is, the stored test data can play an auxiliary role in other test scenes. And determining boundary information corresponding to the regression test scene according to the stored test data. The regression test refers to that after the old code is modified, the test is carried out again to confirm that no new error is introduced into the modification or other codes are in error. For example, interface test data of the three systems is acquired A, B, C. If the interface of one of the systems needs to be modified or optimized, it is known that this modification affects A, B, C the three systems. Therefore, in the regression test scenario, three systems, namely, the system A, B, C, can be analyzed, with the assistance information of the boundary being A, B, C. Also, the effects may be displayed in the form of Web pages. For example, a change in demand may affect A, B, C the three systems, the effect may be displayed on a Web page, and if a change is made to an interface of one of the systems, the change may also be displayed on the Web page, i.e., the change may be displayed on the Web page, where it is displayed, and where the effect is to occur.
And if the test data is real-time data, the test data can be stored in the message queue, so that the running condition of the application to be tested can be displayed in real time, and the effect of monitoring the running of the application to be tested is achieved. That is, the test data may be displayed on the page in a manner that is consumed by the client. For example, a tester initiates a call according to a test case, can directly store test data generated by the call into a message queue, and then display the test data, so that the test data generated by the call is displayed in real time, and the data is prevented from being stored in a database and then queried, and the pressure of the database is reduced. In addition, it should be noted that, whether the test data is real-time data or not is determined, and whether the test data is data that needs to be checked in real time or not can be determined in addition to whether the test data is currently generated.
Considering that a complex scene may involve interaction among multiple systems, that is, a scene with multiple applications exists, it is necessary to bind each application with a Java Agent corresponding to the application, that is, the Java Agent corresponding to the application is added to a virtual machine parameter corresponding to the application, so that the Java Agent corresponding to the application can run along with the application, and further, the running condition of the application can be obtained. Therefore, as an embodiment of the present invention, the testing method may further include: and if the number of the applications is multiple, adding the Java Agent corresponding to each application into the virtual machine parameter corresponding to the application.
In addition, the information of the Java agents corresponding to each application can be stored in the database, that is, the name and the ID of the Java Agent corresponding to each application are stored in the data, so that the Web page can display the application bound with the Java agents by reading the database. The name of the JavaAgent may be an application name. For the application bound with the Java Agent, the running condition of the application can be obtained through the Java Agent. Then, in the process of testing the application bound with the Java Agent by using the test case, the running condition of the application can be displayed through the Web page. Therefore, the tester can switch among a plurality of systems to observe the test operation condition of each application. For example, a certain service involves A, B, C three systems, and all three systems are bound with corresponding Java agents, and names and IDs of the Java agents are stored in a database. In the process of testing the service by using the test case, the operation conditions of the three systems, namely A, B, C, can be observed on the Web page by loading the database. The tester can switch between the A, B, C three systems as required to observe the operation of the system of interest.
FIG. 2 is a block diagram of an overall architecture of a test system according to an embodiment of the present invention. As shown in fig. 2, the test system may include: the system comprises a tested application, a plug-in, a Java Agent, a Collector, a message queue, an Hbase database and a Web application service.
The application under test may be a system under test or a function under test. It should be noted that, in the scenario of multi-system interaction, the application under test in the embodiment of the present invention is a system under test.
Java agents may be added to the virtual machine parameters. When the tested application is started, the Java Agent is started together with the tested application. And before the class loader loads the class file of the tested application, the Java Agent acquires the class file of the tested application and then acquires a target class, namely a remotely called class and a class related to persistent data. Bytecode modifications can then be made to the target class based on bytecode enhancement techniques. Specifically, the before method and the after method of the interceptor can be added at the beginning and the end of the target method included in the target class by adding the interceptor respectively. Therefore, in the process of testing the tested application by using the test case, if the target method is called, the before method and the after method of the interceptor can be called, so that data before and after the target method is operated are obtained, and the operation condition of the tested application is monitored. And the Java Agent can also be used for carrying out link acquisition if monitoring that the remote calling class or method is initiated, and finally collecting the calling link.
In addition, a data acquisition rule corresponding to the Java Agent can be defined, and the data acquisition rule is stored in a plug-in mode, so that the plug-in is started along with the starting of the Java Agent.
The Collector is mainly used for collecting test data sent by the Java Agent, and queuing the test data message and the Hbase database. The message queue is mainly used for storing real-time data by using a message queue asynchronous mechanism so as to facilitate the subscription and consumption of a foreground Web page. Hbase is used primarily to store all test data.
In addition, the test system may also include a Web service. The Web page of the Web service may display the behavior of the application under test. For a scene with multiple systems, the Web page can also display the system bound with the Java Agent by reading the database. Also, the tester can switch between systems on the Web page.
The test method provided by the embodiment of the invention can modify the target class of the tested application by Java Agent and byte code enhancement technology, so that in the process of executing the test case, if the target method of the target class is called, the running data corresponding to the target method can be acquired, namely, context information of the running of the target method is acquired, the context information is equivalent to opening a section for testing, data in the testing process can be acquired without modifying program source codes of the tested application, therefore, the test can be performed in the program, the technical problems of the black box test that the problem cannot be completely positioned and the problem is difficult to position are solved, the defect that the problem can only be positioned by performing coverage test through mass data in the black box test is overcome, and the test efficiency is improved. In addition, compared with a white box test, the test method provided by the embodiment of the invention is low in test cost and is also suitable for testing complex scenes. And, the generated test process data can be utilized to generate automatic test codes and white-box test codes for subsequent regression testing or iterative testing. That is, the test procedure is saved in a coded manner for later use when changed or modified.
Fig. 3 is a schematic structural diagram of main modules of a test apparatus according to an embodiment of the present invention. As shown in fig. 3, the main modules of the test apparatus 300 may include: a deployment module 301, a proxy module 302, a calling module 303, and a determination module 304.
Wherein the deployment module 301 is operable to: receiving a test request, acquiring a tested application and a test case according to the test request, and adding the Java Agent into a virtual machine parameter corresponding to the tested application; the agent module 302 may be configured to: before loading a class file of the application to be tested, carrying out bytecode modification on a target class of the application to be tested according to Java Agent and based on a bytecode enhancement technology; the calling module 303 may be configured to: in the process of testing the application to be tested by using the test case, calling a target method contained in a target class to acquire running data corresponding to the target method; the determination module 304 may be operable to: and determining test data corresponding to the test case according to the acquired operation data, and storing the test data. Wherein, the target class may include: a remotely invoked class, a class to which persistent data relates.
As an embodiment of the present invention, the agent module 302 may further be configured to: before the class loader loads the class file of the application to be tested, the class file of the application to be tested is obtained through the Java Agent; acquiring a target class from a class file of an application to be tested; and adding an interceptor to the target class to modify the bytecode of the target class based on the bytecode enhancement technology.
As an embodiment of the present invention, the invoking module 303 may be further configured to: when the target method is called, the before and after methods of the interceptor are called, and the parameter entering data, the parameter outputting data and the data type corresponding to the target method are obtained.
As an embodiment of the present invention, the agent module 302 may further be configured to: and defining a data acquisition rule corresponding to the Java Agent so as to acquire the parameter input data, the parameter output data and the data type corresponding to the target method according to the data acquisition rule.
As an embodiment of the present invention, the invoking module 303 may be further configured to: in the process of testing the application to be tested by using the test case, if the remotely called class or the method contained in the remotely called class is monitored, the call link corresponding to the test case is collected.
As an embodiment of the present invention, the determining module 304 may further be configured to: storing the test data in a database; and storing the test data into a message queue under the condition that the test data is real-time data so as to display the test data or monitor the running of the application to be tested by utilizing the test data.
As an embodiment of the present invention, the deployment module 301 may further be configured to: if the number of the applications is multiple, adding the Java Agent corresponding to each application into the virtual machine parameter corresponding to each application; and storing the Java Agent information corresponding to each application into a database.
According to the testing device of the embodiment of the invention, the target class of the application to be tested can be modified by Java Agent and byte code enhancement technology, so that in the process of executing the test case, if the target method of the target class is called, the running data corresponding to the target method can be acquired, namely, context information of the running of the target method is acquired, the context information is equivalent to opening a section for testing, data in the testing process can be acquired without modifying program source codes of the tested application, therefore, the test can be performed in the program, the technical problems of the black box test that the problem cannot be completely positioned and the problem is difficult to position are solved, the defect that the problem can only be positioned by performing coverage test through mass data in the black box test is overcome, and the test efficiency is improved. In addition, compared with a white box test, the test device provided by the embodiment of the invention is low in test cost and is also suitable for testing complex scenes. And, the generated test process data can be utilized to generate automatic test codes and white-box test codes for subsequent regression testing or iterative testing.
Fig. 4 shows an exemplary system architecture 400 to which the test method or test apparatus of an embodiment of the invention may be applied.
As shown in fig. 4, the system architecture 400 may include terminal devices 401, 402, 403, a network 404, and a server 405. The network 404 serves as a medium for providing communication links between the terminal devices 401, 402, 403 and the server 405. Network 404 may include various types of connections, such as wire, wireless communication links, or fiber optic cables, to name a few.
A user may use terminal devices 401, 402, 403 to interact with a server 405 over a network 404 to receive or send messages or the like. The terminal devices 401, 402, 403 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 405 may be a server providing various services, for example, a background management server (for example only) providing support during a test performed by a user using the terminal devices 401, 402, and 403; as another example, server 405 may perform the testing of embodiments of the present invention.
It should be noted that the testing method provided by the embodiment of the present invention is generally executed by the server 405, and accordingly, the testing apparatus is generally disposed in the server 405.
It should be understood that the number of terminal devices, networks, and servers in fig. 4 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 5, shown is a block diagram of a computer system 500 suitable for use with a terminal device implementing an embodiment of the present invention. The terminal device shown in fig. 5 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 5, the computer system 500 includes a Central Processing Unit (CPU)501 that 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 section 508 into a Random Access Memory (RAM) 503. In the RAM 503, various programs and data necessary for the operation of the system 500 are also stored. The CPU 501, ROM 502, and RAM 503 are connected to each other via a bus 504. An input/output (I/O) interface 505 is also connected to bus 504.
The following components are connected to the I/O interface 505: an input portion 506 including a keyboard, a mouse, and the like; an output portion 507 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 508 including a hard disk and the like; and a communication section 509 including a network interface card such as a LAN card, a modem, or the like. The communication section 509 performs communication processing via a network such as the internet. The driver 510 is also connected to the I/O interface 505 as necessary. A removable medium 511 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 510 as necessary, so that a computer program read out therefrom is mounted into the storage section 508 as necessary.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 509, and/or installed from the removable medium 511. The computer program performs the above-described functions defined in the system of the present invention when executed by the central processing unit (CP U) 501.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present invention, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor includes a deployment module, an agent module, a calling module, and a determination module. For example, the deployment module may be further described as a module that receives a test request, obtains a tested application and a test case according to the test request, and adds the Java Agent to a virtual machine parameter corresponding to the tested application.
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise: receiving a test request, acquiring a tested application and a test case according to the test request, and adding the Java Agent into a virtual machine parameter corresponding to the tested application; before loading a class file of an application to be tested, according to Java Agent and based on a byte code enhancement technology, carrying out byte code modification on a target class of the application to be tested, wherein the target class comprises: a remotely invoked class, a class to which persistent data relates; in the process of testing the application to be tested by using the test case, calling a target method contained in a target class to acquire running data corresponding to the target method; and determining test data corresponding to the test case according to the acquired operation data, and storing the test data.
According to the technical scheme of the embodiment of the invention, the target class of the tested application can be modified by Java Agent and byte code enhancement technology, so that in the process of executing the test case, if the target method of the target class is called, the running data corresponding to the target method can be acquired, namely, context information of the running of the target method is acquired, the context information is equivalent to opening a section for testing, data in the testing process can be acquired without modifying program source codes of the tested application, therefore, the test can be performed in the program, the technical problems of the black box test that the problem cannot be completely positioned and the problem is difficult to position are solved, the defect that the problem can only be positioned by performing coverage test through mass data in the black box test is overcome, and the test efficiency is improved. In addition, compared with a white box test, the test method provided by the embodiment of the invention is low in test cost and is also suitable for testing complex scenes. And, the generated test data can be used to generate an automated test code and a white-box test code for subsequent regression testing or iterative testing.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (10)

1. A method of testing, comprising:
receiving a test request, acquiring a tested application and a test case according to the test request, and adding a Java Agent into a virtual machine parameter corresponding to the tested application;
before loading the class file of the tested application, according to the Java Agent and based on a byte code enhancement technology, carrying out byte code modification on a target class of the tested application, wherein the target class comprises: a remotely invoked class, a class to which persistent data relates;
calling a target method contained in the target class in the process of testing the tested application by using the test case to obtain running data corresponding to the target method;
and determining test data corresponding to the test case according to the acquired operation data, and storing the test data.
2. The method of claim 1, wherein the bytecode modification of the target class of the application under test according to the Java Agent and based on a bytecode enhancement technology includes:
before a class loader loads the class file of the tested application, the class file of the tested application is obtained through the Java Ag ent;
acquiring the target class from the class file of the tested application;
adding an interceptor to the target class to enable modification of the bytecode of the target class based on bytecode enhancement techniques.
3. The method according to claim 2, wherein the calling the target method included in the target class to obtain the running data corresponding to the target method comprises:
and when the target method is called, calling the before and after methods of the interceptor, and acquiring the parameter input data, the parameter output data and the data type corresponding to the target method.
4. The method of claim 3, wherein before obtaining the ingress data, egress data, and data type corresponding to the target method, the method further comprises:
and defining a data acquisition rule corresponding to the Java Agent so as to acquire the input parameter data, the output parameter data and the data type corresponding to the target method according to the data acquisition rule.
5. The method of claim 1, further comprising:
and in the process of testing the application to be tested by using the test case, if the remotely called class or the method contained in the remotely called class is monitored, collecting a calling link corresponding to the test case.
6. The method of claim 1, wherein said storing said test data comprises:
storing the test data in a database; and the number of the first and second groups,
and under the condition that the test data is real-time data, storing the test data into a message queue so as to display the test data or monitor the running of the application to be tested by utilizing the test data.
7. The method of any of claims 1 to 6, further comprising:
if the number of the applications is multiple, adding the Java Agent corresponding to each application into the virtual machine parameter corresponding to each application; and the number of the first and second groups,
and storing the Java Agent information corresponding to each application into a database.
8. A test apparatus, comprising:
the deployment module is used for receiving a test request, acquiring a tested application and a test case according to the test request, and adding Java agents into the virtual machine parameters corresponding to the tested application;
the Agent module is used for modifying the bytecode of the target class of the tested application according to the Java Agent and based on a bytecode enhancement technology before loading the class file of the tested application, wherein the target class comprises: a remotely invoked class, a class to which persistent data relates;
the calling module is used for calling a target method contained in the target class in the process of testing the application to be tested by using the test case to acquire running data corresponding to the target method;
and the determining module is used for determining the test data corresponding to the test case according to the acquired running data and storing the test data.
9. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-7.
10. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-7.
CN202110413114.9A 2021-04-16 2021-04-16 Test method and test device Pending CN113076253A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110413114.9A CN113076253A (en) 2021-04-16 2021-04-16 Test method and test device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110413114.9A CN113076253A (en) 2021-04-16 2021-04-16 Test method and test device

Publications (1)

Publication Number Publication Date
CN113076253A true CN113076253A (en) 2021-07-06

Family

ID=76617811

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110413114.9A Pending CN113076253A (en) 2021-04-16 2021-04-16 Test method and test device

Country Status (1)

Country Link
CN (1) CN113076253A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113688031A (en) * 2021-07-15 2021-11-23 上海浦东发展银行股份有限公司 Testing positioning method based on byte code enhancement technology
CN113986736A (en) * 2021-10-29 2022-01-28 重庆富民银行股份有限公司 Slow SQL monitoring system and method based on JAVA proxy and bytecode enhancement
CN115981962A (en) * 2022-12-30 2023-04-18 北京基调网络股份有限公司 Thread pool monitoring method and device, electronic equipment and storage medium
CN117130917A (en) * 2023-08-28 2023-11-28 北京安普诺信息技术有限公司 Ash box testing method, device and system for containerized Java application

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113688031A (en) * 2021-07-15 2021-11-23 上海浦东发展银行股份有限公司 Testing positioning method based on byte code enhancement technology
CN113688031B (en) * 2021-07-15 2024-03-26 上海浦东发展银行股份有限公司 Test positioning method based on byte code enhancement technology
CN113986736A (en) * 2021-10-29 2022-01-28 重庆富民银行股份有限公司 Slow SQL monitoring system and method based on JAVA proxy and bytecode enhancement
CN115981962A (en) * 2022-12-30 2023-04-18 北京基调网络股份有限公司 Thread pool monitoring method and device, electronic equipment and storage medium
CN115981962B (en) * 2022-12-30 2024-03-12 北京基调网络股份有限公司 Thread pool monitoring method and device, electronic equipment and storage medium
CN117130917A (en) * 2023-08-28 2023-11-28 北京安普诺信息技术有限公司 Ash box testing method, device and system for containerized Java application
CN117130917B (en) * 2023-08-28 2024-01-23 北京安普诺信息技术有限公司 Ash box testing method, device and system for containerized Java application

Similar Documents

Publication Publication Date Title
CN113076253A (en) Test method and test device
CN111597110B (en) Page test method and device, electronic equipment and storage medium
CN107644075B (en) Method and device for collecting page information
CN110858172A (en) Automatic test code generation method and device
US11934287B2 (en) Method, electronic device and computer program product for processing data
CN112631590B (en) Component library generation method, device, electronic equipment and computer readable medium
CN110598135A (en) Network request processing method and device, computer readable medium and electronic equipment
CN112948272A (en) Production environment-based data test system function method and device and related equipment
CN110457132B (en) Method and device for creating functional object and terminal equipment
CN115357761A (en) Link tracking method and device, electronic equipment and storage medium
CN113138768B (en) Application package generation method and device, electronic equipment and readable storage medium
CN113360377B (en) Test method and device
CN112395098A (en) Application program interface calling method and device, storage medium and electronic equipment
CN115705190A (en) Method and device for determining dependence degree
CN111414154A (en) Method and device for front-end development, electronic equipment and storage medium
CN115291928A (en) Task automatic integration method and device of multiple technology stacks and electronic equipment
CN114116509A (en) Program analysis method, program analysis device, electronic device, and storage medium
CN111488286B (en) Method and device for independently developing Android modules
CN115202973A (en) Application running state determining method and device, electronic equipment and medium
CN113434382A (en) Database performance monitoring method and device, electronic equipment and computer readable medium
CN113760693A (en) Method and apparatus for local debugging of microservice systems
CN113342633B (en) Performance test method and device
CN115563183B (en) Query method, query device and program product
CN113704016B (en) Cloud function component diagnosis method, device, equipment and storage medium
CN117472716A (en) Non-invasive application log acquisition method, device, equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination