Disclosure of Invention
The invention aims to solve the problems of low detection efficiency and easy missed detection of test script codes in the prior art, and provides an xml-based automatic test script written by a test script language, which uses the same script language as the script codes to be detected, has good expansibility, can be reused, can replace a large amount of manual detection workload, remarkably improves the detection efficiency of the test script codes, can record the detection rule that the static detection fails, supports the regression detection after the repair of the test script problems, and avoids the missed detection.
The technical scheme provided by the embodiment of the invention is that the static inspection method based on the xml test script code comprises the following steps:
S1, constructing an inspection rule base, and establishing mapping between the inspection rule base and a script analysis executor;
S2, loading a script code file to be detected by a script analysis executor, and preprocessing the script code file to obtain a plurality of script code subfiles;
S3, sequentially matching the checking specification list of the script code sub-files by a script analysis executor, and sequentially associating detection item instructions in a detection rule base in the detection specification list;
S4, testing the script code subfiles in sequence according to detection logic of the detection specification table, and providing a fault detection table;
S5, if the test fails, executing S6, and obtaining the label of the corresponding script code subfile from the fault column in the fault detection table;
s6, performing regression static inspection after performing fault analysis and correction on fault section information corresponding to the label;
s7, repeatedly executing S5-S6 according to the set execution times threshold, and executing S8 if the repetition times exceed the threshold;
s8, relating the labels of the script code subfiles with the test faults to a fault sharing container, wherein the fault sharing container is associated with an expert database;
And S9, when all the script code sub-files pass the test, weaving a plurality of script code sub-files to obtain a target script code file.
Preferably, the construction of the detection rule base in S1 includes the following steps:
determining a checking rule according to the language specification and the use requirement of the xml test script language;
Static check rule codes based on xml test script language are written in a regular expression mode.
Preferably, in S2, preprocessing the script code file to obtain a plurality of script code subfiles, wherein the script code file is divided into a plurality of script code subfiles according to the test item attribute of the script code file;
Recording a start code row, an end code row and a code row difference value of each script code subfile;
And (3) distributing the separation slots in the test container according to the code line difference values, storing a plurality of script code subfiles into the separation slots of the test container to be tested, marking, extracting the marks as test sequences, and establishing mapping between the sequence bits of the test sequences and the separation slots.
Preferably, S3 includes the steps of:
And the script analysis executor sequentially acquires script code subfiles in the container to be tested according to the detection logic of the test sequence, and invokes corresponding detection item instructions to test the script code subfiles.
Preferably, S5 includes the steps of:
If the test fails, the fault column in the fault detection table automatically acquires the label information of the corresponding script code subfile;
and mapping the fault column and the corresponding test sequence bit.
Preferably, in S8, the labels of the script code subfiles in which the test faults occur are associated to a fault sharing container, and the fault sharing container is associated with an expert database, including the steps of:
The fault sharing container establishes mapping with test sequence bits for testing faults, and script code subfiles corresponding to the test sequence bits are obtained;
Acquiring fault section information of the corresponding script code subfile according to the script analysis executor;
associating an expert database according to the attribute characteristics of the fault section information, wherein a daily task popup window is arranged in the expert database;
And converting the fault section information into an Excel format file, filling the Excel format file into a task popup window of an expert library, and processing the corresponding fault section information by the expert according to the task popup window.
Preferably, in S9, when all the script code subfiles pass the test, a plurality of script code subfiles are woven to obtain a target script code file, including:
Sequentially calling script code subfiles corresponding to the test sequence bits, and copying the script code subfiles into a compiling environment according to sequential logic of the test sequence;
Comparing the difference value of the start code row, the end code row and the code row of each script code subfile with the recorded value, generating a target script code file if the difference value of the start code row, the end code row and the code row is matched with the historical recorded value, and checking if the difference value is not matched with the historical recorded value.
The invention has the advantages that an automatic test script is compiled based on an xml test script language, manual inspection is replaced by compiling static inspection rules, the workload of manual inspection of codes is greatly reduced, meanwhile, the compiled inspection rules can be repeatedly used, a large amount of labor cost is saved, the static inspection rules are compiled by using the same script language as the inspected test script codes, test developers can quickly compile or modify the inspection rules, meanwhile, because the inspection rules are keyword-driven, different parameters can be freely expanded, different inspection rules can be freely expanded by using different parameters, the language specifications and the use requirements of the inspected test script codes are various, the static rules are compiled by using a regular expression mode, the flexibility of compiling the inspection rules is greatly improved, the workload and difficulty of compiling the inspection rules are reduced, after static inspection is executed, the failed inspection rules of the test script codes can be recorded and reported wrong, after the test scripts are modified according to an inspected problem list, the failed inspection rules of the last inspection can be independently executed for regression inspection, the overall inspection efficiency is greatly improved, and the fault handling efficiency is further improved to a fault expert is further notified according to the high-level fault handling efficiency.
The foregoing summary is merely an overview of the present invention, and is intended to be implemented in accordance with the teachings of the present invention in order that the same may be more fully understood, and in order that the same or additional objects, features and advantages of the present invention may be more fully understood.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the present invention more apparent, the present invention will be described in further detail with reference to the accompanying drawings and examples, it being understood that the detailed description herein is merely a preferred embodiment of the present invention, which is intended to illustrate the present invention, and not to limit the scope of the invention, as all other embodiments obtained by those skilled in the art without making any inventive effort fall within the scope of the present invention.
Before discussing the exemplary embodiments in more detail, it should be mentioned that some exemplary embodiments are described as processes or methods depicted as flowcharts. Although a flowchart depicts operations (or steps) as a sequential process, many of the operations (or steps) can be performed in parallel, concurrently, or at the same time. Furthermore, the order of the operations may be rearranged. The process may be terminated when its operations are completed, but may have additional steps not included in the figures, the process may correspond to a method, a function, a procedure, a subroutine, etc.
Embodiment As shown in FIG. 1, a static inspection method based on xml test script code comprises the following steps:
S1, constructing an inspection rule base, and establishing mapping between the inspection rule base and a script analysis executor;
S2, loading a script code file to be detected by a script analysis executor, and preprocessing the script code file to obtain a plurality of script code subfiles;
S3, sequentially matching the checking specification list of the script code sub-files by a script analysis executor, and sequentially associating detection item instructions in a detection rule base in the detection specification list;
S4, testing the script code subfiles in sequence according to detection logic of the detection specification table, and providing a fault detection table;
S5, if the test fails, executing S6, and obtaining the label of the corresponding script code subfile from the fault column in the fault detection table;
s6, performing regression static inspection after performing fault analysis and correction on fault section information corresponding to the label;
s7, repeatedly executing S5-S6 according to the set execution times threshold, and executing S8 if the repetition times exceed the threshold;
s8, relating the labels of the script code subfiles with the test faults to a fault sharing container, wherein the fault sharing container is associated with an expert database;
And S9, when all the script code sub-files pass the test, weaving a plurality of script code sub-files to obtain a target script code file.
In this embodiment, the inspection rule library is provided with an inspection rule matching the script code subfile, the inspection rule is written using the same scripting language as the inspected script code subfile, the test developer can quickly write or modify the inspection rule, the expansibility is good, the test developer can replace a large amount of manual inspection workload, the test script code detection efficiency is remarkably improved, meanwhile, the inspection rule which is failed in static inspection can be recorded, the regression inspection after the test script problem is repaired is supported, the problem of missed inspection is avoided, and the method is synchronous.
The step S1 of constructing a detection rule base comprises the following steps:
determining a checking rule according to the language specification and the use requirement of the xml test script language;
Static check rule codes based on xml test script language are written in a regular expression mode.
In the scheme, the inspection rules are driven by keywords, and different inspection rules can be freely expanded by using different keywords, and specifically, as shown in fig. 2, each group of inspection specifications comprises one or more inspection items, wherein the inspection items can be driven by CheckXMLNodeName (for checking whether the node names of the test case scripts are correct), checkXMLNodePropName (for checking whether the attribute names of the test case scripts are correct), regexCheckExecStepMatch (for checking the matching property of the execution steps of the test case scripts by a regular expression mode), regexCheckExecStepPostConditionMatch (for checking the matching property of the execution steps and the post conditions of the test case scripts by the regular expression mode) and CheckExecStepRuleExist (for checking whether the keywords used by the test case scripts exist).
Further, a c++ development language is used to add a function of checking rule keywords in the test script parsing executor, wherein different keywords can freely expand different checking rules, and typical keywords can be:
CheckXMLNodeName (check whether the test case script node name is correct)
CheckXMLNodePropName (check whether the test case script node attribute name is correct)
CheckXMLNodePropValueExist (check whether test case script node attribute value exists)
RegexCheckXMLNodePropValueOrMatch (regular expression mode checking whether the test case script node attribute value is correct)
RegexCheckExecStepMatch (regular expression mode checking test case script execution step matching)
RegexCheckExecStepPostConditionMatch (regular expression mode checking test case script execution step and post condition matching)
RegexCheckExecPostConditionMatch (regular expression type checking test case script post condition matching)
RegexCheckRevExecStepMatch (regular expression reverse check test case script execution step match)
RegexCheckRevExecStepPostConditionMatch (regular expression reverse check test case script execution step and post condition matching)
RegexCheckRevExecPostConditionMatch (regular expression reverse check test case script post condition matching)
RegexCheckExecStepTitleMatch (regular expression method checking test script test case title and execution step matching)
RegexCheckSameExecStepMatch (regular expression type checking test case script content match with complex execution step)
RegexCheckSameExecPostConditionMatch (regular expression type checking test case script same compound post condition content matching)
CheckExecStepRuleExist (check whether the keywords used by the test case script exist)
CheckExecStepExist (check whether the test case script execution step exists)
CheckExcelTestCase2ScriptXMLNode (checking whether the automatable test case has a corresponding test script)
CheckScriptXMLNode2ExcelTestCase (check whether the test script has a corresponding test case present)
CheckScriptXMLNodeTitle (check whether the test case header property in the test script is correct)
RegexCheckScriptXMLNodeMatchExcelExecStepExist (check if the corresponding execution step of the test script exists based on the test case key).
S2, preprocessing the script code file to obtain a plurality of script code subfiles, wherein the method comprises the following steps:
Dividing the script code file into a plurality of script code subfiles according to the test item attribute of the script code file;
Recording a start code row, an end code row and a code row difference value of each script code subfile;
And (3) distributing the separation slots in the test container according to the code line difference values, storing a plurality of script code subfiles into the separation slots of the test container to be tested, marking, extracting the marks as test sequences, and establishing mapping between the sequence bits of the test sequences and the separation slots.
S3, comprising the following steps:
And the script analysis executor sequentially acquires script code subfiles in the container to be tested according to the detection logic of the test sequence, and invokes corresponding detection item instructions to test the script code subfiles.
S5, the method comprises the following steps:
If the test fails, the fault column in the fault detection table automatically acquires the label information of the corresponding script code subfile;
and mapping the fault column and the corresponding test sequence bit.
In S8, the labels of the script code subfiles with test faults are associated to a fault sharing container, and the fault sharing container is associated with an expert database, and the method comprises the following steps of:
The fault sharing container establishes mapping with test sequence bits for testing faults, and script code subfiles corresponding to the test sequence bits are obtained;
Acquiring fault section information of the corresponding script code subfile according to the script analysis executor;
associating an expert database according to the attribute characteristics of the fault section information, wherein a daily task popup window is arranged in the expert database;
And converting the fault section information into an Excel format file, filling the Excel format file into a task popup window of an expert library, and processing the corresponding fault section information by the expert according to the task popup window.
S9, when all script code sub-files pass the test, weaving a plurality of script code sub-files to obtain a target script code file, wherein the method comprises the following steps:
Sequentially calling script code subfiles corresponding to the test sequence bits, and copying the script code subfiles into a compiling environment according to sequential logic of the test sequence;
Comparing the difference value of the start code row, the end code row and the code row of each script code subfile with the recorded value, generating a target script code file if the difference value of the start code row, the end code row and the code row is matched with the historical recorded value, and checking if the difference value is not matched with the historical recorded value.
The above embodiments are preferred embodiments of the static inspection method based on xml test script code according to the present invention, and the scope of the present invention is not limited to the preferred embodiments, but all equivalent changes in shape and structure according to the present invention are within the scope of the present invention.