Program testing method, readable storage medium and program product
By analyzing the user's operation information on the software being tested and generating unit test cases, the problems of high program testing costs and unreliable results in the prior art are solved, and efficient and reliable program testing and code coverage acquisition are achieved.
Patent Information
- Application Number
- CN202411783095.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-05
- Publication Date
- 2025-02-14
AI Technical Summary
In the prior art, program testing methods require users to manually write test cases, resulting in an increase in time and labor costs. Due to different testers, the test results are unreliable and the code coverage cannot be accurately obtained.
By detecting the user's operation information on the user interface of the software being tested, analyzing the keywords of the operation event, using a predefined test code template to generate unit test cases, and determining the execution order based on the weight of the operation event, running the test cases for program testing, And generate a code coverage report.
It reduces the time and labor costs of program testing, improves the reliability of test results, and ensures accurate acquisition of code coverage.
Smart Images

Figure CN119441061A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of databases, and in particular to a readable storage medium and a program product for a program testing method. Background Art
[0002] The current software program testing method is that the user first writes the corresponding test case according to the software function, and then runs the test case to test the software function and performance. However, with the diversification and personalization of user needs, the functions of the software are also increasing and complex, which will cause the time and labor costs of writing test cases to increase sharply.
[0003] On the other hand, since each tester has different code writing habits, the test cases written by different testers for the same software may be different. Using different test cases to test the software program may result in different test results. Therefore, the program testing method in the prior art cannot guarantee the reliability of the program testing results. Summary of the invention
[0004] One purpose of the present invention is to automatically generate test cases according to the user's operations on the tested software during the process of program testing of the software, so as to reduce the time cost and labor cost of program testing; another purpose is to reduce the differences in program testing results caused by different testers and improve the reliability of program testing results.
[0005] A further object of the present invention is to solve the problem that the program testing method in the prior art cannot accurately obtain the code coverage during the program testing process.
[0006] In a first aspect, the present invention provides a program testing method, comprising:
[0007] In response to starting a program test on the software under test, detecting a user interface of the software under test to obtain user operation information;
[0008] Parsing the user operation information to obtain keywords of the operation events in the user operation information;
[0009] Obtaining a predefined test code template, and filling the test code template according to the keyword to generate a unit test case;
[0010] The unit test cases are run to perform program testing on the software under test.
[0011] Furthermore, after the step of detecting the user operation information of the user in the user interface of the software under test, the method further includes:
[0012] Acquire the operation event of the user according to the user operation information, and acquire the weight of the operation event;
[0013] Allocating the operation event to a processing channel / processing queue of a corresponding priority according to the weight;
[0014] The execution order of each of the operation events in the unit test case is determined according to the priority of the processing channel / processing queue where each of the operation events is located.
[0015] Furthermore, after the step of detecting the user operation information of the user in the user interface of the software under test, the method further includes:
[0016] The user operation information is preprocessed, and the preprocessing at least includes: removing or correcting abnormal data in the user operation information.
[0017] Furthermore, the step of obtaining a predefined test code template includes:
[0018] Obtaining a preset standard test structure, and obtaining a basic test file according to the standard test structure;
[0019] The dynamic parameters in the basic test file are configured to generate the test code template.
[0020] Furthermore, the step of filling the test code template according to the keyword includes:
[0021] Get the test method name corresponding to each of the keywords;
[0022] The test code corresponding to each of the test method names is called to fill in the test code template.
[0023] Furthermore, the step of obtaining the test method name corresponding to each of the keywords includes:
[0024] Obtain a preset method mapping table, wherein the method mapping table is used to record the mapping relationship between keywords and test method names;
[0025] The method mapping table is queried according to the keywords of the operation event to obtain the test method name corresponding to each keyword.
[0026] Furthermore, after the step of obtaining the test method name corresponding to each keyword, the following step is further included:
[0027] Determine whether the test code corresponding to the test method name has dependencies;
[0028] If so, the test method names corresponding to the dependencies are obtained, and the order of the test method names is arranged according to the dependency relationship.
[0029] Further, after the step of running the unit test case to perform program testing on the software under test, the method further includes:
[0030] Obtaining code execution information of the software under test during the execution of the unit test instance;
[0031] A code coverage report is generated based on the code execution information.
[0032] In a second aspect, the present invention further provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the steps of any of the program testing methods described above are implemented.
[0033] In a third aspect, the present invention further provides a computer program product, comprising a computer program, which, when executed by a processor, implements the steps of any of the above program testing methods.
[0034] The technical solution provided by the present invention can detect the user operation information of the user in the user interface of the software under test, generate the unit test case of the software under test according to the user operation information, and run the unit test case to perform program testing on the software under test. Since the technical solution of the present invention does not require the user to write code in the process of constructing the unit test case of the software under test, the time cost and labor cost of program testing can be reduced. In addition, the technical solution of the present invention adopts a predefined test code template to generate unit test cases according to the keywords in the user operation information, so it can also avoid the problem of differences in unit test cases due to different code writing habits of users, thereby achieving the purpose of improving the reliability of program testing.
[0035] Based on the following detailed description of specific embodiments of the present invention in conjunction with the accompanying drawings, those skilled in the art will become more aware of the above and other objects, advantages and features of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Hereinafter, some specific embodiments of the present invention will be described in detail in an exemplary and non-limiting manner with reference to the accompanying drawings. The same reference numerals in the accompanying drawings indicate the same or similar components or parts. It should be understood by those skilled in the art that these drawings are not necessarily drawn to scale. In the accompanying drawings:
[0037] Figure 1 is a schematic flow chart of a program testing method according to an embodiment of the present invention;
[0038] Figure 2 is a schematic flow chart of determining the execution order of each operation event in a unit test case in a program testing method according to an embodiment of the present invention;
[0039] Figure 3 is a schematic flow chart of obtaining a predefined test code template in a program testing method according to an embodiment of the present invention;
[0040] Figure 4 is a schematic flow chart of obtaining a predefined test code template in a program testing method according to another embodiment of the present invention;
[0041] Figure 5 It is a schematic flow chart of a test method name corresponding to a keyword of an operation event in user operation information in a program testing method according to an embodiment of the present invention;
[0042] Figure 6 is a schematic flow chart of determining the execution order of each operation event in a unit test case in a program testing method according to an embodiment of the present invention;
[0043] Figure 7 is a schematic flow chart of a program testing method according to another embodiment of the present invention;
[0044] Figure 8 is a schematic flow chart of a program testing method according to yet another embodiment of the present invention;
[0045] Fig. 9 is a schematic diagram of a computer program product according to an embodiment of the present invention; and
[0046] Fig.10 is a schematic diagram of a computer-readable storage medium according to an embodiment of the present invention. DETAILED DESCRIPTION
[0047] Refer to the following Figures 1 to 10 A program testing method readable storage medium and a program product of an embodiment of the present invention are described. In the description of the present invention, the meaning of "multiple" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined. When a feature "includes or contains" one or some of the features it covers, unless otherwise specifically described, this indicates that other features are not excluded and other features may be further included.
[0048] See also Figure 1 , Figure 1 It is a schematic flow chart of a program testing method according to an embodiment of the present invention. The method can automatically generate unit test cases of the software under test based on the user's operations in the user interface of the software under test to perform program testing on the software under test, so as to reduce the time cost and labor cost of program testing and improve the reliability of program testing on the software under test.
[0049] exist Figure 1In the process shown, the program testing method of this embodiment includes the following steps:
[0050] Step S102: Detect whether the program test of the software under test is started;
[0051] If yes, execute step S104;
[0052] Step S104: detecting the user interface of the software under test to obtain user operation information, and parsing the user operation information to extract keywords of the operation events in the user operation information;
[0053] Step S106: obtaining a predefined test code template, and filling the test code template according to the keywords of the operation event in the user operation information to generate a unit test case;
[0054] Step S108: Run the generated unit test cases to perform program testing on the software under test.
[0055] In the above step S102, a test function button can be set on the user interface of the tested software, and after detecting that the user clicks the test function button, it is determined that the user has started the program test of the tested software. The user in this embodiment is the user who performs the program test on the tested software, and can also be understood as a test operator.
[0056] In the above step S104, an extension dependency may be added to the software under test, and an event listener may be added to the user interface of the software under test to capture user operations on the user interface of the software under test, such as click operations, data input operations, etc., through the event listener.
[0057] After the user starts the program test of the software under test, operations such as selecting buttons and entering test data for program testing can be performed on the user interface of the software under test; the set event listener can collect information on the user interface of the software under test to obtain the user's operations on the user interface of the software under test, and then collect information related to the operation in the callback function to obtain user operation information.
[0058] In this embodiment, the obtained user operation information includes the user's operation events, as well as parameter information of the operation events, timestamp, user ID, device information and network status, etc., wherein the operation events may include button clicks, text input, etc., and the parameter information of the operation events may include clicked options, input text content, etc.; the timestamp refers to the time when the operation event occurs; the user ID refers to the user's identity information; the device information refers to the information of the device running the software under test, such as configuration information such as the device's processor model; the network status refers to the network status of the device running the software under test, which includes the connected state and the disconnected state.
[0059] The method for parsing user operation information in this embodiment includes: firstly sorting the user operation events according to the timestamps, and then parsing the user operation events according to the sorting to obtain the keywords of each operation event.
[0060] In this embodiment, each type of operation event is provided with a corresponding keyword. In the process of parsing the user operation information, the corresponding keyword can be determined according to the type of the operation event in the user operation information. For example, if the user's operation event is clicking a submit button, the keywords of the operation event may include "click" and "submit"; if the user's operation event is inputting text data, the keywords of the operation event may include "input" and "text".
[0061] In this embodiment, after obtaining the keywords of the user's operation event, the test method matching the corresponding operation event is obtained according to each keyword, and the test method name of the test method is obtained. Then, the obtained operation event, class name, test method name, number of function parameters and function parameter values, and UI identifier are used as the analysis results of the user operation information, and the analysis results are saved in the database.
[0062] In the above step S106, a test code template may be predefined and used as built-in data of the software under test. In this embodiment, the predefined test code template may be obtained by calling the built-in data, and then the preset test information may be imported into the test code template, wherein the preset test information may include import statements, test method declarations, and exception handling logic, etc.
[0063] In this embodiment, the test code template includes a standard test structure for program testing. After the preset test information is imported into the test code template, the test code template can form a template for a unit test case.
[0064] After obtaining the preset test code template, you can first identify the position in the test code template that needs to be filled or replaced with data. For example, you can set a specific identifier at the position in the test code template where data needs to be filled or replaced; after obtaining the test code template, determine the position where data needs to be filled or replaced based on the position of the specific identifier. Then obtain the test code corresponding to the keyword of the operation event in the user operation information, and use the test code to fill the data at the corresponding position in the test code template, or replace the data at the corresponding position, so as to improve the test logic in the test code template and generate unit test cases.
[0065] In the above step S108, after running the constructed unit test case, program testing can be performed on the software under test to obtain the performance of the software under test.
[0066] According to the above content, since the technical solution of this embodiment does not require the user to write code in the process of constructing the unit test case of the tested software, the time cost and labor cost of program testing can be reduced compared with the prior art. On the other hand, the technical solution of this embodiment uses a predefined test code template to generate unit test cases based on keywords in the user operation information, thereby avoiding the problem of differences in unit test cases due to different code writing habits of users, and ensuring the reliability of program test results.
[0067] In some embodiments of the present invention, after detecting the user operation information of the user in the user interface of the software under test in step S102, the process further includes determining the execution order of each operation event in the unit test case according to the user operation information.
[0068] In this embodiment, the method for determining the execution order of each operation event in the unit test case is as follows: Figure 2 As shown, the following steps are included:
[0069] Step S202: obtaining the user's operation event according to the user operation information;
[0070] Step S204: Obtain the weight of the user's operation event, and assign the user's operation event to a processing channel / processing queue of a corresponding priority according to the weight;
[0071] Step S206: Determine the execution order of each operation event in the unit test case according to the priority of the processing channel / processing queue where each operation event is located.
[0072] In this embodiment, each type of event may be evaluated according to its business importance, user attention, data value, and processing cost to obtain a weight for each type of event.
[0073] For example, the weights of operational events can be divided into high weight, medium weight, and low weight, where high-weight operational events refer to operational events that have a direct impact on the business. These operational events need to be handled with priority to ensure that they can be quickly transformed into valuable information, such as object structure definitions, business data changes, and user role authorizations.
[0074] Medium-weighted operation events refer to events that require certain analysis or aggregation to extract valuable information, such as data retrieval queries and page dwell time. These events can be processed after high-weighted operation events are processed.
[0075] Low-weight operation events refer to operation events that can be processed with a delay, partially processed, or directly cleared according to actual conditions, such as system logs and debugging information.
[0076] In this embodiment, each processing channel / processing queue is set with a corresponding priority, and the higher the priority of the processing channel / processing queue, the higher the weight of the corresponding operation event. After determining the weight of the operation event in the user operation information, the operation event with a high weight is allocated to the processing channel / processing queue with the highest priority, the operation event with a medium weight is allocated to the processing channel / processing queue with a medium priority, and the operation event with a low weight is allocated to the processing channel / processing queue with a low priority.
[0077] In the process of running the generated unit test case in the above step S108, the execution order of the code corresponding to each operation event is determined according to the priority of each processing channel or processing queue, wherein the higher the priority of the processing channel or processing queue, the higher the priority of the code corresponding to the operation event therein is.
[0078] Therefore, the technical solution of this embodiment can ensure that the operation events with high weights in the unit test cases are executed first and the operation events with low weights are executed last during the testing of the software under test, so as to achieve the purpose of improving the reliability of the test.
[0079] In some embodiments of the present invention, before parsing the user operation information in the above step S108, the method further includes:
[0080] The user operation information is preprocessed, and the preprocessing at least includes checking whether the format of each field in the user operation information is a preset format, whether the data type is a preset type, and / or removing or correcting abnormal data in the user operation information.
[0081] Taking an application scenario as an example, assuming that in the user operation information, the preset format of the timestamp is "year-month-day-hour-minute-second-millisecond", and the data type of the input data is a character type, then after obtaining the user operation information, check whether the format of the timestamp field is "year-month-day-hour-minute-second-millisecond", and whether the data type of the input data is a character type.
[0082] In this embodiment, fields in the user operation information whose format is not in the corresponding preset format and fields whose data type is not in the corresponding preset type can be regarded as abnormal data. Other data in the user operation information that does not meet expectations can also be regarded as abnormal data, for example, data with empty characteristic values in the user operation information can be regarded as abnormal data.
[0083] Taking the abnormal data that the characteristic data corresponding to the "network status" is empty as an example, the preprocessing of the abnormal data includes: setting the characteristic data corresponding to the "network status" to "unknown", or processing according to the default processing rules, such as removing the "network status".
[0084] Through the technical solution of this embodiment, after preprocessing the user operation information, abnormal data in the user operation information can be reduced, the accuracy and reliability of the user operation information can be guaranteed, and the reliability of the generated unit test cases can be improved.
[0085] In some embodiments of the present invention, the method for obtaining the predefined test code template in step S106 is as follows: Figure 3 As shown, the following steps are included:
[0086] Step S212: obtaining a preset standard test structure, and obtaining a basic test file according to the standard test structure to obtain an initial test code template;
[0087] Step S214: configure the dynamic parameters in the basic test file to import the preset test information into the test code template.
[0088] In the above step S212, the preset standard test structure includes the steps of preparing test data, importing dependent library test methods, calling test methods and verifying results. By building a basic test file, statements can be imported into the test code template, test methods can be declared and exception handling logic can be set.
[0089] In the above step S214, placeholders can be used as template test parameters in the test code template. For example, $ can be used as a marker for the position where the parameter needs to be filled in, ${method_name} can be used to indicate the position where the test method name needs to be filled in, and ${method_parameters} can be used to indicate the position where the test method parameters need to be filled in.
[0090] Through the technical solution of this embodiment, an accurate test code template can be quickly constructed to improve the work efficiency of constructing unit test cases and improve the accuracy of unit test cases.
[0091] In some embodiments of the present invention, in the above step S106, the method of filling the test code template according to the keywords of the operation event in the user operation information is as follows: Figure 4 As shown, the following steps are included:
[0092] Step S222: Obtain the test method name corresponding to each keyword of the operation event in the user operation information;
[0093] Step S228: Call the test code corresponding to each of the above test method names to fill in the test code template to obtain a unit test case.
[0094] In the above step S222, the mapping relationship between each keyword and each test method name may be obtained first, and after the keyword of the operation event in the user operation information is obtained, the test method name corresponding to the keyword may be obtained according to the mapping relationship.
[0095] In the above step S228, a reflection mechanism may be used to obtain the corresponding test code according to the obtained test method name, and fill the test code into the corresponding position on the test code template to fill the test logic of the test code template and obtain a unit test case.
[0096] For example, in the location where the unit test case is named in the test code template, the event name of the operation event plus Test can be used as the instance name of the unit test case. In the location of the variable in the test code template, a generated random value can be used as the value of the variable. In the location of the control in the test code template, the test code corresponding to the element positioning method (i.e., the findelement method) can be used to find the location of the target control according to the UI identifier. If the user's operation event is a click, the test code of the click method is called in the test code template. If the user's operation event is input data, the test code of the input method is called in the test code template, and the corresponding operation parameters are passed in with the $ symbol. In the return position in the test code template, fill in the result value of the corresponding return method.
[0097] Through the technical solution of this embodiment, in the process of constructing a unit test instance, the test code corresponding to the keyword of the operation event can be automatically called without directly modifying the code in the test code template, thereby achieving the purpose of improving the work efficiency of generating unit test instances.
[0098] In some embodiments of the present invention, Figure 5 As shown, after obtaining the test method name corresponding to the keyword of the operation event in the user operation information in the above step S222, the following steps are also included:
[0099] Step S224: determine whether the test code corresponding to the acquired test method name has any dependencies;
[0100] If it exists, execute step S226; if it does not exist, execute step S228;
[0101] Step S226: Acquire the test method names corresponding to the above dependencies, and arrange the order of the acquired test method names according to the dependency relationship.
[0102] In the above step S224, the test code corresponding to the test method name has a dependency, which means that in the test code corresponding to the test method name, the output data of other code methods need to be called. For example, assuming that data X is needed in the test code of the test method name A, and data X is the output data of the test method name B, then it can be determined that the test code of the test method name A has a dependency, and the dependency is X.
[0103] Accordingly, in the above step S228, B can be used as the test method name corresponding to the dependency X, and because the test code of the test method name A depends on the test code of the test method name B, the test method name B can be arranged before the test method name A according to the dependency relationship.
[0104] Through the technical solution of this embodiment, when the test code corresponding to the obtained test method name has dependencies, the test method name corresponding to the dependency can be obtained, thereby ensuring the comprehensiveness of the generated unit test cases and improving the code coverage of the program test and the accuracy of the test results.
[0105] In some embodiments of the present invention, the method for obtaining the test method name corresponding to the keyword of the operation event in the user operation information in the above step S222 is as follows: Figure 6 As shown, the steps include:
[0106] Step S232: Obtain a preset method mapping table, which is used to record the mapping relationship between keywords and test method names;
[0107] Step S234: query the method mapping table according to the keywords of the user operation event to obtain the corresponding test method name.
[0108] In the above step S232, a pre-constructed method mapping table may be obtained, or a method mapping table may be constructed according to a mapping relationship between known keywords and test method names.
[0109] In this embodiment, the method of constructing the method mapping table includes:
[0110] First, an operation event table is constructed to record the information of the operation event. The fields of the operation event table constructed in this embodiment may include event_id, event_name, event_description and gui_component_id. The above event_id represents the unique identifier of the operation event, that is, the primary key of the operation event table; event_name represents the name of the operation event, such as button click, text input, etc.; event_description represents the description of the operation event; gui_component_id represents the ID of the component in the user operation interface of the tested software, such as the ID of a button.
[0111] Taking a scenario as an example, the constructed operation event table is shown in Table 1. In the operation event table, the name of the operation event with a unique identifier of 1 is ButtonClick, the description of the operation event is "click the submit button", and the component ID in the user operation interface of the tested software is button_submit. The name of the operation event with a unique identifier of 2 in the operation event table is TextInput, the description of the operation event is "enter the user name", and the component ID in the user operation interface of the tested software is input_username.
[0112] event_id event_name event_description gui_component_id 1 ButtonClick Click the Submit button button_submit 2 TextInput Enter Username input_username
[0113] Table 1
[0114] Then associate the action events with the test methods to build a method mapping table.
[0115] The method mapping table constructed in this embodiment includes the fields mapping_id, event_id, method_name, method_parameters and method_description, where mapping_id represents the unique identifier of the test method, i.e., the primary key of the method mapping table; event_id is the foreign key of the method mapping table, and is used to associate the unique identifier event_id of the operation event in the operation event table. method_name represents the test method name of the test method, method_parameters represents the parameters of the test method, and method_description represents the method description of the test method.
[0116] Taking an application scenario as an example, the constructed method mapping table is shown in Table 2. In this method mapping table, the test method with a unique identifier of 1 corresponds to the operation event with a unique identifier of 1 in the operation event table, and the test method name of the test method is submitForm, the parameter is "submit_data", and the method description is "submit form information". The test method with a unique identifier of 2 corresponds to the operation event with a unique identifier of 2 in the operation event table, and the test method name of the test method is validateUser, the parameter is "username:input_value", and the method description is "validate the username entered by the user".
[0117]
[0118] Table 2
[0119] After obtaining the keyword of the operation event in the user operation information, the unique identifier of the operation event can be found in the operation event table based on the keyword, and then the test method name corresponding to the unique identifier can be found from the method mapping table. The test method name is the test method name corresponding to the keyword of the operation event in the user operation information.
[0120] Through the technical solution of this embodiment, the test method name corresponding to the keyword of the operation event in the user operation information can be quickly obtained by querying the preset method mapping table, thereby improving the work efficiency of constructing unit test cases and achieving the purpose of increasing the speed of program testing.
[0121] In some embodiments of the present invention, Figure 7 As shown, the program testing method of the present invention further includes the following steps after the program testing is performed on the tested software in the above step S108:
[0122] Step S110: Obtaining code execution information of the software under test during the running of the unit test instance;
[0123] Step S112: Generate a code coverage report according to the acquired code execution information.
[0124] In this embodiment, before running the unit test instance in the above step S108, a code coverage tool can be added and configured in the test environment of the software under test, so that during the process of running the unit test instance to test the software under test, the code coverage tool can collect code execution information of the software under test in real time.
[0125] In the above step S112, based on the code execution information of the software under test, it is possible to obtain which codes in the software under test are executed during the program testing process, and then obtain the code coverage of the software under test, and generate a code coverage report for the software under test based on the code coverage, so that the user can understand whether the test of the software under test is comprehensive.
[0126] The code coverage of this embodiment may include line coverage, branch coverage and condition coverage, wherein line coverage is used to measure whether each line of code of the tested software is executed, branch coverage is used to measure whether different paths of each branch statement (such as if-else statement) in the tested software are executed, and condition coverage measures whether each individual condition of the logical expression in the code of the tested software is executed.
[0127] Through the technical solution of this embodiment, code coverage data for the software under test can be quickly generated during the program testing process, so that the user can clearly understand which codes of the software under test are covered and which codes are not covered during the test program, so as to evaluate the program testing quality of the software under test.
[0128] In some embodiments of the present invention, the program testing method of the present invention is as follows Figure 8 As shown, the following steps are included:
[0129] Step S302: Detect whether the program test of the software under test is started;
[0130] If yes, execute step S304;
[0131] Step S304: Detect the user interface of the software under test to obtain the user's operation, and obtain information related to the operation in the callback function to obtain user operation information;
[0132] Step S306: obtaining the user's operation events according to the user operation information, then obtaining the weight of each operation event, and assigning the user's operation events to processing channels / processing queues of corresponding priorities according to the weight;
[0133] Step S308: pre-processing the user operation information to detect whether each field of the user operation information conforms to the expected type and format, and removing or correcting abnormal data in the user operation information;
[0134] Step S310: converting the user operation information into a parsable operation sequence, and then parsing the user operation information to extract keywords of the operation events therein;
[0135] Step S312: Obtain the test method name corresponding to the keyword in the user operation event, and determine whether there is a dependency in the test method corresponding to the test method name;
[0136] If yes, execute step S314; if no, execute step S316;
[0137] Step S314: obtaining the test method names of the dependent items in the test method corresponding to the keyword in the user operation information, and arranging the order of the obtained test method names according to the dependency relationship;
[0138] Step S316: obtaining a preset standard test structure, and obtaining a basic test file according to the standard test structure;
[0139] Step S318: using preset placeholders to set dynamic parameters in the basic test file to obtain a test code template;
[0140] Step S320: using the reflection mechanism, dynamically calling the corresponding test code according to the test method name corresponding to the keyword of the operation event, so as to fill the test logic of the test code template;
[0141] Step S322: running the generated unit test cases to perform program testing on the software under test;
[0142] Step S324: Obtain code execution information of the software under test during the execution of the unit test instance, and generate a code coverage report based on the acquired code execution information.
[0143] The flow chart provided by the present embodiment is not intended to indicate that the operation of the method will be performed in any particular order, or that all operations of the method are included in all every case. In addition, the method may include additional operations. Within the scope of the technical ideas provided by the present embodiment method, additional changes can be made to the above method.
[0144] It should be understood that in some embodiments, each part can be implemented by hardware, software, firmware or a combination thereof. In the above embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system.
[0145] This embodiment also provides a computer program product 10 and a computer readable storage medium 20 . Fig. 9 is a schematic diagram of a computer program product 10 according to an embodiment of the present invention, Fig.10 is a schematic diagram of a computer-readable storage medium 20 according to an embodiment of the present invention. The computer program product 10 includes a computer program 11, which implements the steps of any of the above-mentioned program testing methods when the computer program 11 is executed by the processor 32. The computer-readable storage medium 20 stores the above-mentioned computer program 11 thereon, and the computer program 11 implements the steps of the program testing method of any of the above-mentioned embodiments when the computer program 11 is executed by the processor 32.
[0146] The computer program 11 for performing the operation of the present invention may be an assembly instruction, an instruction set architecture (ISA) instruction, a machine instruction, a machine-related instruction, a microcode, a firmware instruction, a state setting data, a configuration data of an integrated circuit, or a source code or an object code written in any combination of one or more programming languages and process programming languages. The computer program 11 may be executed entirely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the latter case, the remote computer may be connected to the user's computer via any type of network (including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider via the Internet). In some embodiments, in order to perform various aspects of the present invention, an electronic circuit including, for example, a programmable logic circuit, a field programmable gate array (FPGA) or a programmable logic array (PLA) may execute computer-readable program instructions by utilizing the state information of the computer-readable program instructions to personalize the electronic circuit.
[0147] In the description of this embodiment, the computer program product 10 is a related product including the computer program 11 .
[0148] For the purpose of the description of the present embodiment, the computer readable storage medium 20 is a tangible device capable of retaining and storing the computer program 11, which can be any device that can contain, store, communicate, propagate or use the computer program 11 for an instruction execution system, device or apparatus or in conjunction with these instruction execution systems, devices or apparatuses. More specific examples (a non-exhaustive list) of the computer readable storage medium 20 include the following: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, and any suitable combination of the above.
[0149] At this point, those skilled in the art should recognize that, although multiple exemplary embodiments of the present invention have been shown and described in detail herein, many other variations or modifications that conform to the principles of the present invention can still be directly determined or derived based on the content disclosed in the present invention without departing from the spirit and scope of the present invention. Therefore, the scope of the present invention should be understood and recognized as covering all these other variations or modifications.
Claims
1. A program testing method, characterized in that: include: In response to starting a program test on the software under test, detecting a user interface of the software under test to obtain user operation information; Parsing the user operation information to obtain keywords of the operation events in the user operation information; Obtaining a predefined test code template, and filling the test code template according to the keyword to generate a unit test case; The unit test cases are run to perform program testing on the software under test.
2. The program testing method according to claim 1, characterized in that: After the step of detecting the user operation information of the user in the user interface of the software under test, the method further includes: Acquire the operation event of the user according to the user operation information, and acquire the weight of the operation event; Allocating the operation event to a processing channel / processing queue of a corresponding priority according to the weight; The execution order of each of the operation events in the unit test case is determined according to the priority of the processing channel / processing queue where each of the operation events is located.
3. The program testing method according to claim 1, characterized in that: After the step of detecting the user operation information of the user in the user interface of the software under test, the method further includes: The user operation information is preprocessed, and the preprocessing at least includes: removing or correcting abnormal data in the user operation information.
4. The program testing method according to claim 1, characterized in that: The step of obtaining a predefined test code template includes: Obtaining a preset standard test structure, and obtaining a basic test file according to the standard test structure; The dynamic parameters in the basic test file are configured to generate the test code template.
5. The program testing method according to claim 1, characterized in that: The step of filling the test code template according to the keyword comprises: Get the test method name corresponding to each of the keywords; The test code corresponding to each of the test method names is called to fill in the test code template.
6. The program testing method according to claim 5, characterized in that: The step of obtaining the test method name corresponding to each keyword includes: Obtain a preset method mapping table, wherein the method mapping table is used to record the mapping relationship between keywords and test method names; The method mapping table is queried according to the keywords of the operation event to obtain the test method name corresponding to each keyword.
7. The program testing method according to claim 5, characterized in that: After the step of obtaining the test method name corresponding to each keyword, the method further includes: Determine whether the test code corresponding to the test method name has dependencies; If so, the test method names corresponding to the dependencies are obtained, and the order of the test method names is arranged according to the dependency relationship.
8. The program testing method according to claim 1, characterized in that: After the step of running the unit test case to perform program testing on the software under test, the method further includes: Obtaining code execution information of the software under test during the execution of the unit test instance; A code coverage report is generated based on the code execution information.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the program testing method according to any one of claims 1 to 8 are implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the program testing method according to any one of claims 1 to 8 are implemented.