Code atomic power testing method and device, electronic equipment and program product
By comparing the atomic capability list of project codes and project requirements documents, atomic capability inspection is automatically completed, which solves the problems of low manual inspection efficiency and high error detection rate, and achieves more efficient and accurate atomic capability inspection.
Patent Information
- Application Number
- CN202411674455.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-21
- Publication Date
- 2025-02-11
AI Technical Summary
In the prior art, the atomic capability inspection of project codes relies on manual verification, resulting in low efficiency and high false detection rates.
Automatically complete the atomic capability test of the project code by obtaining the code atomic capability list and the document atomic capability list and comparing them one by one.
The efficiency and accuracy of atomic capability inspection of project codes have been improved, which has been significantly improved compared with the traditional method of manual verification.
Smart Images

Figure CN119415401A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of software testing technology, and in particular to a method, device, electronic device and computer program product for checking the atomic capability of codes. Background Art
[0002] Atomic capability refers to the indivisible and uninterruptible characteristics of an operation or a group of operations during execution. In the project code, an atomic capability can be understood as a text segment contained in the code text that is used to implement an atomic operation. Since atomic capabilities play an important role in implementing the required functions of the project code, after the project code is written, it is often necessary to check whether there are problems with the atomic capabilities described in the code text. At present, manual verification is usually used for verification, which has the problems of low verification efficiency and high false detection rate. Summary of the invention
[0003] In view of this, the embodiments of the present application provide a method, device, electronic device and computer program product for checking the atomic capability of codes, which can improve the efficiency and accuracy of atomic capability checking of project codes.
[0004] A first aspect of an embodiment of the present application provides a method for verifying code atomicity, including:
[0005] Obtain a code atomic capability list and a document atomic capability list; wherein the code atomic capability list records all atomic capabilities of the project code, and the document atomic capability list records all atomic capabilities of the project requirement document corresponding to the project code;
[0006] Compare the code atomic capability list with the document atomic capability list, and based on the comparison results, determine the atomic capability problems existing in the project code.
[0007] In the technical solution of the embodiment of the present application, all atomic capabilities of the project code are integrated into a code atomic capability list, and all atomic capabilities of the project requirement document are integrated into a document atomic capability list. After that, the code atomic capability list and the document atomic capability list only need to be compared one by one in terms of atomic capabilities to know whether there are discrepancies between the atomic capabilities described in the project code and the project requirement document, thereby determining whether there are atomic capability problems in the project code. The above process automatically completes the atomic capability inspection of the project code by list comparison, which can greatly improve the efficiency and accuracy of the inspection compared to the traditional method of manual verification.
[0008] In one implementation of the embodiment of the present application, the code atom capability list is obtained in the following manner:
[0009] Recursively scan the project file directory where the project code is located to find the code files with atomic capabilities in the project file directory;
[0010] Parse the code file to obtain the atomic capability information of the code file;
[0011] Generate a code atomic capability list according to the atomic capability information of the code file.
[0012] In one implementation of the embodiment of the present application, the project code is written in Java language; searching for code files with atomic capabilities in the project file directory includes:
[0013] Find all files with the suffix ".java" in the project file directory as code files;
[0014] Parse the code file to obtain the atomic capability information of the code file, including:
[0015] The javaparser tool is used to extract the function text starting with a specified string in the code file, and the function text is parsed to obtain the atomic capability information of the code file.
[0016] In one implementation of the embodiment of the present application, the project requirement document is a table document, and each row of the table document records the attribute information of an atomic capability; the document atomic capability list is obtained in the following manner:
[0017] Parse the content of the table document line by line to obtain the attribute information of each atomic capability recorded in the table document;
[0018] According to the attribute information of each atomic capability recorded in the table document, a document atomic capability list is generated according to the atomic capability as a unit.
[0019] In an implementation of the embodiment of the present application, each column of the table document records one kind of attribute information of the atomic capability; let the target content be any row of the table document, parse the content of the table document row by row, and obtain the attribute information of each atomic capability of the table document, including:
[0020] According to the specified characters in the target content, split the target content into individual cell texts;
[0021] For each cell text, determine the attribute name corresponding to the cell text according to the attribute information corresponding to the column where the cell text is located, and use the cell text as the attribute value corresponding to the attribute name;
[0022] According to the attribute name and attribute value corresponding to each cell text, the attribute information of the atomic capability corresponding to the target content is determined.
[0023] In an implementation of the embodiment of the present application, after generating a document atomic capability list according to the attribute information of each atomic capability of the table document in units of atomic capabilities, the method further includes:
[0024] Check whether there is any error in the attribute information of each atomic capability in the document atomic capability list;
[0025] A document error report is generated based on the atomic capabilities in the document atomic capability list that have erroneous attribute information.
[0026] In an implementation of the embodiment of the present application, determining the atomic capability problem existing in the project code according to the comparison result includes:
[0027] If there is any atomic capability in the code atomic capability list that is not in the document atomic capability list, it is determined that the project code has an outdated atomic capability problem;
[0028] If any atomic capability in the document atomic capability list does not exist in the code atomic capability list, it is determined that the project code has a problem of missing atomic capabilities;
[0029] If the code atomic capability list and the document atomic capability list contain the same atomic capability with different attribute information, it is determined that there is an atomic capability error problem in the project code.
[0030] A second aspect of an embodiment of the present application provides a device for testing code atomicity, including:
[0031] A list acquisition module is used to acquire a code atomic capability list and a document atomic capability list; wherein the code atomic capability list records all atomic capabilities of the project code, and the document atomic capability list records all atomic capabilities of the project requirement document corresponding to the project code;
[0032] The list comparison module is used to compare the code atomic capability list with the document atomic capability list, and determine the atomic capability problems existing in the project code based on the comparison results.
[0033] A third aspect of an embodiment of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the method for verifying the code atomic capability provided in the first aspect of the embodiment of the present application is implemented.
[0034] A fourth aspect of the embodiments of the present application provides a computer program product. When the computer program product is run on an electronic device, the electronic device executes the code atomic capability verification method provided in the first aspect of the embodiments of the present application.
[0035] The fifth aspect of the embodiments of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the code atomic capability verification method provided by the first aspect of the embodiments of the present application.
[0036] It can be understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] Figure 1 It is a flow chart of a method for checking code atomicity provided in an embodiment of the present application;
[0038] Figure 2 This is a schematic diagram of an operation flow for checking the atomic capability of a code provided by an embodiment of the present application;
[0039] Figure 3 This is a schematic diagram of an operation flow of batch generating atomic capabilities provided by an embodiment of the present application;
[0040] Figure 4 It is a structural schematic diagram of a code atomic capability testing device provided in an embodiment of the present application;
[0041] Figure 5 It is a schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0042] In the following description, for the purpose of illustration rather than limitation, specific details such as specific system structures, technologies, etc. are proposed, so as to thoroughly understand the embodiments of the present application. However, it should be clear to those skilled in the art that the present application can also be implemented in other embodiments without these specific details. In other cases, the detailed description of well-known systems, devices, circuits and methods is omitted to prevent unnecessary details from hindering the description of the present application. In addition, in the description of the present application specification and the attached claims, the terms "first", "second", "third" etc. are only used to distinguish the description, and cannot be interpreted as indicating or suggesting relative importance.
[0043] At present, after the project code is written, it is usually necessary to manually check whether there are problems with each atomic capability in the code text. Assuming that the code text has 300 atomic capabilities and the manual inspection time for each atomic capability is about 3 minutes, it will take about 15 hours in total to complete the inspection. It can be seen that there is a problem of low inspection efficiency. In addition, the false detection rate of manual inspection is also relatively high.
[0044] In view of the above problems, the embodiments of the present application provide a method, device, electronic device and computer program product for checking the atomic capability of a code, which automatically completes the atomic capability check of a project code by list comparison, and can greatly improve the efficiency and accuracy of the check compared to the traditional method of manual check. For more specific technical implementation details of the embodiments of the present application, please refer to the various method embodiments described below.
[0045] It should be understood that the execution subjects of the various method embodiments of the present application are various types of electronic devices, such as mobile phones, tablet computers, wearable devices, vehicle-mounted terminals, augmented reality (AR) / virtual reality (VR) devices, laptop computers, ultra-mobile personal computers (UMPC), netbooks, personal digital assistants (PDA), etc. The embodiments of the present application do not impose any restrictions on the specific types of the electronic devices.
[0046] See also Figure 1 , showing a method for checking the atomic capability of a code provided by an embodiment of the present application, including:
[0047] 101. Obtain a code atomic capability list and a document atomic capability list; wherein the code atomic capability list records all atomic capabilities of the project code, and the document atomic capability list records all atomic capabilities of the project requirement document corresponding to the project code;
[0048] All atomic capabilities of the project code are integrated into a code atomic capability list, and all atomic capabilities of the project requirement document are integrated into a document atomic capability list. To facilitate comparison of the two atomic capability lists, the content formats of the two atomic capability lists can be made consistent, for example, both are arranged in units of atomic capabilities. Among them, the atomic capabilities of the project code refer to all text segments used to implement atomic operations contained in the code text, and a text segment used to implement an atomic operation is called an atomic capability. The atomic capabilities of the project requirement document refer to the text content used to describe the atomic operations required by the project contained in the project requirement document, and the text content used to describe an atomic operation is called an atomic capability. For example, assuming that an atomic capability of the project requirement document has the following text content: "Voice, SETrigger.setupKwsVoice(), parameter name: texts, parameter type: string array, whether it must be passed: yes, parameter description: broadcast content list...", then this part of the text content is used to represent the relevant information of the atomic operation X corresponding to the atomic capability named "SETrigger.setupKwsVoice()". In the project code, the code text segment for implementing the atomic operation X represents the atomic capability named “SETrigger.setupKwsVoice()”.
[0049] For a certain software system, its project requirement document can be obtained for parsing, and information about all atomic capabilities of the document can be obtained. This information can be integrated into a list based on atomic capabilities, thereby obtaining a document atomic capability list. Similarly, the project code of the software system can be obtained for parsing, and information about all atomic capabilities of the code text can be obtained. This information can be integrated into another list based on atomic capabilities, thereby obtaining a code atomic capability list. The content format of the two atomic capability lists can be: information about atomic capability 1, information about atomic capability 2… information about atomic capability n, where the information about each atomic capability can be recorded in a line in the atomic capability list. The following specifically describes how to obtain the code atomic capability list and the document atomic capability list.
[0050] In one implementation of the embodiment of the present application, the code atom capability list is obtained in the following manner:
[0051] (1) Recursively scan the project file directory where the project code is located to find the code files with atomic capabilities in the project file directory;
[0052] (2) Parse the code file to obtain the atomic capability information of the code file;
[0053] (3) Generate a code atomic capability list based on the atomic capability information of the code file.
[0054] When generating a code atomic capability list, you need to first collect information on all atomic capabilities that the project code has. Usually, the project code includes multiple code files, some of which have atomic capabilities, while other code files do not. Therefore, you first need to recursively scan the project file directory where the project code is located to find code files with atomic capabilities in the project file directory. These code files can be integrated into a file list. Then, you can use a third-party code parsing tool or parse these code files according to preset parsing rules to find out the information on all atomic capabilities in the code files. Here you can obtain key information such as the name and parameter list of the atomic capability, and then generate a list with the obtained atomic capability information in units of atomic capabilities to obtain a code atomic capability list.
[0055] In one implementation of the embodiment of the present application, the project code is written in Java language; searching for code files with atomic capabilities in the project file directory includes:
[0056] Find all files with the suffix ".java" in the project file directory as code files;
[0057] Parse the code file to obtain the atomic capability information of the code file, including:
[0058] The javaparser tool is used to extract the function text starting with a specified string in the code file, and the function text is parsed to obtain the atomic capability information of the code file.
[0059] Assuming that the project code is written in Java, each atomic capability in the Java code file will be expressed as a function text, and the function text has a specified string as the beginning, for example, one of the specified strings "@SEAction", "@SETrigger" and "@SECondition" as the beginning, so the atomic capability information in the code file can be extracted according to this feature. Specifically, first recursively scan the project file directory to find all the files in the project file directory, and identify all the files with the suffix ".java". These files are code files with atomic capabilities in the project file directory, and their absolute paths can be recorded to generate a file list. Then traverse the file list, load each code file in the file list one by one, use the javaparser tool to extract the function text that starts with the specified string in each code file, and parse each function text to obtain the atomic capability information of each code file. Finally, integrate the atomic capability information of all code files, and generate the code atomic capability list in units of atomic capabilities. Javaparser is based on an open source Java library, which allows developers to parse, modify, generate and operate Java source code in Java programs. Javaparser uses an abstract syntax tree to represent the structure of Java source code, allowing developers to easily traverse and modify the code. Using the three-party parsing library of Javaparser, the key information of all atomic capabilities in the Java code can be accurately identified, including the name of the atomic capability, the parameter list, and the parameter name, parameter type and whether it is required to pass in the parameter list. The three-party parsing library of Javaparser is specially used to parse Java code. It has the function of extracting function text in Java code. If it is detected that there is a function text starting with the above specified string, the function text is marked as an atomic capability, and the content of the function text is further parsed until the function name, parameter name, parameter type and whether it is required to pass are obtained, and this information is extracted as the information of an atomic capability. Finally, the information of all atomic capabilities extracted from each Java code file is integrated into a list to obtain the above code atomic capability list.
[0060] The above is a method for obtaining a code atomic capability list. Next, a method for obtaining a document atomic capability list is described.
[0061] In one implementation of the embodiment of the present application, the project requirement document is a table document, and each row of the table document records the attribute information of an atomic capability; the document atomic capability list is obtained in the following manner:
[0062] (1) Parse the content of the table document line by line to obtain the attribute information of each atomic capability recorded in the table document;
[0063] (2) Based on the attribute information of each atomic capability recorded in the table document, a document atomic capability list is generated according to the atomic capability.
[0064] A project requirement document is a document that describes the product requirements and functions of a software project in detail, and is one of the key documents in the product development process. For the convenience of parsing atomic capability information, the project requirement document can be a table document, such as an xls table or a csv table, etc., and the specific type of the table document is not restricted in any way by the embodiment of the present application. In particular, each row of the table document records the attribute information of an atomic capability, and the attribute information may include but is not limited to: the module to which it belongs, the name and the parameter list, wherein the parameter list includes information such as the parameter name, the parameter type, whether it must be transmitted and the parameter description. By setting it in this way, it is only necessary to parse the table document line by line to obtain the attribute information of all atomic capabilities that the document has. Afterwards, according to the attribute information of each atomic capability recorded in the table document, a list is generated in units of atomic capabilities as the atomic capability list of the document.
[0065] As an example, the following is the content of a row in a table document, which represents all the attribute information of an atomic capability:
[0066] Voice, SETrigger.setupKwsVoice(),"Parameter name: texts
[0067] Parameter type: string array
[0068] Is it necessary to transmit: Yes
[0069] Parameter description: List of contents to be reported
[0070] -------------------
[0071] Parameter name: timeout
[0072] Parameter type: int
[0073] Is it necessary to transmit: Yes
[0074] Parameter description: timeout duration",,,,,,,,,,,,,,,,
[0075] It should be noted that all the contents of the above examples are recorded in the same row of the table document. It can be seen that each row uses a key-value pair to describe the parameters of the atomic capability. Each parameter is separated by multiple consecutive "-" symbols, and finally ends with 16 "," signs, and then the information of the next atomic capability is continued. In the above example, the name of the atomic capability is "SETrigger.setupKwsVoice()", the module it belongs to is "voice", the first parameter is "texts", the parameter type of "texts" is "string array", and it is a required parameter for the list of contents to be broadcast; the second parameter is "timeout"..., and so on. According to the preset parsing rules, the content of the table document is parsed line by line. The most core parsing items include the name of the atomic capability, which starts with a specified string, such as the string "SETrigger", "SEAction" or "SECondition". After parsing the name of the atomic capability, continue to parse the information of the parameter list of the atomic capability, so as to determine the name and parameter type of each parameter it has.
[0076] In an implementation of the embodiment of the present application, each column of the table document records one kind of attribute information of the atomic capability; let the target content be any row of the table document, parse the content of the table document row by row, and obtain the attribute information of each atomic capability of the table document, including:
[0077] (1) Segment the target content into individual cell texts according to the specified characters in the target content;
[0078] (2) for each cell text, determine the attribute name corresponding to the cell text according to the attribute information corresponding to the column where the cell text is located, and use the cell text as the attribute value corresponding to the attribute name;
[0079] (3) Determine the attribute information of the atomic capability corresponding to the target content based on the attribute name and attribute value corresponding to each cell text.
[0080] Each row of the table document records the attribute information of an atomic capability, and each column records the attribute information of an atomic capability. In the table document, the contents of each cell are separated by a certain specified character by default. For example, in a csv table document, English commas are usually used for separation. If the text inside the cell already contains English commas, a pair of Chinese commas can be added to the cell text when generating cell data to wrap it. The English commas wrapped in the Chinese commas will not be regarded as separators. Assuming that the target content is any row of the table document, the target content is used as an example to illustrate the specific method of parsing and obtaining the attribute information of the atomic capability. First, according to the specified characters in the target content, the target content is divided into each cell text. For example, the English commas in the target content can be found, and the target content is divided into multiple parts according to each English comma, each part represents a cell text. Then, for each cell text, according to the attribute information corresponding to the column where the cell text is located, the attribute name corresponding to the cell text is determined, and the cell text is used as the attribute value corresponding to the attribute name. For example, a cell text "SETrigger.setupKwsVoice()" is in the second column, and the attribute information corresponding to the second column is "atomic capability name", which represents the attribute name, and the content of the cell text represents the attribute value corresponding to the attribute name, so it can be determined that the meaning of the cell text is: the atomic capability name is SETrigger.setupKwsVoice(). According to this method, each cell text of the target content can be mapped to the corresponding attribute in the atomic capability data. Finally, the attribute names and attribute values corresponding to each cell text are integrated to determine all the attribute information of the atomic capability corresponding to the target content. Similarly, each row of the table document is processed in the same way as the target content, and the attribute information of all the atomic capabilities of the table document can be obtained. Finally, a list is generated according to the attribute information of all atomic capabilities in units of atomic capabilities to obtain the atomic capability list of the document.
[0081] In an implementation of the embodiment of the present application, after generating a document atomic capability list according to the attribute information of each atomic capability of the table document in units of atomic capabilities, the method further includes:
[0082] (1) respectively checking whether there is any error in the attribute information of each atomic capability in the document atomic capability list;
[0083] (2) Generate a document error report based on the atomic capabilities in the document atomic capability list that have erroneous attribute information.
[0084] As the benchmark for software code design, the project requirements document needs to ensure that the atomic capability information recorded in it is correct. However, the project requirements document is also manually compiled, and sometimes it is difficult to avoid some atomic capability errors. For example, the atomic capability may have missing expressions or parameters, irregular naming, irregular parameters or parameter formats, etc. In view of this situation, after generating the document atomic capability list in the above manner, the document atomic capability list can be checked to detect whether there are errors in the attribute information of each atomic capability in the document atomic capability list, and generate a document error report based on the atomic capabilities with errors in the attribute information in the document atomic capability list. The verification here can be carried out in two ways: manual verification and automatic verification. Automatic verification refers to automatically analyzing and checking the information of each atomic capability in the document atomic capability list one by one according to the set verification rules. If errors are found, they are summarized and recorded, and recommended error handling solutions can be given. The corresponding document error report is generated in a natural language to the user to help the user correct the project requirements document. Specifically, under normal circumstances, the data of atomic capabilities in a table document is in the key-value data format. If it is found that the attribute information of an atomic capability does not conform to the above format, it is marked as an error, and the name, attribute name and attribute value of the corresponding atomic capability are recorded.
[0085] As an example, if the atomic capability name "SETrigger.setupKwsVoice()" lacks the last "()", a document error report with the content "Atomic capability SETrigger.setupKwsVoice() lacks ()" can be generated. After the project requirement document is corrected, the corrected document atomic capability list can be generated in the same way using the corrected project requirement document, and the corrected document atomic capability list can continue to be tested until a document atomic capability list without errors is obtained.
[0086] 102. Compare the code atomic capability list with the document atomic capability list, and based on the comparison results, determine the atomic capability problems in the project code.
[0087] After obtaining the code atomic capability list and the document atomic capability list in the manner described above, use the document atomic capability list as a standard to compare whether the code atomic capability list is consistent with the document atomic capability list. If they are consistent, it means that there is no atomic capability problem in the project code. If they are inconsistent, it means that there is an atomic capability problem in the project code. In the process of list comparison, the names of the atomic capabilities can be compared one by one to determine whether the key items such as parameter names and parameter types for the atomic capabilities of the same name in the two lists are consistent. In addition, after determining the atomic capability problems in the project code, the corresponding code error report can be sorted and generated based on these atomic capability problems. After obtaining the code error report, the user can clearly view all the atomic capability problems in the project code, so as to conveniently correct these problems.
[0088] In an implementation of the embodiment of the present application, determining the atomic capability problem existing in the project code according to the comparison result includes:
[0089] (1) If there is any atomic capability in the code atomic capability list that is not in the document atomic capability list, it is determined that the project code has an outdated atomic capability problem;
[0090] (2) If any atomic capability in the document atomic capability list does not exist in the code atomic capability list, it is determined that the project code has a missing atomic capability problem;
[0091] (3) If the code atomic capability list and the document atomic capability list contain the same atomic capability with different attribute information, it is determined that the project code has an atomic capability error problem.
[0092] After comparing the code atomic capability list with the document atomic capability list, it can be determined whether there are three types of atomic capability problems in the project code. The first type of problem is the problem of outdated atomic capabilities. If an atomic capability A exists in the code atomic capability list but does not exist in the document atomic capability list, it means that atomic capability A is outdated and no longer used. Therefore, it is determined that the project code has an atomic capability outdated problem. At this time, a report content of "Atomic capability A is outdated, please indicate the obsolescence in the project code" can be generated. The second type of problem is the problem of missing atomic capabilities. If an atomic capability B does not exist in the code atomic capability list but exists in the document atomic capability list, it means that atomic capability B has not been implemented in the project code. Therefore, it is determined that the project code has an atomic capability missing problem. At this time, a report content of "Atomic capability B is missing, please implement it in the project code" can be generated. The third type of problem is the problem of atomic capability errors. If an atomic capability C exists in both the code atomic capability list and the document atomic capability list, but the attribute information of atomic capability C is different in the two lists, it means that there are errors in the attribute information of atomic capability C described in the project code, such as errors in the number of parameters or the type of the same parameter, or whether the same parameter must be passed. In this case, it is determined that there is an atomic capability error in the project code, and a report content "XX attribute information of atomic capability C is wrong, the correct attribute information is YY, please correct it in the project code" can be generated.
[0093] In actual operation, users can develop an application based on the principles described above, called an atomic capability detection tool. The tool has the ability to analyze table documents, check the correctness and standardization of atomic capability information in each row, and generate a document atomic capability list. The tool has the ability to scan and analyze Java files and generate a code atomic capability list. The tool has the ability to compare the atomic capabilities in the document atomic capability list with the atomic capabilities in the code atomic capability list one by one, use the former list as the standard, identify the atomic capability problems in the latter list, and generate a code error report after summarizing. In addition, during the project iteration process, the number of atomic capabilities will also increase, so there is a need to increase atomic capabilities in batches. For this demand, the tool also has the function of batch generating atomic capabilities. Specifically, in the process of obtaining an error-free document atomic capability list, an error-free table document can be obtained at the same time. The user can specify a row or multiple rows of the table document. The tool can generate and output the corresponding atomic capability code text according to the code generation rules based on the content of these rows. When writing project code, users can copy these atomic capability code texts into the project code to realize the functions of the corresponding atomic capabilities.
[0094] As an example, Figure 2This is a schematic diagram of an operation flow for checking the atomic capability of a code provided by an embodiment of the present application. Figure 2 In the process, firstly, the download function of the online form is used to download the project requirement document, which is a csv form; then, the csv form is parsed, and a document atomic capability list is generated according to the parsing result; then, the document atomic capability list is checked for errors, and if there are errors, a corresponding document error report is generated. After the errors are corrected and the csv form is updated, the csv form is parsed again until a document atomic capability list without errors is obtained; by parsing the project code, a code atomic capability list can be generated, and the code atomic capability list is compared with the document atomic capability list, and it is determined whether there is an atomic capability error in the project code according to the comparison result; if there is an atomic capability error, a corresponding code error report is generated to prompt the user to modify the project code; after the user modifies the project code, the project code continues to be parsed until the code atomic capability list is completely consistent with the document atomic capability list, which means that the project code has been checked and there is no atomic capability problem.
[0095] As another example, Figure 3 This is a schematic diagram of an operation flow of batch generating atomic capabilities provided by an embodiment of the present application. Figure 3 In the process, first use the download function of the online form to download the project requirement document, which is a csv table; then parse the csv table and generate the document atomic capability list according to the parsing results; then check whether there are errors in the document atomic capability list. If there are errors, generate the corresponding document error report. After correcting the errors and updating the csv table, parse the csv table again until you get the document atomic capability list without errors and the csv table without errors; you can specify one or more rows in the csv table, and generate and output the corresponding atomic capability code text list according to the content of these rows and the code generation rules. After that, the user only needs to copy the corresponding code text in the atomic capability code text list into the project code written by himself to realize the corresponding atomic capability function.
[0096] In the technical solution of the embodiment of the present application, all atomic capabilities of the project code are integrated into a code atomic capability list, and all atomic capabilities of the project requirement document are integrated into a document atomic capability list. After that, the code atomic capability list and the document atomic capability list only need to be compared one by one in terms of atomic capabilities to know whether there are discrepancies between the atomic capabilities described in the project code and the project requirement document, thereby determining whether there are atomic capability problems in the project code. The above process automatically completes the atomic capability inspection of the project code by list comparison, which can greatly improve the efficiency and accuracy of the inspection compared to the traditional method of manual verification.
[0097] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0098] A method for verifying the atomic capability of a code is mainly described above, and a device for verifying the atomic capability of a code will be described below.
[0099] See also Figure 4 , shows a code atomic capability testing device provided by an embodiment of the present application, including:
[0100] List acquisition module 401, used to acquire a code atomic capability list and a document atomic capability list; wherein the code atomic capability list records all atomic capabilities of the project code, and the document atomic capability list records all atomic capabilities of the project requirement document corresponding to the project code;
[0101] The list comparison module 402 is used to compare the code atomic capability list with the document atomic capability list, and determine the atomic capability problems existing in the project code according to the comparison result.
[0102] In one implementation of the embodiment of the present application, the device for verifying the code atomicity capability further includes:
[0103] The scanning module is used to recursively scan the project file directory where the project code is located to find the code files with atomic capabilities in the project file directory;
[0104] A code parsing module is used to parse the code file and obtain the atomic capability information of the code file;
[0105] The code list generation module is used to generate a code atomic capability list according to the atomic capability information of the code file.
[0106] In one implementation of the embodiment of the present application, the project code is written in Java; the scanning module includes:
[0107] A file search unit is used to search all files with the suffix ".java" in the project file directory as code files;
[0108] The code parsing module includes:
[0109] The atomic capability extraction unit is used to extract the function text starting with a specified string in the code file using the javaparser tool, and parse the function text to obtain the atomic capability information of the code file.
[0110] In an implementation of the embodiment of the present application, the project requirement document is a table document, and each row of the table document records the attribute information of an atomic capability; the code atomic capability verification device also includes:
[0111] The document parsing module is used to parse the content of the table document line by line to obtain the attribute information of each atomic capability recorded in the table document;
[0112] The document list generation module is used to generate a document atomic capability list according to the attribute information of each atomic capability recorded in the table document and in units of atomic capability.
[0113] In an implementation of the embodiment of the present application, each column of the table document records a kind of attribute information of the atomic capability; let the target content be any row of content in the table document, and the document parsing module includes:
[0114] A content segmentation unit is used to segment the target content into individual cell texts according to the specified characters in the target content;
[0115] An attribute determination unit, for determining, for each cell text, an attribute name corresponding to the cell text according to the attribute information corresponding to the column where the cell text is located, and using the cell text as an attribute value corresponding to the attribute name;
[0116] The atomic capability determination unit is used to determine the attribute information of the atomic capability corresponding to the target content according to the attribute name and attribute value corresponding to each cell text.
[0117] In one implementation of the embodiment of the present application, the device for verifying the code atomicity capability further includes:
[0118] A document detection module is used to detect whether there is an error in the attribute information of each atomic capability in the document atomic capability list;
[0119] The report generation module is used to generate a document error report according to the atomic capabilities with erroneous attribute information in the document atomic capability list.
[0120] In one implementation of the embodiment of the present application, the list comparison module includes:
[0121] An outdated detection unit, used to determine that the project code has an outdated atomic capability problem if there is any atomic capability in the code atomic capability list that is not in the document atomic capability list;
[0122] A missing detection unit, used for determining that there is a problem of missing atomic capabilities in the project code if any atomic capabilities in the document atomic capabilities list do not exist in the code atomic capabilities list;
[0123] The error detection unit is used to determine that there is an atomic capability error in the project code if the code atomic capability list and the document atomic capability list contain the same atomic capability with different attribute information.
[0124] An embodiment of the present application also provides a computer program product. When the computer program product is run on an electronic device, the electronic device executes a method for verifying the code atomic capability as represented by any of the above embodiments.
[0125] An embodiment of the present application also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the code atomic capability verification method represented by any of the above embodiments.
[0126] Figure 5 is a schematic diagram of an electronic device provided by an embodiment of the present application. Figure 5 As shown, the electronic device 5 of this embodiment includes: a processor 50, a memory 51, and a computer program 52 stored in the memory 51 and executable on the processor 50. When the processor 50 executes the computer program 52, the steps in the above-mentioned code atomic capability verification method are implemented, for example Figure 1 Alternatively, when the processor 50 executes the computer program 52, the functions of each module / unit in the above-mentioned device embodiments are realized, for example, Figure 4 Modules 401 and 402 of the device shown.
[0127] The computer program 52 may be divided into one or more modules / units, which are stored in the memory 51 and executed by the processor 50 to complete the present application. The one or more modules / units may be a series of computer program instruction segments capable of completing specific functions, which are used to describe the execution process of the computer program 52 in the electronic device 5.
[0128] The processor 50 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0129] The memory 51 may be an internal storage unit of the electronic device 5, such as a hard disk or memory of the electronic device 5. The memory 51 may also be an external storage device of the electronic device 5, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the electronic device 5. Further, the memory 51 may also include both an internal storage unit and an external storage device of the electronic device 5. The memory 51 is used to store the computer program and other programs and data required by the electronic device. The memory 51 may also be used to temporarily store data that has been output or is to be output.
[0130] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0131] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0132] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0133] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0134] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the system embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0135] The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the embodiments of the present application.
[0136] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0137] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0138] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A method for testing the atomicity of a code, characterized in that: include: Obtain a code atomic capability list and a document atomic capability list; wherein the code atomic capability list records all atomic capabilities of the project code, and the document atomic capability list records all atomic capabilities of the project requirement document corresponding to the project code; The code atomic capability list is compared with the document atomic capability list, and based on the comparison result, the atomic capability problem existing in the project code is determined.
2. The method according to claim 1, characterized in that The code atomic capability list is obtained in the following way: Recursively scan the project file directory where the project code is located to find the code file with atomic capability in the project file directory; Parsing the code file to obtain atomic capability information of the code file; The code atomic capability list is generated according to the atomic capability information of the code file.
3. The method according to claim 2, characterized in that The project code is written in Java language; searching for code files with atomic capabilities in the project file directory includes: Search for all files with the suffix ".java" in the project file directory as the code files; The step of parsing the code file to obtain atomic capability information of the code file includes: The javaparser tool is used to extract the function text starting with the specified string in the code file, and the function text is parsed to obtain the atomic capability information of the code file.
4. The method according to claim 1, characterized in that The project requirement document is a table document, and each row of the table document records the attribute information of an atomic capability; the document atomic capability list is obtained in the following way: Parsing the content of the table document line by line to obtain attribute information of each atomic capability recorded in the table document; According to the attribute information of each atomic capability recorded in the table document, the document atomic capability list is generated in units of atomic capability.
5. The method according to claim 4, characterized in that Each column of the table document records one kind of attribute information of the atomic capability; let the target content be any row of the table document, and parse the content of the table document row by row to obtain the attribute information of each atomic capability of the table document, including: According to the specified characters in the target content, the target content is divided into individual cell texts; For each of the cell texts, determine the attribute name corresponding to the cell text according to the attribute information corresponding to the column where the cell text is located, and use the cell text as the attribute value corresponding to the attribute name; According to the attribute name and the attribute value corresponding to each of the cell texts, the attribute information of the atomic capability corresponding to the target content is determined.
6. The method according to claim 4, characterized in that After generating the document atomic capability list according to the attribute information of each atomic capability of the table document in units of atomic capability, the method further includes: respectively detecting whether there is any error in the attribute information of each atomic capability in the atomic capability list of the document; A document error report is generated according to the atomic capabilities in the document atomic capability list whose attribute information has errors.
7. The method according to any one of claims 1 to 6, characterized in that: Determining the atomic capability problem existing in the project code according to the comparison result includes: If there is any atomic capability in the code atomic capability list that is not in the document atomic capability list, it is determined that the project code has an outdated atomic capability problem; If any atomic capability in the document atomic capability list does not exist in the code atomic capability list, it is determined that the project code has a problem of missing atomic capabilities; If the code atomic capability list and the document atomic capability list contain the same atomic capability with different attribute information, it is determined that the project code has an atomic capability error problem.
8. A device for testing the atomicity of a code, characterized in that: include: A list acquisition module, used to acquire a code atomic capability list and a document atomic capability list; wherein the code atomic capability list records all atomic capabilities of the project code, and the document atomic capability list records all atomic capabilities of the project requirement document corresponding to the project code; The list comparison module is used to compare the code atomic capability list with the document atomic capability list, and determine the atomic capability problems existing in the project code according to the comparison result.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method for verifying the code atomic capability according to any one of claims 1 to 7 is implemented.
10. A computer program product, characterized in that When the computer program product is run on an electronic device, the electronic device is enabled to execute the method for verifying the code atomic capability as claimed in any one of claims 1 to 7.
Citation Information
Cited By
Method, device and storage medium for automatically generating embedded code
CN122691605A
Method, device and storage medium for automatically generating embedded code
CN122691605B