Method for automatically developing secondary development
By using static encapsulation and unit testing to generate extension packages, the problem of inconsistent package versions in JMeter functions or JavaSamples secondary development is solved, realizing an automated secondary development process and improving development efficiency and tool execution stability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-08
- Publication Date
- 2026-03-24
AI Technical Summary
In existing technologies, when secondary development of JMeter functions or JavaSampler, there are problems such as inconsistent versions of imported packages, inconsistent coding styles, and inconsistent versions of dependent packages, which cause the load testing tool to fail to execute.
By acquiring the code to be tested, statically encapsulating it, and calling static methods, generating functions or request modules based on pre-integrated JMeter function templates or JavaSampler templates, generating unit test cases, and automatically generating extension packages when the tests pass, and exporting them to the target path.
It simplifies the operation steps for developers and testers, improves efficiency, ensures consistency in package versions and writing style, avoids dependency conflicts, and realizes automated secondary development processes.
Smart Images

Figure CN115344480B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of software testing, and particularly relates to a method for automatically performing secondary development. BACKGROUND
[0002] In the process of interface testing or stress testing of interface class requirements, the performance of some middleware and code classes cannot be tested. The common method in the prior art is to add an http package to perform stress testing through http calling. In the testing process, external jar packages need to be called to meet the running requirements of the internal logic of the tested interface or code. However, for interfaces that cannot provide http api, regular stress testing cannot be performed, and stress testing needs to be performed through jmeter secondary development.
[0003] The prior art secondary development process of jmeter functions or javasamplers is to write codes locally, establish a maven project through an idea tool, load the dependent packages required by jmeter functions or javasamplers, and then package and upload to the target jmeter. The package thus packaged has the problems of inconsistent introduced package versions, inconsistent writing styles, inconsistent dependent package versions, and possible conflicts with the dependent packages of the stress testing platform jmeter, which causes the jmeter tool to be unable to execute. SUMMARY
[0004] In order to at least partially overcome the problems of inconsistent introduced package versions, inconsistent writing styles, and inconsistent dependent package versions in the secondary development of jmeter functions or javasamplers in the related art, the present application provides a method for automatically performing secondary development.
[0005] The scheme of the present application is as follows:
[0006] A method for automatically performing secondary development, comprising:
[0007] obtaining a code to be tested; the code to be tested is provided by a user;
[0008] statically encapsulating the code to be tested, and calling through a corresponding static method;
[0009] generating a jmeter function or a javasampler based on a pre-integrated jmeter function template or a javasampler template referring to the called static method;
[0010] generating a unit test case, and performing unit testing on the generated jmeter function or javasampler;
[0011] When the test is passed, generate the extended package after secondary development;
[0012] Export the extended package to a target path;
[0013] Restart to obtain the jmeter function or javasampler after secondary development.
[0014] Preferably, in an implementable manner of the application, the obtaining of the code to be tested comprises:
[0015] Receiving an external jar package uploaded by a user through an external interface, and parsing the external jar package through a parsing tool to obtain readable code to be tested.
[0016] Preferably, in an implementable manner of the application, the obtaining of the code to be tested further comprises:
[0017] Receiving code to be tested copied by a user to a coding area; the coding area is configured with a custom tool class; the custom tool class is used to simplify code writing of the coding area or expand functions of the coding area.
[0018] Preferably, in an implementable manner of the application, the exporting of the extended package to a target path comprises:
[0019] Exporting the extended package to a jmeter or lib or ext directory, or exporting the extended package to a remote system.
[0020] Preferably, in an implementable manner of the application, the jmeter function or javasampler is generated based on a Maven tool.
[0021] The technical scheme provided in the application can have the following beneficial effects: the method for automatically performing secondary development in the application comprises the following steps: obtaining to-be-tested code; the to-be-tested code is provided by a user. The to-be-tested code is statically encapsulated, and a corresponding static method is called. A jmeter function or a javasampler is generated based on a pre-integrated jmeter function template or javasampler template reference to the called static method. A unit test case is generated, and the generated jmeter function or javasampler is unit tested. When the test passes, an extended package after secondary development is generated, the extended package is exported to a target path, and a jmeter function or javasampler after secondary development is obtained after restarting. In the application, the user only needs to provide the to-be-tested code, and the system automatically injects the to-be-tested code into the pre-integrated jmeter function template or javasampler template, and automatically generates an extended package when the subsequent test passes, and exports the extended package to the target path, thereby simplifying the operation steps of the development or test personnel and improving the efficiency.
[0022] It should be understood that the foregoing general description and the following detailed description are only exemplary and explanatory, and are not limiting to the application. BRIEF DESCRIPTION OF DRAWINGS
[0023] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the application and serve to explain the principles of the application, together with the description.
[0024] Figure 1 The application provides a method for automatically performing secondary development. DETAILED DESCRIPTION
[0025] The exemplary embodiments will be described in detail herein with reference to the attached drawings. The following description is only exemplary and explanatory, and is not limiting to the application.
[0026] A method for automatically performing secondary development, referring to Figure 1 , comprises the following steps:
[0027] S11: obtaining to-be-tested code; the to-be-tested code is provided by a user;
[0028] The to-be-tested code is obtained, comprising the following steps:
[0029] Receiving the external jar package uploaded by the user through the external interface, and parsing the readable test code through the parsing tool.
[0030] The user uploads the required external jar package through the external interface, and parses the readable java code, i.e., the test code, through the jad parsing tool.
[0031] Alternatively, receiving the test code copied to the coding area by the user; the coding area is configured with a customized tool class; the customized tool class is used to simplify the code writing of the coding area or extend the function of the coding area.
[0032] If the user does not need to call the external interface, only the code block is tested for performance, the code to be tested can be copied to the coding area.
[0033] In this embodiment, the user only needs to upload the required external jar package through the external interface, or directly copy the test code to the coding area, and the subsequent processes are automatically completed, simplifying the operation steps of the development or test personnel.
[0034] S12: statically encapsulating the test code, and calling the corresponding static method;
[0035] In this embodiment, the test code is statically encapsulated to facilitate direct reference by the jmeter class. Jmeter is a pressure testing tool developed based on Java, and can also be used as an interface class automatic testing tool.
[0036] S13: referencing the called static method based on the pre-integrated jmeter function template or javasampler template to generate jmeter function or javasampler;
[0037] Jmeter function: based on a function module inside the jmeter tool;
[0038] Javasampler: based on a request module inside the jmeter tool.
[0039] In this embodiment, the jmeter function template or javasampler template is pre-integrated, and the statically encapsulated test code is injected into the jmeter function template or javasampler template to obtain the jmeter function or javasampler.
[0040] Preferably, the jmeter function or javasampler is generated based on the Maven tool.
[0041] The Maven tool includes project building, management, jar package downloading, project packaging tool, etc.
[0042] S14: Generate unit test cases and perform unit tests on the generated JMeter functions or JavaSamples;
[0043] Preferably, in this embodiment, unit test cases are generated using JUnit, and unit tests are performed on the generated JMeter functions or JavaSamples. JUnit is a unit testing tool used to test whether classes or methods in Java development meet expectations.
[0044] S15: Upon successful testing, generate the extended package for secondary development;
[0045] In this embodiment, the generated extension package is a jar extension package.
[0046] S16: Export the expansion pack to the target path;
[0047] In this embodiment, the extension package is exported to the jmeter, lib, or ext directory, or exported to the remote system agent.
[0048] S17: Restart to obtain the JMeter function or JavaSample after secondary development.
[0049] Restarting the JMeter tool will provide you with the modified JMeter functions or JavaSampler.
[0050] The method for automatically performing secondary development on JMeter functions or Javasamplers in this embodiment includes: obtaining the code to be tested (provided by the user); statically encapsulating the code to be tested and calling it through the corresponding static method; generating the JMeter function or Javasampler based on the referenced static method in a pre-integrated JMeter function template or Javasampler template; generating unit test cases and performing unit tests on the generated JMeter function or Javasampler; generating a secondary development extension package when the test passes, exporting the extension package to the target path, and restarting to obtain the secondary development JMeter function or Javasampler. In this embodiment, the user only needs to provide the code to be tested, and the system will automatically inject the code into the pre-integrated JMeter function template or Javasampler template, and automatically generate an extension package and export it to the target path when the subsequent test passes, simplifying the operation steps for developers or testers and improving efficiency.
[0051] It is understood that the same or similar parts in the above embodiments can be referred to each other, and the contents not described in detail in some embodiments can be referred to the same or similar contents in other embodiments.
[0052] It should be noted that in the description of this application, the terms "first," "second," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance. Furthermore, in the description of this application, unless otherwise stated, "a plurality of" means at least two.
[0053] Any process or method described in the flowchart or otherwise herein can be understood as representing a module, segment, or portion of code comprising one or more executable instructions for implementing a particular logical function or process, and the scope of the preferred embodiments of this application includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order depending on the function involved, as will be understood by those skilled in the art to which embodiments of this application pertain.
[0054] It should be understood that various parts of this application can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented using software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.
[0055] Those skilled in the art will understand that all or part of the steps of the methods in the above embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, the program includes one or a combination of the steps of the method embodiments.
[0056] Furthermore, the functional units in the various embodiments of this application can be integrated into a processing module, or each unit can exist physically separately, or two or more units can be integrated into a module. The integrated module can be implemented in hardware or as a software functional module. If the integrated module is implemented as a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium.
[0057] The storage media mentioned above can be read-only memory, disk, or optical disk, etc.
[0058] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0059] Although embodiments of this application have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting this application. Those skilled in the art can make changes, modifications, substitutions and variations to the above embodiments within the scope of this application.
Claims
1. A method for automatically performing secondary development, characterized in that, include: Obtain the code to be tested; the code to be tested is provided by the user; The code to be tested is statically encapsulated and called through the corresponding static method; Generate JMeter functions or Javasamplers based on pre-integrated JMeter function templates or Javasampler templates that reference the invoked static methods; Generate unit test cases and perform unit tests on the generated JMeter functions or JavaSamples; Upon successful testing, a modified extension package will be generated. Export the aforementioned extension package to the target path; Restart the program to obtain the modified JMeter function or JavaSample. The process of obtaining the code to be tested also includes: Receives test code copied by the user to the encoding area; the encoding area is configured with custom utility classes. The custom utility class is used to simplify the code writing of the encoding area or extend the functionality of the encoding area.
2. The method according to claim 1, characterized in that, The process of obtaining the code to be tested includes: It receives external JAR packages uploaded by users through external interfaces, parses them using a parsing tool, and obtains readable test code.
3. The method according to claim 1, characterized in that, The step of exporting the extension package to the target path includes: Export the aforementioned extension package to the jmeter, lib, or ext directory, or export it to a remote system.
4. The method according to claim 1, characterized in that, The JMeter function or JavaSampler is generated based on the Maven tool.
Citation Information
Patent Citations
Unit test code generation method, unit test method and unit test device
CN113495826A