Code change comparison result optimization method, system, equipment and medium
Through Python scripts, the problem of high manual error and time cost in code change comparison is solved, and efficient and accurate code change comparison and document generation is achieved, helping testers quickly determine the scope of regression tests.
Patent Information
- Application Number
- CN202411251708.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-09
- Publication Date
- 2025-02-11
AI Technical Summary
The prior art has problems of manual error and high time cost in code change comparison, and the generated documents are not clear enough.
Automatically complete the code comparison process through Python scripts, use command prompts and TFS to obtain the code change set, store it in a text document, and write the change information to a spreadsheet document. Use pre-configured keyword judgment conditions to analyze the impact of code changes on existing use cases.
It improves the efficiency and accuracy of code changes and comparison, reduces the error of manual writing of documents, increases the clarity and readability of documents, and helps testers quickly determine the scope of regression testing.
Smart Images

Figure CN119415409A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of code testing technology, and in particular to a method, system, device and medium for optimizing code change comparison results. Background Art
[0002] In white-box testing, it is necessary to decide whether to carry out corresponding regression testing activities, such as static testing, unit testing, and integration testing, based on whether the code has been changed. At the same time, when obtaining the corresponding security certification requirements, a code change scope table is also required as a test basis. In existing testing activities, this work often requires a lot of manpower and working hours to do analysis and statistics. Using automated comparison scripts instead of manual work can improve the efficiency of testing and the accuracy of statistics.
[0003] At present, the solution adopted by everyone is that testers use comparison tools such as the comparison tool provided by visual studio, BeyondCompare, Winmerge and other tools to compare codes. The comparison personnel manually extract the changed codes and analyze the reasons to organize and count the code changes; or use scripts to compare the changes in the code between two versions and output the changed parts to documents.
[0004] When the amount of code is large, it is easy to cause manual errors and distort the results by manually extracting the changed code and analyzing the reasons and statistics of the code changes by the comparison personnel. If the amount of code changes is large, it will waste the personnel's time cost. The existing scripts generate documents in TXT format or HTML format that are not easy to read and view, and it is not clear when viewing the code changes. Therefore, the advantage of using scripts to generate code change tables is more obvious.
[0005] Therefore, how to provide a method, system, device and medium for optimizing code change comparison results is a problem that needs to be solved urgently. Summary of the invention
[0006] The embodiments of the present invention provide a code change comparison result optimization method, system, device and medium to solve the above-mentioned technical problems existing in the prior art.
[0007] In order to have a basic understanding of some aspects of the disclosed embodiments, a brief summary is given below. This summary is not intended to be a general review, nor is it intended to identify key / important components or to delineate the scope of protection of these embodiments. Its only purpose is to present some concepts in a simple form as a preface to the detailed description that follows.
[0008] According to a first aspect of an embodiment of the present invention, a method for optimizing a code change comparison result is provided.
[0009] In one embodiment, the code change comparison result optimization method includes:
[0010] Call the command prompt, and based on the command of the command prompt, obtain the code of different change sets and store them in a text document;
[0011] The text document is read and the change information is written into a spreadsheet document.
[0012] In one embodiment, calling a command prompt, and based on a command of the command prompt, obtaining codes of different change sets and storing them in a text document comprises:
[0013] Use os.popen to call cmd command;
[0014] Use the tf command tf vc diff to obtain different change set codes on TFS and save the changes to a text document.
[0015] In one embodiment, reading the text document and writing the changed content into the electronic spreadsheet document comprises:
[0016] Call the open function to open and read the text document;
[0017] The changed content of the text document is read row by row and returned to the list; based on the pre-configured keyword judgment condition, the judgment return value is output, and the judgment return value and the change information are filled in the electronic spreadsheet document, and the electronic spreadsheet document is saved in this directory.
[0018] In one embodiment, the outputting of the judgment return value based on the pre-configured keyword judgment condition and filling the judgment return value and the change information into the electronic spreadsheet document includes:
[0019] Determine whether the read change content contains keywords. If it contains keywords, the output judgment return value is 1; if it does not contain keywords, the output judgment return value is 0; wherein the keywords include if, while, switch and for;
[0020] Extract the change information from the change content with the judgment return value of 1, and fill it into the electronic spreadsheet document in sequence; wherein the change information includes the file name, function name, before change, after change, change content, whether it affects the existing use case and remarks.
[0021] According to a second aspect of an embodiment of the present invention, a code change comparison result optimization system is provided.
[0022] In one embodiment, the code change comparison result optimization system includes:
[0023] The change set acquisition module is used to call the command prompt and obtain the codes of different change sets based on the commands of the command prompt and store them in text documents;
[0024] The change comparison module is used to read the text document and write the change information into the electronic spreadsheet document.
[0025] In one embodiment, the change set acquisition module includes: a command calling module and a code acquisition module, wherein:
[0026] The command calling module is used to call the cmd command using os.popen;
[0027] The code acquisition module is used to use the tf command tf vc diff to obtain different change set codes on TFS and save the changed content into a text document.
[0028] In one embodiment, the change comparison module includes: a document reading module and a result entry module, wherein:
[0029] The document reading module is used to call the open function to open and read the text document;
[0030] The result entry module is used to traverse and read the changed content of the text document row by row and return it to a list; based on pre-configured keyword judgment conditions, output the judgment return value, and fill the judgment return value and change information into a spreadsheet document, and save the spreadsheet document to this directory.
[0031] In one embodiment, the result entry module includes: a keyword judgment module and a change information identification module, wherein:
[0032] The keyword judgment module is used to judge whether the read change content contains the keyword. If it contains the keyword, the output judgment return value is 1; if it does not contain the keyword, the output judgment return value is 0; wherein the keywords include if, while, switch and for;
[0033] The change information identification module is used to extract the change information in the change content with the judgment return value of 1, and fill it into the electronic spreadsheet document in sequence; wherein, the change information includes the file name, function name, before change, after change, change content, whether it affects the existing use case and remarks.
[0034] According to a third aspect of an embodiment of the present invention, a computer device is provided.
[0035] In some embodiments, the computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the steps of the above method when executing the computer program.
[0036] According to a fourth aspect of embodiments of the present invention, a computer-readable storage medium is provided.
[0037] In one embodiment, the computer-readable storage medium stores a computer program, and the computer program implements the steps of the above method when executed by a processor.
[0038] The technical solution provided by the embodiment of the present invention may have the following beneficial effects:
[0039] The present invention uses Python scripts to automatically complete the code comparison process, quickly and accurately output comparison results, including the impact of different change contents on existing test cases, so as to quickly determine the regression test scope; solve the demand for determining the test scope in regression testing caused by code changes, and use TFS to perform version control and management of the code. After each comparison between the changed version and the code content of the previous change set, the changed part is output to Excel. In addition, the script will analyze the changes in the code to confirm whether the original test cases are affected, so as to help testers save time for comparing the changed content after the code is changed to determine the test scope, increase efficiency, speed up work progress, reduce errors that may be caused by manual document writing, and increase the accuracy of the document.
[0040] It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0042] Figure 1 is a flow chart of a method for optimizing code change comparison results according to an exemplary embodiment;
[0043] Figure 2 is a system principle block diagram of a code change comparison result optimization system according to an exemplary embodiment;
[0044] Figure 3 The figure is a schematic diagram showing the structure of a computer device according to an exemplary embodiment. DETAILED DESCRIPTION
[0045] The following description and accompanying drawings fully illustrate the specific embodiments of this article so that those skilled in the art can practice them. Parts and features of some embodiments may be included in or replace parts and features of other embodiments. The scope of the embodiments of this article includes the entire scope of the claims, as well as all available equivalents of the claims. Herein, the terms "first", "second", etc. are only used to distinguish one element from another, without requiring or implying any actual relationship or order between these elements. In fact, the first element can also be called the second element, and vice versa. Moreover, the terms "include", "comprise" or any other variant thereof are intended to cover non-exclusive inclusion, so that the structure, device or equipment including a series of elements includes not only those elements, but also other elements that are not explicitly listed, or also include elements inherent to such structure, device or equipment. In the absence of more restrictions, the elements defined by the sentence "including one..." do not exclude the existence of other identical elements in the structure, device or equipment including the elements. Each embodiment is described in a progressive manner herein, and each embodiment focuses on the differences from other embodiments, and the same and similar parts between the embodiments can be referred to each other.
[0046] The terms "longitudinal", "lateral", "upper", "lower", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside", etc. in this document indicate the orientation or position relationship based on the orientation or position relationship shown in the drawings, and are only for the convenience of describing this document and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operate in a specific orientation, and therefore cannot be understood as a limitation on the present invention. In the description of this document, unless otherwise specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a mechanical connection or an electrical connection, it can also be the internal communication of two elements, it can be a direct connection, or it can be an indirect connection through an intermediate medium. For ordinary technicians in this field, the specific meanings of the above terms can be understood according to specific circumstances.
[0047] As used herein, the term "plurality" means two or more than two, unless otherwise specified.
[0048] In this document, the character " / " indicates that the preceding and following objects are in an "or" relationship. For example, A / B means: A or B.
[0049] In this article, the term "and / or" is a description of the association relationship between objects, indicating that three relationships may exist. For example, A and / or B means: A or B, or, A and B.
[0050] It should be understood that, although the various steps in the flow chart are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear description in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the figure may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these sub-steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
[0051] Each module in the device or system of the present application can be implemented in whole or in part by software, hardware, or a combination thereof. The above modules can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to the above modules.
[0052] In the absence of conflict, the embodiments of the present invention and the features of the embodiments may be combined with each other.
[0053] Figure 1 An embodiment of a method for optimizing code change comparison results of the present invention is shown.
[0054] In this optional embodiment, the code change comparison result optimization method includes:
[0055] Step S101, calling a command prompt, and based on the command of the command prompt, obtaining codes of different change sets and storing them in a text document;
[0056] Step S103: read the text document and write the change information into the electronic spreadsheet document.
[0057] In this optional embodiment, when the command prompt is called and the codes of different change sets are obtained based on the command of the command prompt and stored in a text document, the cmd command can be called using os.popen; the tf command tf vc diff is used to obtain the codes of different change sets on TFS, and the changes are saved in the text document. In this optional embodiment, when the text document is read and the changes are written to the spreadsheet document, the open function can be called to open and read the text document; the changes of the text document are read by line traversal and returned to the list; based on the pre-configured keyword judgment condition, the judgment return value is output, and the judgment return value and the change information are filled in the spreadsheet document, and the spreadsheet document is saved in this directory.
[0058] Specifically, first call the command prompt through Python, use the command prompt command to obtain the code of different change sets on TFS and save it to the generated temporary txt document; then read the document and write the differences into Excel, including the following aspects:
[0059] 1. Generate txt document
[0060] 1.1. Call cmd command: Use os.popen to call cmd command.
[0061] 1.2. Use the tf command tf vc diff to obtain the different change set codes on tfs, and save the changed content to the generated txt document (text document).
[0062] 2. Read the txt document and save it to Excel
[0063] 2.1. Use the open function to open and read the txt document.
[0064] 2.2. Read the txt document content line by line and return it to the list, determine whether the read change content contains the keywords of the judgment conditions such as if, while, switch, etc., return 1 if it contains the keyword, and return 0 if it does not, write the change information and the judgment return value into the Excel document (spreadsheet document) according to the format. Save the Excel document to this directory.
[0065] In this optional embodiment, when the judgment return value is output based on the pre-configured keyword judgment condition, and the judgment return value and change information are filled in the spreadsheet document, it can be judged whether the read change content contains the keyword. If it contains the keyword, the output judgment return value is 1, and if it does not contain the keyword, the output judgment return value is 0; wherein, the keywords include if, while, switch and for; the change information in the change content with the judgment return value of 1 is extracted and filled in the spreadsheet document in sequence; wherein, the change information includes the file name, function name, before change, after change, changed content, whether it affects the existing use case and remarks.
[0066] Specifically, the specific change information about "whether it affects existing use cases" is determined as follows:
[0067] 1) Determine whether the if, while or for condition is increased. If the condition is increased, it will affect the existing use case;
[0068] 2) Determine whether the if, while or for condition has changed. If so, it will affect the existing use case;
[0069] 3) Determine whether a case is added in the switch. If a case statement is added, it will affect the existing use case;
[0070] 4) Determine whether the switch condition has changed. If so, it will affect the existing use case;
[0071] 5) Determine whether there are any assignment statements that have changed. If so, whether the following if, while, switch, and for statements are used. If so, how will the existing use cases be affected?
[0072] 6) Determine whether there are any additional assignment statements. If so, whether they are used in the following if, while, switch, and for statements. If so, how will they affect the existing use cases?
[0073] 7) Determine whether the input parameters of this function have changed. Whether it is increased, decreased or changed, it will affect the existing use case.
[0074] Figure 2 An embodiment of a code change comparison result optimization system of the present invention is shown.
[0075] In this optional embodiment, the code change comparison result optimization system includes:
[0076] The change set acquisition module 201 is used to call the command prompt, and based on the command of the command prompt, obtain the codes of different change sets and store them in a text document;
[0077] The change comparison module 203 is used to read the text document and write the change information into the electronic spreadsheet document.
[0078] In this optional embodiment, the change set collection module 201 includes: a command calling module (not shown in the figure) and a code acquisition module (not shown in the figure), wherein the command calling module is used to use os.popen to call the cmd command; the code acquisition module is used to use the tf command tf vc diff to obtain different change set codes on TFS and save the changed content to a text document.
[0079] In this optional embodiment, the change comparison module 203 includes: a document reading module (not shown in the figure) and a result entry module (not shown in the figure), wherein the document reading module is used to call the open function to open and read the text document; the result entry module is used to traverse the text document line by line and read the change content and return it to the list; based on the pre-configured keyword judgment condition, the judgment return value is output, and the judgment return value and change information are filled in the spreadsheet document, and the spreadsheet document is saved in this directory.
[0080] In this optional embodiment, the result entry module includes: a keyword judgment module (not shown in the figure) and a change information identification module (not shown in the figure), wherein the keyword judgment module is used to judge whether the read change content contains keywords. If it contains keywords, the output judgment return value is 1, and if it does not contain keywords, the output judgment return value is 0; wherein the keywords include if, while, switch and for; the change information identification module is used to extract the change information in the change content with the judgment return value of 1, and fill it into the electronic spreadsheet document in sequence; wherein the change information includes the file name, function name, before change, after change, change content, whether it affects the existing use case and remarks.
[0081] In specific application, the main content of the present invention is based on two parts. First, the command prompt is called through Python, and the codes of different change sets on TFS are obtained using the commands of the command prompt and saved in the generated temporary txt document; then the document is read and the differences are written into Excel.
[0082] 1. Generate txt document
[0083] 1.1. Call cmd command: Use os.popen to call cmd command.
[0084] 1.2. Use the tf command tf vc diff to obtain the different change set codes on tfs, and save the changed content to the generated txt document (text document).
[0085] 2. Read the txt document and save it to Excel
[0086] 2.1. Use the open function to open and read the txt document.
[0087] 2.2. Read the txt document content line by line and return it to the list, judge whether the read change content contains the keywords of the judgment conditions such as if, while, switch, etc., return 1 if it contains the keywords, and return 0 if it does not, and write the change information and judgment return value into the Excel document (spreadsheet document) according to the format. Save the Excel document to this directory, and the Excel format is shown in Table 1.
[0088] Table 1: Spreadsheet document (change information)
[0089]
[0090] In addition, the specific change information on "whether it affects existing use cases" is as follows:
[0091] 1) Determine whether the if, while or for condition is increased. If the condition is increased, it will affect the existing use case;
[0092] 2) Determine whether the if, while or for condition has changed. If so, it will affect the existing use case;
[0093] 3) Determine whether a case is added in the switch. If a case statement is added, it will affect the existing use case;
[0094] 4) Determine whether the switch condition has changed. If so, it will affect the existing use case;
[0095] 5) Determine whether there are any assignment statements that have changed. If so, whether the following if, while, switch, and for statements are used. If so, how will the existing use cases be affected?
[0096] 6) Determine whether there are any additional assignment statements. If so, whether they are used in the following if, while, switch, and for statements. If so, how will they affect the existing use cases?
[0097] 7) Determine whether the input parameters of this function have changed. Whether it is increased, decreased or changed, it will affect the existing use case.
[0098] The above operation is the technical solution for automatically generating code change documents by comparing codes of different change sets on TFS, which effectively reduces the time cost required for manual extraction.
[0099] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 3 As shown. The computer device includes a processor, a memory and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store static information and dynamic information data. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, the steps in the above method embodiment are implemented.
[0100] Those skilled in the art will understand that Figure 3 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present invention, and does not constitute a limitation on the computer device to which the solution of the present invention is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0101] In addition, the present invention also provides a computer device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiment when executing the computer program.
[0102] In addition, the present invention further provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps in the above method embodiment are implemented.
[0103] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided by the present invention can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).
[0104] The present invention is not limited to the structures which have been described above and shown in the drawings, and various modifications and changes may be made without departing from the scope thereof. The scope of the present invention is limited only by the appended claims.
Claims
1. A method for optimizing code change comparison results, characterized in that: include: Call the command prompt, and based on the command of the command prompt, obtain the code of different change sets and store them in a text document; Read the text document and write the change information into a spreadsheet document; The calling of the command prompt and obtaining the codes of different change sets based on the commands of the command prompt and storing them in a text document include: Use os.popen to call cmd command; Use the tf command tf vc diff to obtain different change set codes on TFS and save the changes to a text document; The step of reading the text document and writing the changed content into the electronic spreadsheet document comprises: Call the open function to open and read the text document; The changed content of the text document is read row by row and returned to the list; based on the pre-configured keyword judgment condition, the judgment return value is output, and the judgment return value and the change information are filled in the electronic spreadsheet document, and the electronic spreadsheet document is saved in this directory.
2. The code change comparison result optimization method according to claim 1, characterized in that: The step of outputting a judgment return value based on a pre-configured keyword judgment condition and filling the judgment return value and the change information into an electronic spreadsheet document includes: Determine whether the read change content contains keywords. If it contains keywords, the output judgment return value is 1; if it does not contain keywords, the output judgment return value is 0; wherein the keywords include if, while, switch and for; Extract the change information from the change content with the judgment return value of 1, and fill it into the electronic spreadsheet document in sequence; wherein the change information includes the file name, function name, before change, after change, change content, whether it affects the existing use case and remarks.
3. A code change comparison result optimization system, characterized in that: include: The change set acquisition module is used to call the command prompt and obtain the codes of different change sets based on the commands of the command prompt and store them in text documents; The change comparison module is used to read the text document and write the change information into the electronic spreadsheet document.
4. The code change comparison result optimization system according to claim 3, characterized in that: The change set acquisition module includes: a command calling module and a code acquisition module, wherein: The command calling module is used to call the cmd command using os.popen; The code acquisition module is used to use the tf command tf vc diff to obtain different change set codes on TFS and save the changed content into a text document.
5. The code change comparison result optimization system according to claim 4, characterized in that: The change comparison module includes: a document reading module and a result entry module, wherein: The document reading module is used to call the open function to open and read the text document; The result entry module is used to traverse and read the changed content of the text document row by row and return it to a list; based on pre-configured keyword judgment conditions, output the judgment return value, and fill the judgment return value and change information into a spreadsheet document, and save the spreadsheet document to this directory.
6. The code change comparison result optimization system according to claim 5, characterized in that: The result entry module includes: a keyword judgment module and a change information identification module, wherein: The keyword judgment module is used to judge whether the read change content contains the keyword. If it contains the keyword, the output judgment return value is 1; if it does not contain the keyword, the output judgment return value is 0; wherein the keywords include if, while, switch and for; The change information identification module is used to extract the change information in the change content with the judgment return value of 1, and fill it into the electronic spreadsheet document in sequence; wherein, the change information includes the file name, function name, before change, after change, change content, whether it affects the existing use case and remarks.
7. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 2 are implemented.
8. 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 method according to any one of claims 1 to 2 are implemented.