White box test method and device, storage medium and computer equipment
By using historical test coverage information and the screening method of incremental functions in the white box test to generate test cases and test, the existing white box test efficiency is low, and the more efficient test process is achieved.
Patent Information
- Application Number
- CN202411421148.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-11
- Publication Date
- 2025-01-21
AI Technical Summary
The existing white box testing methods are low in efficiency, resulting in large test runs and long-term, which cannot meet the high requirements of modern software development for testing efficiency.
By pulling the historical test coverage information and the incremental functions of the source code of the version to be tested, a function call relationship diagram and a function control flow diagram are generated. Based on this information, the incremental functions are filtered, test cases are created, and the test cases are executed for white boxing. test.
It greatly avoids repeated testing of code, reduces the amount of testing and testing time, effectively improves the efficiency of white-box testing, and can meet the testing efficiency requirements of rapid development methods such as financial systems and medical systems.
Smart Images

Figure CN119336641A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of software testing technology, finance and medicine, and in particular to a white box testing method and device, a storage medium and a computer device. Background Art
[0002] White box testing is a software testing method. In this test, the "box" refers to the software being tested, and "white box" means that the tester can clearly understand the internal logical structure and operation of the software, and use the internal logical structure and knowledge of the program to design or select test cases to test all the logical paths of the program. White box testing is widely used in software in various fields, especially for financial systems and medical systems with large data processing volume and complex business logic. White box testing can deeply test the internal logic of the software to ensure that it can run correctly in various transaction scenarios.
[0003] With the rapid development of new technologies such as microservices, containerization, and agile development, the efficiency requirements for white-box testing are becoming increasingly higher. However, existing white-box testing methods usually require developers to design and write test cases according to their needs. Due to the high complexity of source code calls, the writing of test cases inevitably involves a large number of repeated tests, resulting in a large amount of test runs and a long test time, making the efficiency of white-box testing unable to meet the efficiency requirements of existing white-box testing. Summary of the invention
[0004] In view of this, the present invention provides a white box testing method and apparatus, a storage medium, and a computer device, the main purpose of which is to solve the problem of low efficiency of existing white box testing.
[0005] According to one aspect of the present invention, a white box testing method is provided, comprising:
[0006] Pulling historical test coverage information and an incremental function of the source code of the version to be tested, wherein the historical test coverage information is determined based on a test coverage merger result of a previous version of the source code of the version to be tested;
[0007] Respectively generate a function call relationship diagram and a function control flow diagram of the incremental function;
[0008] Screening the incremental function according to the historical test coverage information, the function call relationship diagram and the function control flow diagram, and creating a test case according to the screening result;
[0009] The test case is executed to perform white box testing on the source code of the version to be tested, and a test result of the source code of the version to be tested is generated.
[0010] Furthermore, the historical test coverage information includes function call coverage information and function execution coverage information, and the incremental function is screened according to the historical test coverage information, the function call relationship diagram, and the function control flow diagram, and a test case is created according to the screening result, including:
[0011] Screening the function call relationship graph according to the function call coverage information to obtain a basic path to be tested that is not covered by a previous test, and generating a first test case for a system test phase according to the basic path to be tested, wherein the test case includes the first test case; and / or,
[0012] The function control flow graph is screened according to the function execution coverage information to obtain the fine-grained path to be tested that is not covered by the previous test, and a second test case for the integration test phase is generated according to the fine-grained path to be tested, and the test case includes the second test case.
[0013] Further, the function control flow graph is screened according to the function execution coverage information to obtain the fine-grained path to be tested that is not covered by the previous test, including:
[0014] Screening each statement in the function control flow chart according to the function execution coverage information to obtain statements to be tested that are not fully covered by the previous test; determining the fine-grained path to be tested based on the statements to be tested;
[0015] In the case where the statement to be tested contains at least one determination condition, screening the determination conditions in the statement to be tested according to the function execution coverage information to obtain the determination conditions to be tested that are not covered by the previous test; adding the determination conditions to be tested to the fine-grained path to be tested;
[0016] When the determination condition to be tested includes at least two branches, the branches in the determination condition to be tested are screened according to function execution coverage information to obtain branches to be tested that are not covered by previous tests; and the branches to be tested are added to the fine-grained path to be tested.
[0017] Furthermore, the historical test coverage information includes structured display of historical coverage code. After generating the test result of the source code of the version to be tested, the method further includes:
[0018] Pull out multiple lines of test coverage code of the source code test process of the version to be tested;
[0019] Performing byte code merging on the test coverage code to obtain incremental coverage code of the source code of the version to be tested;
[0020] Converting the incremental coverage code into a structured display incremental coverage code described in a hypertext markup language;
[0021] The structured displayed incremental coverage code and the structured displayed historical coverage code are merged line by line, and the historical test coverage information is updated according to the result of the line by line merging.
[0022] Further, the generating of the function call relationship graph and the function control flow graph of the incremental function respectively includes:
[0023] Parsing the byte code of the incremental function, capturing function call information in the incremental function parsing result, and generating a function call relationship graph according to the function call information;
[0024] Determine the flowchart request information of the incremental function, and call the large model to generate a function control flowchart matching the flowchart request information;
[0025] After respectively generating the function call relationship diagram and the function control flow diagram of the incremental function, the method further comprises: displaying the function call relationship diagram and the function control flow diagram on a display terminal.
[0026] Furthermore, before the incremental function of pulling the source code of the version to be tested, the method further includes:
[0027] In response to an encoding completion instruction of the source code of the version to be tested, code scanning is performed on the source code of the version to be tested, and after feedback of code scanning problems, code scanning is repeatedly performed on updated code of the source code of the version to be tested, until a code scanning result of the source code of the version to be tested is passed;
[0028] In response to a code scanning pass indication of the source code of the version to be tested, performing a difference comparison between the source code of the version to be tested and a source code list of a test item corresponding to the source code of the version to be tested to obtain an incremental function;
[0029] At least one review task is created according to the incremental function, and the review task is distributed to manual review process nodes to perform collaborative review on the incremental function.
[0030] Furthermore, the review task carries a code display page with a marked incremental function, and the method further includes:
[0031] Parsing the bytecode of the source code of the version to be tested, and generating a display page of the code to be reviewed according to the parsing result of the source code of the version to be tested;
[0032] Marking the code lines corresponding to the incremental functions in the code display page to be reviewed with colors to obtain a code display page to be reviewed marked with the incremental functions;
[0033] The link of the to-be-reviewed code display page is associated with the corresponding review task, so as to display the to-be-tested version source code of the marked incremental function at the terminal of the manual review process node.
[0034] According to another aspect of the present invention, a white box testing device is provided, comprising:
[0035] A pulling module, used to pull historical test coverage information and an incremental function of a source code of a version to be tested, wherein the historical test coverage information is determined based on a test coverage merging result of a previous version of the source code of the version to be tested;
[0036] A generating module, used to generate a function call relationship diagram and a function control flow diagram of the incremental function respectively;
[0037] A creation module is used to screen the incremental function according to the historical test coverage information, the function call relationship diagram and the function control flow diagram, and create a test case according to the screening result;
[0038] The test module is used to execute the test case to perform white box test on the source code of the version to be tested, and generate the test result of the source code of the version to be tested.
[0039] Furthermore, the creation module includes:
[0040] a first screening unit, configured to screen the function call relationship graph according to the function call coverage information, obtain a basic path to be tested that is not covered by a previous test, and generate a first test case for a system test phase according to the basic path to be tested, wherein the test case includes the first test case; and / or,
[0041] The second screening unit is used to screen the function control flow chart according to the function execution coverage information, obtain the fine-grained path to be tested that is not covered by the previous test, and generate a second test case for the integration test phase based on the fine-grained path to be tested, and the test case includes the second test case.
[0042] Further, in a specific application scenario, the second screening unit is specifically used to screen each statement in the function control flow chart according to the function execution coverage information to obtain statements to be tested that are not fully covered by the previous test; determine the fine-grained path to be tested based on the statements to be tested;
[0043] In the case where the statement to be tested contains at least one determination condition, screening the determination conditions in the statement to be tested according to the function execution coverage information to obtain the determination conditions to be tested that are not covered by the previous test; adding the determination conditions to be tested to the fine-grained path to be tested;
[0044] When the determination condition to be tested includes at least two branches, the branches in the determination condition to be tested are screened according to function execution coverage information to obtain branches to be tested that are not covered by previous tests; and the branches to be tested are added to the fine-grained path to be tested.
[0045] Furthermore, the device also includes:
[0046] The pulling module is further used to pull multiple lines of test coverage code of the source code test process of the version to be tested;
[0047] A first merging module is used to perform byte code merging on the test coverage code to obtain an incremental coverage code of the source code of the version to be tested;
[0048] A conversion module, used for converting the incremental coverage code into a structured display incremental coverage code described in a hypertext markup language;
[0049] The second merging module is used to merge the structured displayed incremental coverage code and the structured displayed historical coverage code line by line, and update the historical test coverage information according to the result of the line by line merging.
[0050] Furthermore, the generation module includes:
[0051] A parsing unit, used for parsing the byte code of the incremental function, capturing function call information in the incremental function parsing result, and generating a function call relationship graph according to the function call information;
[0052] A calling unit, used for determining the flowchart request information of the incremental function, and calling the large model to generate a function control flowchart matching the flowchart request information;
[0053] A generating unit is used for respectively generating a function call relationship diagram and a function control flow diagram of the incremental function. After that, the method further comprises: displaying the function call relationship diagram and the function control flow diagram on a display terminal.
[0054] Furthermore, the device also includes:
[0055] a scanning module, configured to perform code scanning on the source code of the version to be tested in response to an encoding completion instruction of the source code of the version to be tested, and after feedback of code scanning problems, repeatedly perform code scanning on updated code of the source code of the version to be tested until the code scanning result of the source code of the version to be tested is passed;
[0056] A difference comparison module is used for comparing the source code of the version to be tested with the source code list of the test items corresponding to the source code of the version to be tested in response to the code scanning passing indication of the source code of the version to be tested, so as to obtain an incremental function;
[0057] A distribution module is used to create at least one review task according to the incremental function, and distribute the review task to the manual review process node to perform collaborative review on the incremental function.
[0058] Furthermore, the device also includes:
[0059] The generating module is further used to parse the byte code of the source code of the version to be tested, and generate a display page of the code to be reviewed according to the parsing result of the source code of the version to be tested;
[0060] A marking module, used for marking the code lines corresponding to the incremental functions in the code display page to be reviewed with colors, so as to obtain the code display page to be reviewed with the marked incremental functions;
[0061] An association module is used to associate the link of the to-be-reviewed code display page with the corresponding review task, so as to display the to-be-tested version source code of the marked incremental function at the terminal of the manual review process node.
[0062] According to another aspect of the present invention, a storage medium is provided, wherein at least one executable instruction is stored in the storage medium, and the executable instruction enables a processor to perform operations corresponding to the above-mentioned white box testing method.
[0063] According to another aspect of the present invention, there is provided a computer device, comprising: a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus;
[0064] The memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute operations corresponding to the above-mentioned white box testing method.
[0065] By means of the above technical solution, the technical solution provided by the embodiment of the present invention has at least the following advantages:
[0066] The present invention provides a white box testing method and device, a storage medium, and a computer device. First, historical test coverage information and incremental functions of the source code of the version to be tested are pulled, wherein the historical test coverage information is determined based on the test coverage rate merging result of the source code of the previous version of the source code of the version to be tested; the function call relationship diagram and the function control flow diagram of the incremental function are respectively generated; the incremental function is screened according to the historical test coverage information, the function call relationship diagram, and the function control flow diagram, and a test case is created according to the screening result; the test case is executed to perform white box testing on the source code of the version to be tested, and a test result of the source code of the version to be tested is generated. Compared with the prior art, the embodiment of the present invention screens the code to be tested in the source code of the version to be tested through the function call relationship diagram and the function control flow diagram of the incremental function and the code coverage information of the historical test process, and automatically generates a test case based on the screened code, which greatly avoids repeated testing of the code, reduces the test amount and test time, and effectively improves the efficiency of white box testing. At the same time, it can also meet the requirements of the rapid development means such as microservices, containerization, agile development, etc. used in the development process of financial systems and medical systems to the greatest extent for testing efficiency.
[0067] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented according to the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0068] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present invention. Moreover, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:
[0069] Figure 1 A flow chart of a white box testing method provided by an embodiment of the present invention is shown;
[0070] Figure 2 Another white box testing method flow chart provided by an embodiment of the present invention is shown;
[0071] Figure 3 A white box test flow chart of the entire process provided by an embodiment of the present invention is shown;
[0072] Figure 4 A block diagram of a white box testing device provided by an embodiment of the present invention is shown;
[0073] Figure 5 A schematic structural diagram of a computer device provided by an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0074] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
[0075] The present invention provides a white box testing method. Figure 1 As shown, the method includes:
[0076] 101. Pull the incremental function of historical test coverage information and the source code of the version to be tested.
[0077] The source code development process is a complex and systematic project, which involves multiple stages and steps to ensure that the executable program finally generated meets the functional requirements. Therefore, white box testing needs to follow the version update progress of the source code and test each version of the source code. In the real-time example of the present invention, the source code of the version to be tested can be the source code of any version. If the source code of the version to be tested is the source code of the initial version, the historical test coverage information is empty. The timing of pulling the historical test coverage information and the incremental function of the source code of the version to be tested can be triggered by the submission of the source code of the version to be tested to the code repository, or it can be triggered by a preset time, which is not specifically limited in the embodiment of the present invention.
[0078] Among them, the historical test coverage information is determined based on the test coverage merge result of the previous version of the source code of the version to be tested. Test coverage is the code coverage of the test process. Code coverage is an important concept in the test process. It refers to the proportion of the code executed in the test process to the entire source code, which can characterize the execution coverage of the code. By merging the test coverage of each version of the source code before the version to be tested, the code coverage of the white box test before the source code of the version to be tested can be obtained, and it is clear which source code has been tested and which source code has not been tested. Incremental function refers to the difference information between the source code of the version to be tested and the completed test source code, which is described with function as the minimum granularity, that is, the newly added function of the source code of the version to be tested, which can be multiple. Generating test cases based on the newly added code can make the test more targeted, thereby improving the effectiveness and reliability of software testing.
[0079] It should be noted that the source code of the version to be tested can be the software source code of a financial system, such as a trading system, a financial risk management system, etc., or it can be the software source code of a medical system, an electronic medical record system, a hospital information system, etc., and the embodiment of the present invention does not make any specific limitations.
[0080] 102. Generate a function call relationship diagram and a function control flow diagram of the incremental function respectively.
[0081] In the embodiment of the present invention, the function call relationship diagram is an external relationship diagram of the incremental function, which is used to characterize the call relationship between the incremental function and other functions in the source code. The function control flow diagram is the internal control flow of the incremental function, which is used to characterize the execution logic of the incremental function. For example, when judging A=B, call function c, and when judging A=C, jump to the next target value to continue judging.
[0082] 103. Filter incremental functions based on historical test coverage information, function call relationship diagrams, and function control flow diagrams, and create test cases based on the filtering results.
[0083] In an embodiment of the present invention, the historical test coverage information covers all the codes tested by the previous test. In order to avoid repeated testing, before creating a test case, the incremental function is screened using the historical test coverage information to filter out the code that has been tested previously. Although the incremental function is a difference function relative to the existing source code, this difference is judged from the overall dimension of the function. The called function inside the function, the statements, judgments, and branches executed inside it may also be repeated with the existing source code, and there is a possibility that they have already been tested. Filtering the tested code in the incremental function in combination with the function call relationship diagram and the function control flow diagram to obtain the untested code can greatly improve the screening accuracy of the untested code, making the created test cases more targeted. Among them, the automatic generation of test cases can be achieved by calling the test case generation component.
[0084] 104. Execute the test case to perform white box testing on the source code of the version to be tested, and generate test results of the source code of the version to be tested.
[0085] In the embodiment of the present invention, after the test case is created, the test case can be automatically run to perform white box testing on the source code of the version to be tested. Since the test case is created based on the untested code obtained by screening with the fine granularity shown by the function call relationship diagram and the function control flow diagram through the historical test coverage information, the test case can greatly avoid repeated testing of the tested code, reduce the test amount, and thus effectively improve the test efficiency of the white box test.
[0086] In one embodiment of the present invention, for further explanation and limitation, the step of screening the incremental function according to the historical test coverage information, the function call relationship diagram and the function control flow diagram, and creating a test case according to the screening result includes:
[0087] The function call relationship graph is screened according to the function call coverage information to obtain the basic path to be tested that is not covered by the previous test, and a first test case for the system test phase is generated according to the basic path to be tested. And / or,
[0088] The function control flow graph is screened according to the function execution coverage information to obtain the fine-grained path to be tested that is not covered by the previous test, and a second test case for the integration test phase is generated according to the fine-grained path to be tested.
[0089] In an embodiment of the present invention, the dynamic test phase of the white box test includes an integration test phase and a system test phase. In a test scenario where only the integration test phase needs to be performed, the test case includes a first test case. In a test scenario where only the system test phase needs to be performed, the test case includes a second test case. In a test scenario where both the integration test phase and the system test phase need to be performed, a test case including the first test case and the second test case needs to be generated.
[0090] Historical test coverage information includes function call coverage information and function execution coverage information. Function call coverage information includes functions that have been called in the previous test process. The first test case used in the system test phase is created based on the functions that were not called in the previous test in the external call of the function, that is, the basic path to be tested that was not covered by the previous test. For example, the calling functions of the current incremental function include functions 1 to 5, and the called functions in the function call coverage information are function 2 and function 3, then the basic path to be tested includes function 1, function 4 and function 5.
[0091] Among them, the function execution coverage information includes the statements, judgments and branches that have been tested in the previous test process. The second test case used in the integration test phase is created based on one or more of the statements, judgments and branches that have not been tested before in the internal logic flow of the incremental function, that is, the fine-grained path to be tested that was not covered by the previous test. For example, the incremental function includes 5 statements, 1 of which contains judgment logic, and this judgment logic contains 3 branches, and the function execution coverage information only contains one of the statements and one branch in the judgment logic. Then the fine-grained path to be tested includes 3 statements that may not be tested, and 2 branches in the judgment logic that have not been tested.
[0092] It should be noted that by filtering the function call relationship graph through function call coverage information, it is possible to filter out the tested functions called in the incremental function, avoiding repeated testing and calling of the tested functions during the system testing process, which results in unnecessary waste of time and test data. By filtering the function control flow graph through function execution coverage information, it is possible to filter out the execution logic that has been tested in the internal control flow of the incremental function, avoiding repeated testing of fine-grained codes such as judgment and branching, so as to filter the tested code at a more detailed granularity, improve the test pertinence and accuracy of the test cases, and thus improve the efficiency of the test.
[0093] In one embodiment of the present invention, for further explanation and limitation, the step of screening the function control flow graph according to the function execution coverage information to obtain the fine-grained path to be tested that is not covered by the previous test includes:
[0094] Screening each statement in the function control flow chart according to the function execution coverage information to obtain statements to be tested that are not fully covered by the previous test; determining the fine-grained path to be tested based on the statements to be tested;
[0095] In the case where the statement to be tested contains at least one determination condition, screening the determination conditions in the statement to be tested according to the function execution coverage information to obtain the determination conditions to be tested that are not covered by the previous test; adding the determination conditions to be tested to the fine-grained path to be tested;
[0096] When the determination condition to be tested includes at least two branches, the branches in the determination condition to be tested are screened according to function execution coverage information to obtain branches to be tested that are not covered by previous tests; and the branches to be tested are added to the fine-grained path to be tested.
[0097] In the embodiment of the present invention, the incremental function includes multiple statements, and the statements may also include multiple judgment logics, and the judgment logic may include one or more branches. Therefore, in the screening process, the statements that have been completely (covered) tested in the function control flow chart are filtered out, and the remaining statements that are not completely covered are used as statements to be tested. The statements to be tested that do not contain judgment conditions are directly used as fine-grained paths to be tested. For the remaining statements to be tested, the judgment conditions are screened to see if they have been covered by the test, and the judgment conditions that may not be covered are added to the fine-grained paths to be tested as judgment conditions to be tested. For the judgment conditions to be tested, the branches under the judgment conditions are screened to see if there are uncovered branches, and the judgment branches that may not be covered are added to the fine-grained paths to be tested as branches to be tested, and the final fine-grained paths to be tested are obtained. Through the hierarchical analysis of the internal code of the function, it is possible to accurately screen which branches of the cluster and which judgment conditions are not covered by the test, and to achieve accurate screening of the code, thereby improving the pertinence of the test cases and improving the test efficiency.
[0098] In an embodiment of the present invention, for further explanation and limitation, as Figure 2 As shown in step 1, the historical test coverage information includes a structured display of historical coverage code. After the test result of the source code of the version to be tested is generated, the method further includes:
[0099] 201. Pull out multiple lines of test coverage code of the test process of the source code of the version to be tested.
[0100] 202. Perform byte code merging on the test coverage code to obtain incremental coverage code of the source code of the version to be tested.
[0101] 203. Convert the incremental coverage code into a structured display incremental coverage code described in hypertext markup language.
[0102] 204. Merge the structured displayed incremental coverage code and the structured displayed historical coverage code line by line, and update the historical test coverage information according to the result of the line by line merging.
[0103] In an embodiment of the present invention, during the code testing process, the code coverage of the test process will be monitored. After the test is completed, multiple lines of test coverage code covered by the test in the source code of the version to be tested are pulled from the component used to monitor the code coverage rate. Since these test coverage codes are all codes in the same version, they can be directly merged in a byte code merge manner to obtain all the codes covered during the test process of the source code of the version to be tested, that is, the incremental coverage code. Since different versions of source code cannot be directly merged in byte code format, the incremental coverage code is structured and displayed, that is, the binary code of the incremental coverage code is converted into hypertext markup language, so that in this data format, the incremental coverage code and the historical coverage code before this are merged line by line. After each version of the source code is tested, the historical test coverage information is updated and stored in the database, so that during the test process of the next version of the source code, the updated historical test coverage information can be called for the creation of test cases for the next version of the source code.
[0104] It should be noted that integrating the global code coverage information of the code by combining the incremental code coverage and the multi-version source code coverage, and then creating test cases based on the global code coverage information can avoid code duplication testing to the greatest extent, thereby better meeting the needs of agile development with higher testing efficiency requirements.
[0105] In one embodiment of the present invention, for further explanation and limitation, the step of respectively generating a function call relationship diagram and a function control flow diagram of the incremental function includes:
[0106] Parsing the byte code of the incremental function, capturing function call information in the incremental function parsing result, and generating a function call relationship graph according to the function call information;
[0107] Determine the flowchart request information of the incremental function, and call the large model to generate a function control flowchart matching the flowchart request information;
[0108] After respectively generating the function call relationship diagram and the function control flow diagram of the incremental function, the method further comprises: displaying the function call relationship diagram and the function control flow diagram on a display terminal.
[0109] In an embodiment of the present invention, after determining the incremental function, the incremental function is parsed, and a function call relationship graph and a function control flow chart are generated for each incremental function. The function call relationship graph can be obtained by parsing the byte code of the incremental function, that is, the call information of other external functions in the source code in the current incremental function, and constructing a topological relationship graph according to the calls between functions, thereby obtaining the function call relationship graph. The function control flow chart can be generated by a large model, by calling the large model, and inputting each incremental code and the corresponding query statement (flow chart request information) into the model, and generating a flow chart representing the internal execution control logic of the function according to the model.
[0110] After the function call relationship graph and function control flow graph are generated, they can also be sent to the display terminal for structured display. Specifically, the function call relationship graph and function control flow graph can be associated with the corresponding incremental function. When the cursor is focused on the incremental function, the visualization tool is used to display the output to show the developer the calling relationship between the current incremental function and other associated functions, as well as the logical scores and loops within the function, so as to better understand the incremental function and facilitate code design, testing and optimization.
[0111] In one embodiment of the present invention, for further explanation and limitation, before the step of pulling the incremental function of the source code of the version to be tested, the method further includes:
[0112] In response to an encoding completion instruction of the source code of the version to be tested, code scanning is performed on the source code of the version to be tested, and after feedback of code scanning problems, code scanning is repeatedly performed on updated code of the source code of the version to be tested, until a code scanning result of the source code of the version to be tested is passed;
[0113] In response to a code scanning pass indication of the source code of the version to be tested, performing a difference comparison between the source code of the version to be tested and a source code list of a test item corresponding to the source code of the version to be tested to obtain an incremental function;
[0114] At least one review task is created according to the incremental function, and the review task is distributed to manual review process nodes to perform collaborative review on the incremental function.
[0115] In the embodiment of the present invention, in addition to testing the source code based on the test case, the white box test also includes detecting the problems existing in the source code of the version to be tested before the source code of the version to be tested is submitted for testing. After the developer completes the writing of the source code of the version to be tested, the code is submitted to the code warehouse, the coding completion instruction is triggered by the preset configuration hook, and the code scan is run. Specifically, the potential errors, security vulnerabilities, and coding styles of the source code of the version to be tested can be scanned by calling the scanning component, and the scanning results are merged to obtain a scanning report, and the report is fed back to the developer or the head of the development team so that they can view and fix the problems found, and submit the code again until the scan passes. After the scan passes, manual review is required to find errors in the code, irregular coding habits, potential performance problems, etc. Specifically, the source code of the version to be tested can be compared with the source code list of the test project corresponding to the source code of the version to be tested to determine the newly added and modified content of the current version of the source code. And according to the number of incremental functions and the corresponding functions, the corresponding auditors and the number of auditors are selected to distribute the review tasks. After the review passes, the source code of the version to be tested is submitted to the code warehouse, and the review task is closed.
[0116] In one embodiment of the present invention, for further explanation and limitation, the review task in step 1 carries a code display page with a marked incremental function, and the method further includes:
[0117] Parsing the bytecode of the source code of the version to be tested, and generating a display page of the code to be reviewed according to the parsing result of the source code of the version to be tested;
[0118] Marking the code lines corresponding to the incremental functions in the code display page to be reviewed with colors to obtain a code display page to be reviewed marked with the incremental functions;
[0119] The link of the to-be-reviewed code display page is associated with the corresponding review task, so as to display the to-be-tested version source code of the marked incremental function at the terminal of the manual review process node.
[0120] In the embodiment of the present invention, in order to improve the convenience of the review, the source code of the version to be tested is converted into a web page, and the incremental functions in the source code of the version to be tested are marked with different colors. For example, the incremental function is marked in yellow, and the non-incremental function is marked in gray, so that the reviewer can more intuitively capture the content that needs to be reviewed. In addition, this page can also support the reviewer to perform code review, difference comparison, annotation and discussion, status tracking and other operations on the code, providing a good collaborative environment for the review, thereby improving the review efficiency.
[0121] In an application example, the full process test of the source code of the version to be tested is implemented based on the above method. Figure 3 As shown, the source code of the version to be tested is tested in three stages: static testing, dynamic testing, and code coverage integration. In the product coding stage of the static testing process, the code scanning component is called to scan the source code of the version to be tested, and the coding standards, potential problems, security vulnerabilities, etc. are checked. In the unit test extreme of the static testing process, the code review process is started, and the code review tasks are distributed to conduct multi-step reviews such as desktop inspection, code walkthrough, and code review through manual online collaboration. In the dynamic testing process, the corresponding test cases are first generated based on the function control flow chart and the function call relationship diagram according to the fine-grained path (statement, judgment, branch) coverage strategy and the basic path coverage strategy. In the process of testing the source code of the version to be tested using the test case, code coverage monitoring is performed, so that after the test is completed, the incremental code coverage of the current version source code and the combined coverage of the historical version source code are pulled to determine the incremental code coverage and the full code coverage, thereby providing a basis for code coverage and screening in the test generation process of the subsequent version source code case.
[0122] The present invention provides a white box testing method, firstly pulling historical test coverage information and incremental functions of the source code of the version to be tested, wherein the historical test coverage information is determined based on the test coverage rate merging result of the source code of the previous version of the source code of the version to be tested; respectively generating a function call relationship diagram and a function control flow chart of the incremental function; filtering the incremental function according to the historical test coverage information, the function call relationship diagram and the function control flow chart, and creating a test case according to the filtering result; executing the test case to perform white box testing on the source code of the version to be tested, and generating a test result of the source code of the version to be tested. Compared with the prior art, the embodiment of the present invention filters the code to be tested in the source code of the version to be tested through the function call relationship diagram and the function control flow chart of the incremental function and the code coverage information of the historical test process, and automatically generates a test case based on the filtered code, which greatly avoids repeated testing of the code, reduces the test amount and test time, and thus effectively improves the efficiency of white box testing. At the same time, it can also meet the requirements of the rapid development means such as microservices, containerization, agile development, etc. used in the development process of financial systems and medical systems to the greatest extent for testing efficiency.
[0123] Furthermore, as a response to the above Figure 1 To implement the method shown in the figure, the embodiment of the present invention provides a white box testing device, such as Figure 4 As shown, the device comprises:
[0124] A pulling module 31 is used to pull historical test coverage information and an incremental function of a source code of a version to be tested, wherein the historical test coverage information is determined based on a test coverage merging result of a previous version of the source code of the version to be tested;
[0125] A generating module 32, used to generate a function call relationship diagram and a function control flow diagram of the incremental function respectively;
[0126] A creation module 33 is used to filter the incremental function according to the historical test coverage information, the function call relationship diagram and the function control flow diagram, and create a test case according to the filtering result;
[0127] The testing module 34 is used to execute the test case to perform white box testing on the source code of the version to be tested, and generate a test result of the source code of the version to be tested.
[0128] Furthermore, the creation module 33 includes:
[0129] a first screening unit, configured to screen the function call relationship graph according to the function call coverage information, obtain a basic path to be tested that is not covered by a previous test, and generate a first test case for a system test phase according to the basic path to be tested, wherein the test case includes the first test case; and / or,
[0130] The second screening unit is used to screen the function control flow chart according to the function execution coverage information, obtain the fine-grained path to be tested that is not covered by the previous test, and generate a second test case for the integration test phase based on the fine-grained path to be tested, and the test case includes the second test case.
[0131] Furthermore, in a specific application scenario, the second screening unit is specifically used to:
[0132] Screening each statement in the function control flow chart according to the function execution coverage information to obtain statements to be tested that are not fully covered by the previous test; determining the fine-grained path to be tested based on the statements to be tested;
[0133] In the case where the statement to be tested contains at least one determination condition, screening the determination conditions in the statement to be tested according to the function execution coverage information to obtain the determination conditions to be tested that are not covered by the previous test; adding the determination conditions to be tested to the fine-grained path to be tested;
[0134] When the determination condition to be tested includes at least two branches, the branches in the determination condition to be tested are screened according to function execution coverage information to obtain branches to be tested that are not covered by previous tests; and the branches to be tested are added to the fine-grained path to be tested.
[0135] Furthermore, the device also includes:
[0136] The pulling module 31 is also used to pull multiple lines of test coverage code of the source code test process of the version to be tested;
[0137] A first merging module is used to perform byte code merging on the test coverage code to obtain an incremental coverage code of the source code of the version to be tested;
[0138] A conversion module, used for converting the incremental coverage code into a structured display incremental coverage code described in a hypertext markup language;
[0139] The second merging module is used to merge the structured displayed incremental coverage code and the structured displayed historical coverage code line by line, and update the historical test coverage information according to the result of the line by line merging.
[0140] Furthermore, the generating module 32 includes:
[0141] A parsing unit, used for parsing the byte code of the incremental function, capturing function call information in the incremental function parsing result, and generating a function call relationship graph according to the function call information;
[0142] A calling unit, used for determining the flowchart request information of the incremental function, and calling the large model to generate a function control flowchart matching the flowchart request information;
[0143] A generating unit is used for respectively generating a function call relationship diagram and a function control flow diagram of the incremental function. After that, the method further comprises: displaying the function call relationship diagram and the function control flow diagram on a display terminal.
[0144] Furthermore, the device also includes:
[0145] a scanning module, configured to perform code scanning on the source code of the version to be tested in response to an encoding completion instruction of the source code of the version to be tested, and after feedback of code scanning problems, repeatedly perform code scanning on updated code of the source code of the version to be tested until the code scanning result of the source code of the version to be tested is passed;
[0146] A difference comparison module is used for comparing the source code of the version to be tested with the source code list of the test items corresponding to the source code of the version to be tested in response to the code scanning passing indication of the source code of the version to be tested, so as to obtain an incremental function;
[0147] A distribution module is used to create at least one review task according to the incremental function, and distribute the review task to the manual review process node to perform collaborative review on the incremental function.
[0148] Furthermore, the device also includes:
[0149] The generating module 32 is further used to parse the byte code of the source code of the version to be tested, and generate a display page of the code to be reviewed according to the parsing result of the source code of the version to be tested;
[0150] A marking module, used for marking the code lines corresponding to the incremental functions in the code display page to be reviewed with colors, so as to obtain the code display page to be reviewed with the marked incremental functions;
[0151] An association module is used to associate the link of the to-be-reviewed code display page with the corresponding review task, so as to display the to-be-tested version source code of the marked incremental function at the terminal of the manual review process node.
[0152] The present invention provides a white box testing device, firstly pulls historical test coverage information and incremental functions of the source code of the version to be tested, wherein the historical test coverage information is determined based on the test coverage rate merging result of the source code of the previous version of the source code of the version to be tested; respectively generates a function call relationship diagram and a function control flow chart of the incremental function; screens the incremental function according to the historical test coverage information, the function call relationship diagram and the function control flow chart, and creates a test case according to the screening result; executes the test case to perform white box testing on the source code of the version to be tested, and generates the test result of the source code of the version to be tested. Compared with the prior art, the embodiment of the present invention screens the code to be tested in the source code of the version to be tested through the function call relationship diagram and the function control flow chart of the incremental function and the code coverage information of the historical test process, and automatically generates a test case based on the screened code, which greatly avoids repeated testing of the code, reduces the test amount and test time, and thus effectively improves the efficiency of white box testing. At the same time, it can also meet the requirements of the rapid development means such as microservices, containerization, agile development, etc. used in the development process of financial systems and medical systems to the greatest extent for the test efficiency.
[0153] According to an embodiment of the present invention, a storage medium is provided, wherein the storage medium stores at least one executable instruction, and the computer executable instruction can execute the white box testing method in any of the above method embodiments.
[0154] Figure 5 A schematic diagram of the structure of a computer device provided according to an embodiment of the present invention is shown. The specific embodiment of the present invention does not limit the specific implementation of the computer device.
[0155] like Figure 5 As shown, the computer device may include: a processor (processor) 402 , a communication interface (Communications Interface) 404 , a memory (memory) 406 , and a communication bus 408 .
[0156] The processor 402 , the communication interface 404 , and the memory 406 communicate with each other via a communication bus 408 .
[0157] The communication interface 404 is used to communicate with other devices such as clients or other servers.
[0158] The processor 402 is used to execute the program 410, and specifically can execute the relevant steps in the above-mentioned white box testing method embodiment.
[0159] Specifically, the program 410 may include program codes, which include computer operation instructions.
[0160] The processor 402 may be a central processing unit (CPU), or an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present invention. The one or more processors included in the computer device may be processors of the same type, such as one or more CPUs; or processors of different types, such as one or more CPUs and one or more ASICs.
[0161] The memory 406 is used to store the program 410. The memory 406 may include a high-speed RAM memory, and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory.
[0162] The program 410 may be specifically configured to enable the processor 402 to perform the following operations:
[0163] Pulling historical test coverage information and an incremental function of the source code of the version to be tested, wherein the historical test coverage information is determined based on a test coverage merger result of a previous version of the source code of the version to be tested;
[0164] Respectively generate a function call relationship diagram and a function control flow diagram of the incremental function;
[0165] Screening the incremental functions according to the historical test coverage information, the function call relationship diagram and the function control flow diagram, and creating test cases according to the screening results;
[0166] The test case is executed to perform white box testing on the source code of the version to be tested, and a test result of the source code of the version to be tested is generated.
[0167] Obviously, those skilled in the art should understand that the above modules or steps of the present invention can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, and optionally, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order than here, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present invention is not limited to any specific combination of hardware and software.
[0168] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A white box testing method, characterized in that: include: Pulling historical test coverage information and an incremental function of the source code of the version to be tested, wherein the historical test coverage information is determined based on a test coverage merger result of a previous version of the source code of the version to be tested; Respectively generate a function call relationship diagram and a function control flow diagram of the incremental function; Screening the incremental function according to the historical test coverage information, the function call relationship diagram and the function control flow diagram, and creating a test case according to the screening result; The test case is executed to perform white box testing on the source code of the version to be tested, and a test result of the source code of the version to be tested is generated.
2. The method according to claim 1, characterized in that The historical test coverage information includes function call coverage information and function execution coverage information, and the incremental function is screened according to the historical test coverage information, the function call relationship diagram, and the function control flow diagram, and a test case is created according to the screening result, including: The function call relationship graph is screened according to the function call coverage information to obtain a basic path to be tested that is not covered by a previous test, and a first test case for a system test phase is generated according to the basic path to be tested, wherein the test case includes the first test case; and / or, The function control flow graph is screened according to the function execution coverage information to obtain the fine-grained path to be tested that is not covered by the previous test, and a second test case for the integration test phase is generated according to the fine-grained path to be tested, and the test case includes the second test case.
3. The method according to claim 2, characterized in that The step of screening the function control flow chart according to the function execution coverage information to obtain the fine-grained path to be tested that is not covered by the previous test includes: Screening each statement in the function control flow chart according to the function execution coverage information to obtain statements to be tested that are not fully covered by the previous test; determining the fine-grained path to be tested based on the statements to be tested; In the case where the statement to be tested contains at least one determination condition, the determination conditions in the statement to be tested are screened according to the function execution coverage information to obtain the determination conditions to be tested that are not covered by the previous test; and the determination conditions to be tested are added to the fine-grained path to be tested; When the determination condition to be tested includes at least two branches, the branches in the determination condition to be tested are screened according to function execution coverage information to obtain branches to be tested that are not covered by previous tests; and the branches to be tested are added to the fine-grained path to be tested.
4. The method according to claim 1, characterized in that: The historical test coverage information includes structured display of historical coverage code. After generating the test result of the source code of the version to be tested, the method further includes: Pull out multiple lines of test coverage code of the source code test process of the version to be tested; Performing byte code merging on the test coverage code to obtain incremental coverage code of the source code of the version to be tested; Converting the incremental coverage code into a structured display incremental coverage code described in a hypertext markup language; The structured displayed incremental coverage code and the structured displayed historical coverage code are merged line by line, and the historical test coverage information is updated according to the result of the line by line merging.
5. The method according to claim 1, characterized in that: The step of respectively generating a function call relationship diagram and a function control flow diagram of the incremental function comprises: Parsing the byte code of the incremental function, capturing function call information in the incremental function parsing result, and generating a function call relationship graph according to the function call information; Determine the flowchart request information of the incremental function, and call the large model to generate a function control flowchart matching the flowchart request information; After respectively generating the function call relationship diagram and the function control flow diagram of the incremental function, the method further comprises: displaying the function call relationship diagram and the function control flow diagram on a display terminal.
6. The method according to any one of claims 1 to 5, characterized in that Before pulling the incremental function of the source code of the version to be tested, the method further includes: In response to an encoding completion instruction of the source code of the version to be tested, code scanning is performed on the source code of the version to be tested, and after feedback of code scanning problems, code scanning is repeatedly performed on updated code of the source code of the version to be tested, until a code scanning result of the source code of the version to be tested is passed; In response to a code scanning pass indication of the source code of the version to be tested, performing a difference comparison between the source code of the version to be tested and a source code list of a test item corresponding to the source code of the version to be tested to obtain an incremental function; At least one review task is created according to the incremental function, and the review task is distributed to manual review process nodes to perform collaborative review on the incremental function.
7. The method according to claim 6, characterized in that The review task carries a code display page with a marked incremental function, and the method further includes: Parsing the bytecode of the source code of the version to be tested, and generating a display page of the code to be reviewed according to the parsing result of the source code of the version to be tested; Marking the code lines corresponding to the incremental functions in the code display page to be reviewed with colors to obtain a code display page to be reviewed marked with the incremental functions; The link of the to-be-reviewed code display page is associated with the corresponding review task, so as to display the to-be-tested version source code of the marked incremental function at the terminal of the manual review process node.
8. A white box testing device, characterized in that: include: A pulling module, used to pull historical test coverage information and an incremental function of a source code of a version to be tested, wherein the historical test coverage information is determined based on a test coverage merging result of a previous version of the source code of the version to be tested; A generating module, used to generate a function call relationship diagram and a function control flow diagram of the incremental function respectively; A creation module is used to screen the incremental function according to the historical test coverage information, the function call relationship diagram and the function control flow diagram, and create a test case according to the screening result; The test module is used to execute the test case to perform white box test on the source code of the version to be tested, and generate the test result of the source code of the version to be tested.
9. A storage medium storing at least one executable instruction, wherein the executable instruction enables a processor to perform an operation corresponding to the white-box testing method according to any one of claims 1 to 7.
10. A computer device comprising: A processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus; The memory is used to store at least one executable instruction, and the executable instruction enables the processor to perform an operation corresponding to the white box testing method according to any one of claims 1-7.
Citation Information
Cited By
Hardware code submission method, electronic equipment and medium
CN119621590A
Hardware code submission method, electronic device and medium
CN119621590B