Service testing method, service testing device, electronic device, and storage medium
By instrumenting the program under test to form a tracing plugin, the call stack is recorded and generated, which solves the problem of low testing efficiency for changes in mobile device business code in existing technologies, and enables accurate determination of the scope and coverage of the impact of business modifications.
Patent Information
- Application Number
- CN202111374445.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-19
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2041-11-19
AI Technical Summary
When testing business code changes on mobile devices, existing technologies require comparing source code to determine the scope of the changes, which is inefficient.
By instrumenting components into the program under test to create a tracing plugin, the call information of business functions is recorded, and the call stack is generated using test cases to determine the business test results and coverage.
It improves testing efficiency, allows for a clear understanding of the impact of business modifications and the coverage of test cases, and helps testers determine the suitability of test cases.
Smart Images

Figure CN116149974B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of electronic equipment technology, specifically relating to a service testing method, a service testing device, an electronic device, and a storage medium. Background Technology
[0002] In related technologies, when making business modifications to a program, the modified business code needs to be tested to ensure normal operation. However, when testing on mobile devices, determining the scope of the impact of the modified business code requires comparing the source code, which is less efficient. Summary of the Invention
[0003] The purpose of this application is to provide a service testing method, service testing device, electronic device, and storage medium that can track the second call information of a service and improve testing efficiency.
[0004] Firstly, embodiments of this application provide a business testing method, including:
[0005] Obtain the program to be tested, which includes multiple business functions. The beginning and end of each business function are instrumented with software development kits, forming a tracing plugin in the program to be tested. The tracing plugin can record the first call information of the business functions called during the operation of the program to be tested.
[0006] By using pre-set test cases, the business logic of the program to be tested is run, and the second call information of the business functions by the test cases is obtained.
[0007] The business test results of the program to be tested are determined based on the second call information. The test results include the test coverage of the business functions in the program to be tested whose business code has been modified.
[0008] Secondly, embodiments of this application provide a service testing apparatus, including:
[0009] The acquisition module is used to acquire the program to be tested, which includes multiple business functions. The beginning and end of each business function are instrumented with software development kits, forming a tracing plugin in the program to be tested. The tracing plugin can record the first call information of the business functions called during the operation of the program to be tested.
[0010] The testing module is used to run the business logic of the program to be tested using preset test cases and to obtain the second call information of the business functions by the test cases.
[0011] The determination module is used to determine the business test results of the program to be tested based on the second call information. The test results include the test coverage of the business functions in the program to be tested whose business code has been modified by the test cases.
[0012] Thirdly, embodiments of this application provide an electronic device, including a processor, a memory, and a program or instructions stored in the memory and executable on the processor, wherein the program or instructions, when executed by the processor, implement the steps of the method as described in the first aspect.
[0013] Fourthly, embodiments of this application provide a readable storage medium on which a program or instructions are stored, which, when executed by a processor, implement the steps of the method as described in the first aspect.
[0014] Fifthly, embodiments of this application provide a chip including a processor and a communication interface coupled to the processor, the processor being used to run programs or instructions to implement the steps of the method as described in the first aspect.
[0015] In this embodiment, the program to be tested can be a new program obtained by modifying the business logic based on the original program. During the compilation and configuration of the program to be tested, the start and end points of all business functions in the program to be tested are instrumented, thereby forming a tracing plugin based on the SDK (Software Development Kit) in the program to be tested. Specifically, the tracing plugin is an integrated general instrumentation tool SDK. Through the instrumentation tool SDK, the start and end points of the business code in the gradle (a dependency management tool) file of the program under test can be used to construct a trace file within a specified range, thereby enabling the tracing and output of the first call information of the business functions of the program to be tested.
[0016] During the testing of the program under test, the business logic of the program is run using pre-defined test cases. After execution, the tracing plugin outputs the second call information of the business functions during the business implementation process and saves it to a local file. This second call information allows us to obtain the call chain of the business functions during the business implementation, thus obtaining accurate business test results. Furthermore, because these business test results include the call chain of the business functions, the impact scope of business modifications can be intuitively obtained. Additionally, the business test results include test coverage, which directly reflects the test results of the test cases on the program under test, helping testers determine the appropriateness of the test cases and significantly improving testing efficiency. Attached Figure Description
[0017] Figure 1One of the flowcharts of a business testing method according to an embodiment of this application is shown;
[0018] Figure 2 A second flowchart of a business testing method according to an embodiment of this application is shown;
[0019] Figure 3 A structural block diagram of a service testing apparatus according to an embodiment of this application is shown;
[0020] Figure 4 A structural block diagram of an electronic device according to an embodiment of this application is shown;
[0021] Figure 5 A schematic diagram of the hardware structure of an electronic device to implement an embodiment of this application. Detailed Implementation
[0022] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application are within the scope of protection of this application.
[0023] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.
[0024] The following description, in conjunction with the accompanying drawings, details the testing methods and apparatus, electronic devices, and storage media of the shooting program provided in this application, through specific embodiments and application scenarios.
[0025] In some embodiments of this application, a business testing method is provided. Figure 1 One of the flowcharts of a service testing method according to an embodiment of this application is shown, such as... Figure 1 As shown, the method includes:
[0026] Step 102, obtain the program to be tested;
[0027] In step 102, the program to be tested includes multiple business functions. The beginning and end of each business function are instrumented by the software development kit, forming a tracing plugin in the program to be tested. The tracing plugin can record the first call information of the business functions called during the operation of the program to be tested.
[0028] Step 104: Run the business logic of the program to be tested using preset test cases to obtain the second call information of the business functions by the test cases;
[0029] Step 106: Determine the business test results of the program to be tested based on the second call information;
[0030] In step 106, the test results include the test coverage of the business functions in the program under test for which the business code has been modified.
[0031] In this embodiment of the application, the program to be tested can be a new program obtained by modifying the business logic based on the original program. The program to be tested includes a tracing plugin, which is specifically an integrated general instrumentation tool SDK. Through the instrumentation tool SDK, it is possible to set the start and end of the business code in the gradle (a dependency management tool) file of the program under test to a trace file within a specified range, thereby enabling the tracing and output of the first call information of the business function of the program under test.
[0032] Specifically, when compiling and configuring the program to be tested, instrumentation is performed at the beginning and end of each business function. After instrumentation, test cases are run automatically through the UI (User Interface). During program execution, instrumentation data, that is, the first call information of the business function, is written to a local file.
[0033] During the testing of the program under test, the business logic of the program is run using pre-defined test cases. After execution, the tracing plugin outputs the second call information of the business functions during the business implementation process and saves it to a local file. This second call information allows us to obtain the call chain of the business functions during the business implementation, thus obtaining accurate business test results. Furthermore, because these business test results include the call chain of the business functions, the impact scope of business modifications can be intuitively obtained. Additionally, the business test results include test coverage, which directly reflects the test results of the test cases on the program under test, helping testers determine the appropriateness of the test cases and significantly improving testing efficiency.
[0034] In some embodiments of this application, the second invocation information includes the function name of the business function invoked by the test case and the timestamp of the business function;
[0035] The business test results of the program to be tested are determined based on the second call information, including:
[0036] A call stack is generated based on the timestamp and function name. The call stack includes a call chain of multiple function nodes, and the business function includes function nodes.
[0037] Determine the business test results based on the call stack.
[0038] In this embodiment of the application, the second invocation information specifically includes the function name of the business function called by the test case during the process of testing the program under test through the test case, and the timestamp generated when the business function is called.
[0039] Specifically, the tracking plugin tracks the business functions called during business execution. When a business function is called, the function name is recorded, and timestamps are recorded at the beginning and end of the business function.
[0040] Based on the function names and timestamps of the multiple business functions that are called, a call stack corresponding to these business functions can be formed. Specifically, the call stack includes a call chain of multiple function nodes, and each function node in the call stack is a business function that is called.
[0041] By analyzing timestamps and the call relationships of business functions, the order in which business functions are called during the business implementation process can be established, forming a call chain of business functions (function nodes) and a change in the call stack. Based on this call stack, the calls to the business implementation can be clearly identified, allowing for a comparison of the impact scope of business modifications and improving testing efficiency.
[0042] In some embodiments of this application, the business test result is determined based on the call stack, including:
[0043] Determine the first call stack of the program to be tested and the second call stack of the control program, wherein the program to be tested is obtained by modifying the control program according to business logic.
[0044] The business test results are determined based on the comparison between the first and second call stacks.
[0045] In this embodiment of the application, during the testing of the business logic of the program under test, a first call stack of the program under test and a second call stack of the control program can be determined. It is understood that the code of the program under test is specifically the business code that has undergone "business modification," while the code of the control program is specifically the business code before the "business modification."
[0046] Therefore, by comparing the first and second call stacks, the call chain of the business functions in the modified program can be determined, and the difference between the call chain of the business functions in the original program can be identified. This allows us to determine the scope of the impact of the modification and thus accurately express the business test results.
[0047] In some embodiments of this application, the business test result is determined based on the comparison result of the first call stack and the second call stack, including:
[0048] The distinguishing function node is determined based on the original function node in the second call stack and the current function node in the first call stack;
[0049] When distinguishing between new and deleted function nodes, recursively record the sub-functions of the distinguishing function node to obtain the business test results;
[0050] In the case of distinguishing between newly added and deleted function nodes, the function name and function parameters of the distinguishing function nodes are recursively recorded to obtain the business test results.
[0051] In this embodiment, the first call stack specifically refers to the call chain of function nodes in the test program during the implementation of business logic, and the second call stack specifically refers to the call chain of function nodes in the control program during the implementation of the same business logic. Therefore, by comparing whether the nodes in the two call chains are the same and whether the call order is the same, it can be determined whether any function nodes have been modified, i.e., the distinguishing function nodes can be identified.
[0052] Modifying the business logic code of the program under test will result in changes to the business functions within the program, such as adding or deleting function nodes. In other words, distinguishing function nodes includes adding new function nodes, meaning a new function node is added to the existing function node's call chain. Distinguishing function nodes also includes deleting function nodes, meaning an existing function node is removed from the existing function node's call chain.
[0053] For example, the call chain relationship can be identified by the "-" symbol. The absence of "-" indicates that the function node is a top-level function, while the presence of "-" indicates that the function node is a function called by the top-level function, and the functions are ordered in the order of their calls.
[0054] Specifically as follows:
[0055] 1xxxx.xxx.xx.xxx(xx.xx.xx); add
[0056] 2-yyyy.yyy.yy.yyy(yy.yy); modify
[0057] 3--zzzz.zzz.zzz.zzz <zzzz>delete
[0058] In this structure, line 1 represents the top-level function, line 2 represents the function called on line 1, and line 3 represents the function called on line 2. At the end of each function, the function's status is recorded: `add` indicates that the function node is newly added, `delete` indicates that the function node is deleted, and `modify` indicates that the function node has modified its parameters or name.
[0059] If the distinguishing function node is determined to be a newly added or deleted function node, then the distinguishing function node and its sub-functions are recursively processed and recorded. If the distinguishing function node is determined not to be a newly added or deleted function node, that is, a function node whose function parameters or function name have been modified, then the modified function name and function parameters of the distinguishing function node are recursively processed and recorded, resulting in the final business test result, thus achieving highly efficient program testing.
[0060] In some embodiments of this application, after determining the distinguishing function node in the current function node, the testing method further includes:
[0061] If the sub-function of the distinguishing function node is the same as the sub-function of the original function node, determine whether the distinguishing function node is a newly added function node or a deleted function node;
[0062] If the sub-functions of the distinguishing function node are different from the sub-functions of the original function node, the distinguishing function node is determined to be a newly added function.
[0063] In this embodiment, when determining the type of a distinguishing function node, the sub-functions of the current distinguishing function node and the original function node can be compared. It is understood that if a function node is a newly added function node, it should be a "new node" that has broken away from the original function node's link, and therefore its sub-functions are also new. Thus, when a distinguishing function node is a newly added function node, its sub-functions should be different from the sub-functions of the original function node.
[0064] If a function node is a deleted function node, then the function node is "missing" in the call chain relative to the function node in the second call stack. Therefore, there will be no situation where the sub-function domains of the different function nodes are the same as the original function nodes.
[0065] Therefore, if the sub-functions of the current distinguishing function node are the same as those of the original function node, it can be determined that the current distinguishing function node is neither a newly added function node nor a deleted function node.
[0066] When the sub-functions of the distinguishing function node are all different from the sub-functions of the original function node, it indicates that the distinguishing function node is not an original function node, and therefore it can be determined that the distinguishing function node is a newly added function node.
[0067] This application can accurately determine the type of function nodes by comparing whether the sub-functions of function nodes in the first call stack and the second call stack are the same, thereby improving the accuracy and efficiency of testing.
[0068] Specifically, a pre-defined function node call chain comparison tool can be used to compare the function node call chains of the first call stack and the second call stack. This tool parses the file output by the tracking plugin, uses the timestamps and call relationships of each business function to plot the call stack during the business implementation process, and compares the results to obtain the changes in the call stack.
[0069] Figure 2 A second flowchart of a service testing method according to an embodiment of this application is shown, such as... Figure 2 As shown, the process of comparing the first call stack and the second call stack includes:
[0070] Step 202: Determine whether the top-level function node has changed; if yes, proceed to step 208; otherwise, proceed to step 204.
[0071] Step 204: Determine if the recursive descendant function has changed; if yes, proceed to step 208; otherwise, proceed to step 206.
[0072] Step 206, the function remains unchanged;
[0073] Step 208, function change;
[0074] Step 210: Determine if the sub-functions are the same; if yes, proceed to step 212; otherwise, proceed to step 214.
[0075] Step 212, categorized as a function name change;
[0076] Step 214: Determine it as a newly added function;
[0077] Step 216: Recursively process all descendant functions of the newly added function;
[0078] Step 218: Determine the function to be deleted;
[0079] Step 220: Recursively delete all descendant functions of the function.
[0080] In some embodiments of this application, after determining the first call stack of the program to be tested and the second call stack of the control program, the testing method further includes:
[0081] Based on the comparison results of the first and second call stacks, the scope of impact of the business modification is determined.
[0082] In this embodiment, the scope of impact of the business modification can also be determined based on the comparison results of the first call stack and the second call stack. Specifically, the first call stack includes the program to be tested, that is, the call chain of the business functions during the execution of the business by the program after the business modification, and the second call stack includes the control program, that is, the call chain of the business functions when the program before the business modification executes the same business.
[0083] Therefore, by comparing the first and second call stacks, the distinguishing function nodes identified are the changes in business functions resulting from business modifications. These distinguishing function nodes represent the scope of impact of the business modifications. By confirming the scope of impact of the business modifications, testers can effectively locate the scope of regression testing and help developers understand and find the impact points involved in the changed code, thereby reducing the occurrence of bugs.
[0084] In some embodiments of this application, determining the business test result of the program to be tested based on the second invocation information further includes:
[0085] Based on the scope of impact, the first business function is determined in the program to be tested, wherein the first business function is the business function whose business code has been modified;
[0086] Based on the second call information, determine the second business function, wherein the second business function is the business function called by the test case;
[0087] The coverage rate is determined based on the first business function and the second business function.
[0088] In this embodiment of the application, the test results also include the test coverage of the test cases for the business functions whose business code has been modified.
[0089] Test coverage refers to the coverage of the first business function, which has changed business code, by the second business function called by the test case during the execution of the program under test. Test coverage can intuitively reflect the reliability of the test cases.
[0090] Specifically, test cases are automated testing tasks for program business logic and functionality. Essentially, they simulate the calls to software functions during daily use to test whether the business logic functions correctly. When the program under test is triggered by test cases, each function call in the program triggers the SDK plugin for that function to record the call event. This results in a function call record corresponding to the test case. This record can be used to identify which functions that modify business logic were called during the program's execution triggered by the test cases, allowing for the calculation of the test coverage for those modified business logic functions.
[0091] For example, the second business function called by the test case includes A, B, and C, while the business functions whose business code has been modified include A, B, C, and D. Therefore, the test coverage of this test case is 75%. By calculating the test coverage, testers can adjust test cases reasonably based on the test coverage, further improving testing efficiency.
[0092] In some embodiments of this application, obtaining the program to be tested includes:
[0093] Obtain the code to be tested and the tracing plugin, where the code to be tested includes business functions;
[0094] The test code and tracing plugin are packaged and compiled to obtain the program to be tested.
[0095] In this embodiment of the application, the code to be tested is the source code of the program to be tested. By adding a tracing plugin SDK for tracking the second call information of functions to the code to be tested and packaging and compiling it, the tracing plugin can automatically output the second call information of the business functions during the operation of the program to be tested, save it locally, and form the corresponding call stack.
[0096] It is understandable that the code to be tested (i.e., the new code after business modifications and the tracing plugin) and the reference code (i.e. the original code without business modifications and the tracing plugin) can be packaged separately to obtain the program to be tested and the reference program, thereby effectively determining the scope of business modifications and improving testing efficiency.
[0097] In some embodiments of this application, a business testing apparatus is provided. Figure 3 A structural block diagram of a service testing apparatus according to an embodiment of this application is shown, such as... Figure 3 As shown, the service testing device 300 includes:
[0098] The acquisition module 302 is used to acquire the program to be tested, wherein the program to be tested includes multiple business functions. The beginning and end of each business function are instrumented by the software development kit, forming a tracing plugin in the program to be tested. The tracing plugin can record the first call information of the business functions called during the operation of the program to be tested.
[0099] Test module 304 is used to run the business logic of the program to be tested using preset test cases and to obtain the second call information of the business functions by the test cases.
[0100] The determination module 306 is used to determine the business test results of the program to be tested based on the second call information. The test results include the test coverage of the business functions in the program to be tested whose business code has been modified by the test cases.
[0101] In this embodiment, the program to be tested can be a new program obtained by modifying the business logic based on the original program. During the compilation and configuration of the program to be tested, the start and end points of all business functions in the program to be tested are instrumented, thereby forming an SDK-based tracing plugin in the program to be tested. This tracing plugin is specifically an integrated general instrumentation tool SDK. Through the instrumentation tool SDK, the start and end points of the business code in the gradle (a dependency management tool) file of the program under test can be used to create a trace file within a specified range, thereby enabling the tracing and output of the first call information of the business functions of the program to be tested.
[0102] Specifically, instrumentation is performed at the beginning and end of each business function. After instrumentation, test cases are run automatically via UI (User Interface). During program execution, instrumentation data, i.e., the first call information of the business function, is written to a local file.
[0103] During the testing of the program under test, the business logic of the program is run using pre-defined test cases. After execution, the tracing plugin outputs the second call information of the business functions during the business implementation process and saves it to a local file. This second call information allows us to obtain the call chain of the business functions during the business implementation, thus obtaining accurate business test results. Furthermore, because these business test results include the call chain of the business functions, the impact scope of business modifications can be intuitively obtained. Additionally, the business test results include test coverage, which directly reflects the test results of the test cases on the program under test, helping testers determine the appropriateness of the test cases and significantly improving testing efficiency.
[0104] In some embodiments of this application, the second invocation information includes the function name of the business function and the timestamp of the business function;
[0105] The business testing equipment also includes:
[0106] The generation module is used to generate a call stack based on timestamps and function names. The call stack includes a call chain of multiple function nodes, and the business function includes function nodes.
[0107] The module is also used to determine the results of business tests based on the call stack.
[0108] In this embodiment, the second call information specifically includes the function name of the business function called by the test case during the testing of the program under test, and the timestamp generated when the called business function is called. Based on the timestamp and the call relationship of the business functions, the call order of the business functions during the business implementation process can be formed, thus forming a call chain of business functions (function nodes) and a change in the call stack. Based on this call stack, the calls of the business implementation can be intuitively determined, thereby comparing the impact range of business modifications and improving testing efficiency.
[0109] In some embodiments of this application, the determining module is further configured to:
[0110] Determine the first call stack of the program to be tested and the second call stack of the control program, wherein the program to be tested is obtained by modifying the control program according to business logic.
[0111] The business test results are determined based on the comparison between the first and second call stacks.
[0112] In this embodiment of the application, during the testing of the business functions of the program under test, a first call stack of the program under test and a second call stack of the control program can be determined. By comparing the first and second call stacks, the difference between the call chain of the business functions in the modified program and the call chain of the business functions in the original program can be determined, thereby determining the scope of the impact of the modification and accurately expressing the business test results.
[0113] In some embodiments of this application, the determining module is further configured to determine the distinguishing function node based on the original function node in the second call stack and the current function node in the first call stack;
[0114] The testing module is also used to recursively record the sub-functions of the distinguishing function node when the distinguishing function node is a newly added or deleted function node, and obtain the business test results; when the distinguishing function node is neither a newly added nor a deleted function node, it recursively records the function name and function parameters of the distinguishing function node, and obtains the business test results.
[0115] In this embodiment, the first call stack specifically refers to the call chain of function nodes in the test program during the implementation of business logic, and the second call stack specifically refers to the call chain of function nodes in the control program during the implementation of the same business logic. Therefore, by comparing whether the nodes in the two call chains are the same and whether the call order is the same, it can be determined whether any function nodes have been modified, i.e., the distinguishing function nodes can be identified.
[0116] If the distinguishing function node is determined to be a newly added or deleted function node, then the distinguishing function node and its sub-functions are recursively processed and recorded. If the distinguishing function node is determined not to be a newly added or deleted function node, that is, a function node whose function parameters or function name have been modified, then the modified function name and function parameters of the distinguishing function node are recursively processed and recorded, resulting in the final business test result, thus achieving highly efficient program testing.
[0117] In some embodiments of this application, the determining module is further configured to:
[0118] If the sub-function of the distinguishing function node is the same as the sub-function of the original function node, determine whether the distinguishing function node is a newly added function node or a deleted function node;
[0119] If the sub-functions of the distinguishing function node are different from the sub-functions of the original function node, the distinguishing function node is determined to be a newly added function.
[0120] In this embodiment, when determining the type of a distinguishing function node, the sub-functions of the current distinguishing function node and the original function node can be compared. It is understood that if a function node is a newly added function node, it should be a "new node" detached from the original function node chain, and therefore its sub-functions are also new. Thus, when a distinguishing function node is a newly added function node, its sub-functions should be different from those of the original function node. By comparing the sub-functions of function nodes in the first call stack and the second call stack, the type of the distinguishing function node can be accurately determined, thereby improving testing accuracy and efficiency.
[0121] In some embodiments of this application, the determining module is further configured to determine the scope of impact of the business modification based on the comparison results of the first call stack and the second call stack.
[0122] In this embodiment, the scope of impact of the business modification can also be determined based on the comparison results of the first call stack and the second call stack. By comparing the first call stack and the second call stack, the distinguishing function nodes identified, that is, the changes in business functions caused by the business modification, constitute the scope of impact of the business modification. By confirming the scope of impact of the business modification, testers can effectively locate the scope of regression testing and developers can understand and find the impact points involved in the changed code, thereby reducing the occurrence of bugs.
[0123] In some embodiments of this application, the determining module is further configured to determine a first business function in the program to be tested based on the scope of influence, wherein the first business function is a business function whose business code has been modified;
[0124] The determination module is also used to determine the second business function based on the second call information, wherein the second business function is the business function called by the test case;
[0125] The determination module is also used to determine the coverage rate based on the first business function and the second business function.
[0126] In this embodiment, during the execution of the program under test triggered by test cases, when a function is called in the program under test, the SDK plugin of that function will be triggered to record the function call event. This results in the function call record corresponding to the test case. Through this record, it is possible to identify which functions that modify business code are called during the execution of the program under test triggered by the test cases. This allows for the calculation of the test coverage of the modified business code, enabling testers to reasonably adjust the test cases based on the test coverage and further improve testing efficiency.
[0127] In some embodiments of this application, the acquisition module is further configured to acquire the code to be tested and the tracing plugin, wherein the code to be tested includes business functions;
[0128] The business testing equipment also includes:
[0129] The compilation module is used to package and compile the test code and tracing plugin to obtain the program to be tested.
[0130] In this embodiment, the code to be tested is the source code of the program to be tested. By adding a tracing plugin SDK for tracking function call information to the code to be tested and packaging and compiling it, the tracing plugin can automatically output the call information of business functions during the execution of the business process, save it locally, and form a corresponding call stack. The code to be tested (the new code after business modifications) and the tracing plugin are packaged separately, along with the control code (the original code without business modifications) and the tracing plugin, resulting in the program to be tested and the control program respectively. This effectively determines the scope of business modifications and improves testing efficiency.
[0131] The business testing device in this application embodiment can be a device, or a component, integrated circuit, or chip in a terminal. The device can be a mobile electronic device or a non-mobile electronic device. For example, mobile electronic devices can be mobile phones, tablets, laptops, PDAs, in-vehicle electronic devices, wearable devices, ultra-mobile personal computers (UMPCs), netbooks, or personal digital assistants (PDAs), etc., while non-mobile electronic devices can be servers, network-attached storage (NAS), personal computers (PCs), televisions (TVs), ATMs, or self-service machines, etc. This application embodiment does not impose specific limitations.
[0132] The service testing device in this application embodiment can be a device with an operating system. This operating system can be Android, iOS, or other possible operating systems; this application embodiment does not specifically limit its use.
[0133] The business testing apparatus provided in this application embodiment can implement all the processes implemented in the above method embodiments, and will not be described again here to avoid repetition.
[0134] Optionally, embodiments of this application also provide an electronic device 400. Figure 4 A structural block diagram of an electronic device according to an embodiment of this application is shown, such as... Figure 4 As shown, it includes a processor 402, a memory 404, and a program or instructions stored in the memory 404 that can run on the processor 402. When the program or instructions are executed by the processor 402, they implement the various processes of the above method embodiments and achieve the same technical effects. To avoid repetition, they will not be described again here.
[0135] It should be noted that the electronic devices in the embodiments of this application include the aforementioned mobile electronic devices and non-mobile electronic devices.
[0136] Figure 5 A schematic diagram of the hardware structure of an electronic device to implement an embodiment of this application.
[0137] The electronic device 500 includes, but is not limited to, components such as: radio frequency unit 501, network module 502, audio output unit 503, input unit 504, sensor 505, display unit 506, user input unit 507, interface unit 508, memory 509, and processor 510.
[0138] Those skilled in the art will understand that the electronic device 500 may also include a power supply (such as a battery) for supplying power to various components. The power supply may be logically connected to the processor 510 through a power management system, thereby enabling functions such as managing charging, discharging, and power consumption through the power management system. Figure 5 The electronic device structure shown does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown, or combine certain components, or have different component arrangements, which will not be elaborated here.
[0139] The processor 510 is used to acquire the program to be tested, which includes multiple business functions. Each business function has its start and end instrumented with a software development kit (SDK) to form a tracing plugin in the program to be tested. The tracing plugin can record the first call information of the business functions called during the operation of the program to be tested. The processor then runs the business functions of the program to be tested using preset test cases to acquire the second call information of the business functions. Based on the second call information, the processor determines the business test results of the program to be tested, including the test coverage of the business functions whose business code has been modified in the program to be tested.
[0140] Optionally, the second call information includes the function name of the business function called by the test case and the timestamp of the business function; the processor 510 is also used to generate a call stack based on the timestamp and the function name, wherein the call stack includes a call chain of multiple function nodes, and the business function includes function nodes; and determine the business test result based on the call stack.
[0141] Optionally, the processor 510 is further configured to determine a first call stack of the program to be tested and a second call stack of the control program, wherein the program to be tested is obtained by modifying the control program for business purposes; and to determine the business test result based on the comparison result of the first call stack and the second call stack.
[0142] Optionally, the processor 510 is further configured to determine the distinguishing function node based on the original function node in the second call stack and the current function node in the first call stack; if the distinguishing function node is a newly added function node or a deleted function node, recursively record the sub-functions of the distinguishing function node to obtain the business test results; if the distinguishing function node is neither a newly added function node nor a deleted function node, recursively record the function name and function parameters of the distinguishing function node to obtain the business test results.
[0143] Optionally, the processor 510 is further configured to determine whether the distinguishing function node is a newly added function node or a deleted function node when the sub-function of the distinguishing function node is the same as the sub-function of the original function node; and to determine whether the distinguishing function node is a newly added function when the sub-function of the distinguishing function node is different from the sub-function of the original function node.
[0144] Optionally, the processor 510 is also configured to determine the scope of impact of the business modification based on the comparison results of the first call stack and the second call stack.
[0145] Optionally, the processor 510 is further configured to, based on the scope of influence, determine a first business function in the program to be tested, wherein the first business function is a business function whose business code has been modified; determine a second business function based on second call information, wherein the second business function is a business function called by the test case; and determine coverage based on the first business function and the second business function.
[0146] Optionally, the processor 510 is also used to acquire the code to be tested and the tracing plugin, wherein the code to be tested includes business functions; and to package and compile the test code and the tracing plugin to obtain the program to be tested.
[0147] In this embodiment, the program to be tested can be a new program obtained by modifying the business logic based on the original program. During the compilation and configuration of the program to be tested, the start and end points of all business functions in the program to be tested are instrumented, thereby forming an SDK-based tracing plugin in the program to be tested. This tracing plugin is specifically an integrated general instrumentation tool SDK. Through the instrumentation tool SDK, the start and end points of the business code in the gradle (a dependency management tool) file of the program under test can be used to create a trace file within a specified range, thereby enabling the tracing and output of the first call information of the business functions of the program to be tested.
[0148] During the testing of the program under test, the business logic of the program is run using pre-defined test cases. After execution, the tracing plugin outputs the second call information of the business functions during the business implementation process and saves it to a local file. This second call information allows us to obtain the call chain of the business functions during the business implementation, thus obtaining accurate business test results. Furthermore, because these business test results include the call chain of the business functions, the impact scope of business modifications can be intuitively obtained. Additionally, the business test results include test coverage, which directly reflects the test results of the test cases on the program under test, helping testers determine the appropriateness of the test cases and significantly improving testing efficiency.
[0149] It should be understood that, in the embodiments of this application, the input unit 504 may include a graphics processing unit (GPU) 5041 and a microphone 5042. The graphics processing unit 5041 processes image data of still pictures or videos obtained by an image capture device (such as a camera) in video capture mode or image capture mode.
[0150] The display unit 506 may include a display panel 5061, which may be configured using a liquid crystal display, organic light-emitting diode, or other similar methods. The user input unit 507 includes a touch panel 5071 and other input devices 5072. The touch panel 5071 is also called a touchscreen. The touch panel 5071 may include a touch detection device and a touch controller. Other input devices 5072 may include, but are not limited to, a physical keyboard, function keys (such as volume control buttons, power buttons, etc.), a trackball, a mouse, and a joystick; these will not be elaborated further. The memory 509 can be used to store software programs and various data, including but not limited to programs and the operating system. The processor 510 may integrate an application processor and a modem processor. The application processor mainly handles the operating system, user interface, and programs, while the modem processor mainly handles wireless communication. It is understood that the modem processor may not be integrated into the processor 510.
[0151] This application also provides a readable storage medium storing a program or instructions. When the program or instructions are executed by a processor, they implement the various processes of the above method embodiments and achieve the same technical effect. To avoid repetition, they will not be described again here.
[0152] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0153] This application also provides a chip, which includes a processor and a communication interface. The communication interface and the processor are coupled. The processor is used to run programs or instructions to implement the various processes of the above method embodiments and achieve the same technical effect. To avoid repetition, it will not be described again here.
[0154] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.
[0155] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one…" does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.
[0156] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a computer software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0157] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.< / zzzz>
Claims
1. A business testing method, characterized in that, include: Obtain the program to be tested, wherein the program to be tested includes multiple business functions, and the beginning and end of each business function are instrumented by a software development kit, forming a tracing plugin in the program to be tested. The tracing plugin can record the first call information of the business function called during the operation of the program to be tested. The business logic of the program under test is tested using preset test cases. Second call information of the test cases to the business functions is obtained during the business implementation process. The second call information is output by the tracing plugin after the test run. The call chain of the business functions during the business implementation process is obtained based on the second call information. The business test results of the program under test are determined based on the second call information, wherein the test results include the test coverage of the test cases for the business functions in the program under test whose business code has been modified; The determination of the business test results of the program to be tested based on the second invocation information includes: The file output by the tracking plugin is parsed using a function node call chain comparison tool. Based on the timestamps and call relationships of each business function in the file, a first call stack of the test program and a second call stack of the control program are drawn. The state of each business function is recorded at the end. The business functions are ordered according to their call times, and the business functions called by the top-level function correspond to call relationship identifiers. The function node call chains of the first call stack and the function node call chains of the second call stack are compared to obtain the changes in the call stack.
2. The business testing method according to claim 1, characterized in that, The second invocation information includes the function name of the business function invoked by the test case and the timestamp of the business function; Determining the business test results of the program under test based on the second call information includes: A call stack is generated based on the timestamp and the function name, wherein the call stack includes the call chain of the multiple function nodes, and the business function includes the function node; The business test result is determined based on the call stack.
3. The business testing method according to claim 2, characterized in that, Determining the business test result based on the call stack includes: Determine the first call stack of the program to be tested and the second call stack of the control program, wherein the program to be tested is obtained by modifying the control program for business logic. The business test result is determined based on the comparison results of the first call stack and the second call stack.
4. The business testing method according to claim 3, characterized in that, Determining the business test result based on the comparison result of the first call stack and the second call stack includes: The distinguishing function node is determined based on the original function node in the second call stack and the current function node in the first call stack; If the distinguishing function node is a newly added function node or a deleted function node, the sub-functions of the distinguishing function node are recursively recorded to obtain the business test results; In the case where the distinguishing function node is neither a newly added function node nor a deleted function node, the function name and function parameters of the distinguishing function node are recursively recorded to obtain the business test results.
5. The business testing method according to claim 4, characterized in that, After determining the distinguishing function node in the current function node, the testing method further includes: If the sub-function of the distinguishing function node is the same as the sub-function of the original function node, then the distinguishing function node is determined to be neither a newly added function node nor a deleted function node; If the sub-functions of the distinguishing function node are different from the sub-functions of the original function node, the distinguishing function node is determined to be a newly added function.
6. The business testing method according to any one of claims 2 to 5, characterized in that, After determining the first call stack of the program to be tested and the second call stack of the control program, the testing method further includes: Based on the comparison results between the first call stack and the second call stack, the scope of impact of the business modification is determined.
7. The business testing method according to claim 6, characterized in that, The step of determining the business test result of the program to be tested based on the second call information further includes: Based on the scope of influence, a first business function is determined in the program to be tested, wherein the first business function is a business function whose business code has been modified; Based on the second call information, a second business function is determined, wherein the second business function is the business function called by the test case; The coverage rate is determined based on the first business function and the second business function.
8. The business testing method according to any one of claims 1 to 5, characterized in that, The process of obtaining the program to be tested includes: Obtain the code to be tested and the tracing plugin, wherein the code to be tested includes business functions; The test code and the tracing plugin are packaged and compiled to obtain the program to be tested.
9. A business testing device, characterized in that, include: The acquisition module is used to acquire the program to be tested, wherein the program to be tested includes multiple business functions, and the beginning and end of each business function are instrumented by a software development kit, forming a tracing plugin in the program to be tested. The tracing plugin is used to output the first call information of the business functions of the program to be tested. The testing module is used to test the business of the program under test through preset test cases, and to obtain the second call information of the test cases to the business function during the business implementation process. The second call information is output by the tracing plugin after the test run, and the call chain of the business function during the business implementation process is obtained based on the second call information. The determination module is used to determine the business test results of the program under test based on the second call information, wherein the test results include the test coverage of the test cases for the business functions in the program under test whose business code has been modified; The determining module is further configured to: parse the file output by the tracing plugin using a function node call chain comparison tool; draw a first call stack of the test program and a second call stack of the control program based on the timestamps and call relationships of each business function in the file, wherein the state of the business function is recorded at the end of the business function, the multiple business functions are ordered according to the time of their calls, and the business functions called by the top-level function correspond to call relationship identifiers; and compare the function node call chains of the first call stack and the function node call chains of the second call stack to obtain changes in the call stack.
10. An electronic device, characterized in that, include: A memory that stores programs or instructions; A processor for implementing the steps of the business testing method as described in any one of claims 1 to 8 when executing the program or instructions.
11. A readable storage medium having a program or instructions stored thereon, characterized in that, When the program or instructions are executed by the processor, they implement the steps of the business testing method as described in any one of claims 1 to 8.
Citation Information
Patent Citations
Analysis methods of abnormal running, application terminal and monitoring server
CN107273263A
Terminal test method and device, computer equipment and storage medium
CN110389895A
Memory leakage detection method, device and system and computer equipment
CN112346894A
