CN108536583B - Assertion method and device for automatic test, computer equipment and storage medium - Google Patents

Assertion method and device for automatic test, computer equipment and storage medium Download PDF

Info

Publication number
CN108536583B
CN108536583B CN201810196488.8A CN201810196488A CN108536583B CN 108536583 B CN108536583 B CN 108536583B CN 201810196488 A CN201810196488 A CN 201810196488A CN 108536583 B CN108536583 B CN 108536583B
Authority
CN
China
Prior art keywords
root
test case
assertion
xml
creating
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201810196488.8A
Other languages
Chinese (zh)
Other versions
CN108536583A (en
Inventor
周思聪
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Technology Shenzhen Co Ltd
Original Assignee
Ping An Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Technology Shenzhen Co Ltd filed Critical Ping An Technology Shenzhen Co Ltd
Priority to CN201810196488.8A priority Critical patent/CN108536583B/en
Priority to PCT/CN2018/085251 priority patent/WO2019169720A1/en
Publication of CN108536583A publication Critical patent/CN108536583A/en
Application granted granted Critical
Publication of CN108536583B publication Critical patent/CN108536583B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/205Parsing
    • G06F40/226Validation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3692Test management for test results analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/12Use of codes for handling textual entities
    • G06F40/151Transformation
    • G06F40/154Tree transformation for tree-structured or markup documents, e.g. XSLT, XSL-FO or stylesheets
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/205Parsing
    • G06F40/221Parsing markup language streams
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/427Parsing

Abstract

The application discloses an assertion method and device for an automatic test, computer equipment and a storage medium. The method comprises the following steps: converting the map type or list type test case to obtain an xml type test case; and comparing the actual value and the expected value of the xml type test case through a preset comparison class to obtain an assertion result. The method realizes the conversion of the map or list test case into the xml test case, reduces the multilayer and sequence change in the test case, and can make assertion more convenient and flexible.

Description

Assertion method and device for automatic test, computer equipment and storage medium
Technical Field
The present application relates to the field of java automated testing technologies, and in particular, to an assertion method and apparatus for automated testing, a computer device, and a storage medium.
Background
Some assumptions are always made when writing code, and assertions are used to capture assumptions in code, i.e., assertions can be viewed as a high-level form of exception handling. Assertions are expressed as boolean expressions that are used to determine certain critical data and to alert or exit the program if this critical data is not the expected data. At present, when the map or the list is asserted in the java automated test, the assertion difficulty is high because the map or the list may have the problems of multiple layers and sequence change.
Disclosure of Invention
The application provides an assertion method, an assertion device, computer equipment and a storage medium for an automated test, and aims to solve the problem that when a map or a list is asserted in the prior art, the assertion difficulty is high due to the fact that the map or the list may have multi-layer and sequential changes.
In a first aspect, the present application provides an assertion method for an automated test, including:
converting the map type or list type test case to obtain an xml type test case;
and comparing the actual value and the expected value of the xml type test case through a preset comparison class to obtain an assertion result.
In a second aspect, the present application provides an assertion device for automated testing, comprising:
the xml type conversion unit is used for converting the map type or list type test case to obtain an xml type test case;
and the assertion result obtaining unit is used for comparing the actual value of the xml-type test case with the expected value through a preset comparison class to obtain an assertion result.
In a third aspect, the present application further provides a computer device, including a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor implements the assertion method of the automated test provided in any one of the above embodiments when executing the computer program.
In a fourth aspect, the present application further provides a storage medium, wherein the storage medium stores a computer program comprising program instructions that, when executed by a processor, cause the processor to perform the assertion method of the automation test of any one of the provisions of the present application.
The application provides an assertion method and device for an automatic test, computer equipment and a storage medium. The method comprises the steps of converting a map type or list type test case to obtain an xml type test case; and comparing the actual value and the expected value of the xml type test case through a preset comparison class to obtain an assertion result. The method realizes the conversion of the map or list test case into the xml test case, reduces the multilayer and sequence change in the test case, and can make assertion more convenient and flexible.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a schematic flow chart of an assertion method for an automated test according to an embodiment of the present disclosure;
FIG. 2 is a sub-flow diagram of an assertion method for automated testing according to an embodiment of the present disclosure;
FIG. 3 is a schematic view of another sub-flow of an assertion method for an automated test according to an embodiment of the present application;
FIG. 4 is another schematic flow chart of an assertion method for automated testing according to an embodiment of the present disclosure;
FIG. 5 is a schematic view of another sub-flow of an assertion method for an automated test according to an embodiment of the present application;
FIG. 6 is a schematic block diagram of an assertion apparatus for automated testing according to an embodiment of the present application;
FIG. 7 is a block diagram illustrating a sub-unit of an assertion apparatus for automated testing according to an embodiment of the present application;
FIG. 8 is a schematic block diagram of another subunit of an assertion apparatus for automated testing according to an embodiment of the present application;
FIG. 9 is another schematic block diagram of an assertion apparatus for automated testing provided by embodiments of the present application;
FIG. 10 is a schematic block diagram of another subunit of an assertion apparatus for automated testing according to an embodiment of the present application;
fig. 11 is a schematic block diagram of a computer device according to an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some, but not all, embodiments of the present application. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
It will be understood that the terms "comprises" and/or "comprising," when used in this specification and the appended claims, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
It is also to be understood that the terminology used in the description of the present application herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. As used in the specification of the present application and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
It should be further understood that the term "and/or" as used in this specification and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
Referring to fig. 1, fig. 1 is a schematic flow chart of an assertion method of an automated test according to an embodiment of the present application. The method is applied to terminals such as desktop computers, portable computers and tablet computers. As shown in fig. 1, the method includes steps S101 to S102.
S101, converting the map type or list type test case to obtain an xml type test case.
In this embodiment, the test case is converted from the original map type or list type test case to the xml type test case, so as to solve the problems of data multi-layer storage and data order in the map type or list type test case, and convert the test case to the xml type test case.
As shown in fig. 2, this step S101 includes the following sub-steps:
s1011a, creating a root of the document tree;
s1012a, creating a root element, and adding a child element set corresponding to the test case of the list type into the root element;
and S1013a, correspondingly adding the root element to the root of the document tree to obtain the xml type test case.
In this embodiment, the XmlDocument document is created by first using xmldcument doc ═ new xmldcument () in java (the XmlDocument document is the root of the document tree). Then, the creation of the root element is realized by XmlElement root ═ doc.createeelement (typeof (t) Name + "s"), and by foreach (t item in items) { EntityToXml (doc, root, item); and adding a child element set corresponding to the test case of the list type in the root element. And finally, adding a root element into the XMLDockent document through doc.
As another embodiment of step S101, as shown in fig. 3, the step S101 includes the following sub-steps:
s1011b, creating a root of the document tree;
s1012b, creating a root element, and recursively constructing a child element corresponding to the test case of the map type according to the root element;
and S1013b, correspondingly adding the root element to the root of the document tree to obtain the xml type test case.
In this embodiment, first, in java:
create Document () implements the above XMLDocument Document creation.
Then, the creation of the root Element is realized through Element rootElmt ═ doc, addElement (type of (T) Name + "s"), and the recursive construction of the sub-elements corresponding to the Map-type test case in the root Element is realized through for (Map < String, String > test case: maps). And finally, adding a root element into the XMLDockent document through outPrXml (doc, fileTo), and outputting the converted xml type test case.
More specifically, when a child Element corresponding to a test case of the map type is recursively constructed in the root Element, an attribute is added to the test case by Element Testcase Element.
As shown in fig. 4, before step S102, the method further includes:
s102a, presetting the parser in xmlunit, and setting node ignore properties of ignore blank space, property position, annotation, text value and property value of contrast class in the parser.
In the embodiment, when the parser in xmlunit is preset, xmlunit is called through system setproperty to instantiate the parser of xmlunit, and the distinction between two xml files can be compared using the comparison class only after the parser of xmlunit is instantiated. Xmluinit is an XML validation tool that can be used by Java developers to expose the process of validating XML documents to testers.
The parser of xmlunit is also one of XML parsers, which loads XML into memory and then converts it into an XML DOM object accessible by JavaScript. The parser of xmlunit mainly includes functions of traversing the XML tree, accessing insertion and deletion nodes (elements) and their attributes. In the application, a function in which an XML tree is traversed and an insertion element is accessed is mainly selected.
After instantiating the parser of xmlunit, the node ignore property of ignore space, property position, annotation, text value and property value of contrast class in the parser needs to be set.
Specifically, the attribute position in the comparison class is set by an xmlunit.
Set annotations by xmlunit.
Set spaces (i.e., blank) by xmlunit.
Setting a node ignore attribute of a text value and an attribute value by diff.overdiffirencelist () class; more specifically, the newIgnorTextAndAttributeValuesDifferenceListener () is used as an argument of the diff.
Briefly, overridedidiferenceListener () of Diff class may perform ignore node configuration. This is mainly at the time of comparison, and there are values that do not need to be compared, and there may be variations from return to return, such as a timestamp on the returned value (actual value). After initialization of the parser in the xmlunit and setting of various basic attributes of the comparison class in the parser are completed, the xml-type test case can be asserted from front to back according to data in the xml-type test case, multiple changes of a multi-layer structure and sequence of the data do not need to be considered, and the difficulty of assertion is reduced.
S102, comparing the actual value of the xml type test case with the expected value through a preset comparison class to obtain an assertion result.
As shown in fig. 5, the step S102 includes the following sub-steps:
s1021, comparing the actual value and the expected value of the xml type test case to obtain a comparison difference character;
s1022, judging whether the contrast difference characters meet preset assertions or not;
s1023, if the contrast difference characters meet the assertion, returning an assertion success result;
and S1024, if the contrast difference characters do not meet the assertion, returning an assertion failure result.
In this embodiment, the Diff class provided by xmlunit may compare the difference of two xml files. The actual value refers to a result value obtained by actually executing the test case, and the expected value refers to a result value obtained by the user expecting the test case to execute. The comparison of the two values results in their difference, and if there is no difference, the assertion is passed, otherwise the failure occurs.
For example, the expected value of an xml-type test case is denoted as String control xml "< account >3A-00< name > ac </name > </account >";
the actual value of the xml type test case is marked as String testXML ═ account ═ acme ═ 3A-00 </account >;
the comparison between the two is performed by diffdiffdiffdiff (new Diff, testXML), and whether the two are identical is determined by assertion of assert false (Diff. When the contrast difference character meets the assertion, returning an assertion success result; and when the contrast difference character meets the assertion, returning an assertion success result. Through the Diff classes provided in the xmlunit, the actual value and the expected value of the xml type test case are quickly and accurately compared.
Therefore, the method realizes the conversion of the map or list test case into the xml test case, reduces the multilayer and sequence change in the test case, and can make assertion more convenient and flexible.
The embodiment of the application also provides an automatic test assertion device, and the automatic test assertion device is used for executing any one of the automatic test assertion methods. Specifically, referring to fig. 6, fig. 6 is a schematic block diagram of an assertion device for an automated test according to an embodiment of the present application. The assertion device 100 for automated testing may be installed in a desktop computer, a tablet computer, a laptop computer, or the like.
As shown in fig. 6, the assertion device 100 for the automated test includes an xml type conversion unit 101 and an assertion result acquisition unit 102.
And the xml type conversion unit 101 is configured to convert the map type or list type test case to obtain an xml type test case.
In this embodiment, the test case is converted from the original map type or list type test case to the xml type test case, so as to solve the problems of data multi-layer storage and data order in the map type or list type test case, and convert the test case to the xml type test case.
In other embodiments of the present invention, as shown in fig. 7, the xml-type conversion unit 101 includes the following sub-units:
a first document tree creation unit 1011a for creating a root of a document tree;
a first root element creating unit 1012a, configured to create a root element, and add a child element set corresponding to a test case of the list type to the root element;
and a first conversion unit 1013a, configured to correspondingly add a root element to a root of the document tree, so as to obtain an xml-type test case.
In this embodiment, the XmlDocument document is created by first using xmldcument doc ═ new xmldcument () in java (the XmlDocument document is the root of the document tree). Then, the creation of the root element is realized by XmlElement root ═ doc.createeelement (typeof (t) Name + "s"), and by foreach (t item in items) { EntityToXml (doc, root, item); and adding a child element set corresponding to the test case of the list type in the root element. And finally, adding a root element into the XMLDockent document through doc.
As another embodiment of the xml-type conversion unit 101, as shown in fig. 8, the xml-type conversion unit 101 includes the following sub-units:
a second document tree creation unit 1011b for creating a root of the document tree;
a second root element creating unit 1012b, configured to create a root element, and recursively construct a child element corresponding to the map-type test case according to the root element;
and a second conversion unit 1013b, configured to correspondingly add the root element to the root of the document tree, so as to obtain the xml-type test case.
In this embodiment, the XmlDocument document is created by first using xmldcument doc ═ new xmldcument () in java (the XmlDocument document is the root of the document tree). Then, the creation of the root element is realized by XmlElement root ═ doc.createeelement (typeof (t) Name + "s"), and by foreach (t item in items) { EntityToXml (doc, root, item); and adding a child element set corresponding to the test case of the list type in the root element. And finally, adding a root element into the XMLDockent document through doc.
In another embodiment of the present invention, as shown in fig. 9, the assertion device 100 for automated testing further includes:
the comparison class setting unit 102a is configured to set a parser in xmlunit in advance, and set a node ignore attribute that ignores a space, an attribute position, an annotation, a text value, and an attribute value of a comparison class in the parser.
In the embodiment, when the parser in xmlunit is preset, xmlunit is called through system setproperty to instantiate the parser of xmlunit, and the distinction between two xml files can be compared using the comparison class only after the parser of xmlunit is instantiated. Xmluinit is an XML validation tool that can be used by Java developers to expose the process of validating XML documents to testers.
The parser of xmlunit is also one of XML parsers, which loads XML into memory and then converts it into an XML DOM object accessible by JavaScript. The parser of xmlunit mainly includes functions of traversing the XML tree, accessing insertion and deletion nodes (elements) and their attributes. In the application, a function in which an XML tree is traversed and an insertion element is accessed is mainly selected.
After instantiating the parser of xmlunit, the node ignore property of ignore space, property position, annotation, text value and property value of contrast class in the parser needs to be set.
Specifically, the attribute position in the comparison class is set by an xmlunit.
Set annotations by xmlunit.
Set spaces (i.e., blank) by xmlunit.
Setting a node ignore attribute of a text value and an attribute value by diff.overdiffirencelist () class; more specifically, the newIgnorTextAndAttributeValuesDifferenceListener () is used as an argument of the diff.
Briefly, overridedidiferenceListener () of Diff class may perform ignore node configuration. This is mainly at the time of comparison, and there are values that do not need to be compared, and there may be variations from return to return, such as a timestamp on the returned value (actual value). After initialization of the parser in the xmlunit and setting of various basic attributes of the comparison class in the parser are completed, the xml-type test case can be asserted from front to back according to data in the xml-type test case, multiple changes of a multi-layer structure and sequence of the data do not need to be considered, and the difficulty of assertion is reduced.
The assertion result obtaining unit 102 is configured to compare the actual value of the xml-type test case with an expected value through a preset comparison class, so as to obtain an assertion result.
In other embodiments of the present invention, as shown in fig. 10, the assertion result obtaining unit 102 includes the following sub-units:
a comparison unit 1021, configured to compare the actual value of the xml-type test case with the expected value to obtain a comparison difference character;
a judging unit 1022, configured to judge whether the contrast difference character satisfies a preset assertion;
an assertion success returning unit 1023, configured to return an assertion success result if the contrast difference character satisfies the assertion;
and an assertion failure returning unit 1024, configured to return an assertion failure result if the contrast difference character does not satisfy the assertion.
In this embodiment, the Diff class provided by xmlunit may compare the difference of two xml files. The actual value refers to a result value obtained by actually executing the test case, and the expected value refers to a result value obtained by the user expecting the test case to execute. The comparison of the two values results in their difference, and if there is no difference, the assertion is passed, otherwise the failure occurs.
For example, the expected value of an xml-type test case is denoted as String control xml "< account >3A-00< name > ac </name > </account >";
the actual value of the xml type test case is marked as String testXML ═ account ═ acme ═ 3A-00 </account >;
the comparison between the two is performed by diffdiffdiffdiff (new Diff, testXML), and whether the two are identical is determined by assertion of assert false (Diff. When the contrast difference character meets the assertion, returning an assertion success result; and when the contrast difference character meets the assertion, returning an assertion success result. Through the Diff classes provided in the xmlunit, the actual value and the expected value of the xml type test case are quickly and accurately compared.
Therefore, the device can convert the test case of map or list into the test case of xml, reduce the multilayer and sequence change in the test case, and make assertion more convenient and flexible.
The automated test assertion means may be implemented in the form of a computer program that is executable on a computer device such as that shown in fig. 11.
Referring to fig. 11, fig. 11 is a schematic block diagram of a computer device according to an embodiment of the present application. The computer device 500 device may be a terminal. The terminal can be an electronic device such as a tablet computer, a notebook computer, a desktop computer, a personal digital assistant and the like.
Referring to fig. 11, the computer device 500 includes a processor 502, memory, and a network interface 505 connected by a system bus 501, where the memory may include a non-volatile storage medium 503 and an internal memory 504.
The non-volatile storage medium 503 may store an operating system 5031 and a computer program 5032. The computer programs 5032 include program instructions that, when executed, cause the processor 502 to perform a predicate method of automated testing.
The processor 502 is used to provide computing and control capabilities that support the operation of the overall computer device 500.
The internal memory 504 provides an environment for the operation of the computer program 5032 in the non-volatile storage medium 503, and when the computer program 5032 is executed by the processor 502, the processor 502 can be enabled to execute an assertion method of the automated test.
The network interface 505 is used for network communication such as sending assigned tasks and the like. Those skilled in the art will appreciate that the configuration shown in fig. 11 is a block diagram of only a portion of the configuration associated with the present application and does not constitute a limitation of the computer device 500 to which the present application may be applied, and that a particular computer device 500 may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
Wherein the processor 502 is configured to run the computer program 5032 stored in the memory to implement the following functions: converting the map type or list type test case to obtain an xml type test case; and comparing the actual value and the expected value of the xml type test case through a preset comparison class to obtain an assertion result.
In one embodiment, the processor 502 also performs the following operations: creating a root of a document tree; creating a root element, and adding a child element set corresponding to the test case of the list type into the root element; and correspondingly adding the root element to the root of the document tree to obtain the xml type test case.
In one embodiment, the processor 502 also performs the following operations: creating a root of a document tree; creating a root element, and constructing a child element corresponding to the test case of the map type according to the root element recursion; and correspondingly adding the root element to the root of the document tree to obtain the xml type test case.
In one embodiment, the processor 502 also performs the following operations: presetting a parser in xmlunit, and setting node ignoring attributes of ignoring spaces, attribute positions, annotations, text values and attribute values of comparison classes in the parser.
In one embodiment, the processor 502 also performs the following operations: comparing the actual value of the xml type test case with the expected value to obtain a comparison difference character; judging whether the contrast difference characters meet preset assertions or not; if the contrast difference character meets the assertion, returning an assertion success result; if the contrast difference character does not meet the assertion, returning an assertion failure result.
Those skilled in the art will appreciate that the embodiment of a computer device illustrated in fig. 11 does not constitute a limitation on the specific construction of the computer device, and that in other embodiments a computer device may include more or fewer components than those illustrated, or some components may be combined, or a different arrangement of components. For example, in some embodiments, the computer device may only include a memory and a processor, and in such embodiments, the structures and functions of the memory and the processor are consistent with those of the embodiment shown in fig. 11, and are not described herein again.
It should be understood that in the embodiment of the present Application, the Processor 502 may be a Central Processing Unit (CPU), and the Processor 502 may also be other general purpose processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field Programmable Gate Arrays (FPGAs) or other Programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Wherein a general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
In another embodiment of the present application, a storage medium is provided. The storage medium may be a non-volatile computer-readable storage medium. The storage medium stores a computer program, wherein the computer program comprises program instructions. The program instructions, when executed by the processor, implement: converting the map type or list type test case to obtain an xml type test case; and comparing the actual value and the expected value of the xml type test case through a preset comparison class to obtain an assertion result.
In one embodiment, the program instructions, when executed by the processor, implement: creating a root of a document tree; creating a root element, and adding a child element set corresponding to the test case of the list type into the root element; and correspondingly adding the root element to the root of the document tree to obtain the xml type test case.
In one embodiment, the program instructions, when executed by the processor, implement: creating a root of a document tree; creating a root element, and constructing a child element corresponding to the test case of the map type according to the root element recursion; and correspondingly adding the root element to the root of the document tree to obtain the xml type test case.
In one embodiment, the program instructions, when executed by the processor, implement: presetting a parser in xmlunit, and setting node ignoring attributes of ignoring spaces, attribute positions, annotations, text values and attribute values of comparison classes in the parser.
In one embodiment, the program instructions, when executed by the processor, implement: comparing the actual value of the xml type test case with the expected value to obtain a comparison difference character; judging whether the contrast difference characters meet preset assertions or not; if the contrast difference character meets the assertion, returning an assertion success result; if the contrast difference character does not meet the assertion, returning an assertion failure result.
The storage medium may be an internal storage unit of the aforementioned device, such as a hard disk or a memory of the device. The storage medium may also be an external storage device of the device, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like provided on the device. Further, the storage medium may also include both an internal storage unit and an external storage device of the apparatus.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described apparatuses, devices and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again. Those of ordinary skill in the art will appreciate that the elements and algorithm steps of the examples described in connection with the embodiments disclosed herein may be embodied in electronic hardware, computer software, or combinations of both, and that the components and steps of the examples have been described in a functional general in the foregoing description for the purpose of illustrating clearly the interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
In the several embodiments provided in the present application, it should be understood that the disclosed apparatus, device and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the units is only one logical division, and there may be other divisions in actual implementation, or units with the same function may be grouped into one unit, for example, multiple units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may also be an electric, mechanical or other form of connection.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment of the present invention.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a storage medium. Based on such understanding, the technical solution of the present invention essentially or partially contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product stored in a storage medium and including instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a magnetic disk, or an optical disk.
While the invention has been described with reference to specific embodiments, the invention is not limited thereto, and various equivalent modifications and substitutions can be easily made by those skilled in the art within the technical scope of the invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (5)

1. An assertion method for automated testing, comprising:
converting the map type or list type test case to obtain an xml type test case;
comparing the actual value and the expected value of the xml type test case through a preset comparison class to obtain an assertion result;
before the actual value of the xml-type test case is compared with the expected value through the preset comparison class to obtain the assertion result, the method further includes:
presetting a parser in xmlunit, and setting node neglect attributes of ignore blanks, attribute positions, annotations, text values and attribute values of comparison classes in the parser;
wherein the attribute position in the contrast class is set by an XMLUnit.setIgoreAttributeOrder (true) class;
set annotations by xmlunit.
Set ignore blank by xmlunit.
Setting a node ignore attribute of a text value and an attribute value by diff.overdiffirencelist () class;
the step of converting the test case of the list type to obtain the test case of the xml type comprises the following steps:
creating a root of a document tree;
creating a root element, and adding a child element set corresponding to the test case of the list type into the root element;
correspondingly adding the root element to the root of the document tree to obtain an xml type test case;
creating an XMLDcument document through XmlDocument doc ═ new XmlDocument () in java to obtain a root of a document tree; creating a root element by XmlElement root ═ doc.createeelement (typeof (t). Name + "s"), and by foreach (t element entries) { EntityToXml (doc, root, item); adding a sub-element set corresponding to the test case of the list type into the root element; adding a root element to a root of the document tree through doc. appendix child (root), and outputting a converted xml type test case;
or the converting the map type test case to obtain the xml type test case comprises the following steps:
creating a root of a document tree;
creating a root element, and constructing a child element corresponding to the test case of the map type according to the root element recursion;
correspondingly adding the root element to the root of the document tree to obtain an xml type test case;
creating an XMLDcument Document through Document doc () in java to obtain a root of a Document tree; creating a root Element through Element rootElmt ═ doc.addElement (typeof (T) Name + "s"), and recursively constructing sub-elements corresponding to the Map type test case to elements in the root Element through for (Map < String > test case: maps); and adding a root element into the root of the document tree through outputXml (doc, fileTo), and outputting the converted xml type test case.
2. The assertion method of the automated testing of claim 1, wherein comparing the actual value of the xml-type test case with the expected value through a preset comparison class to obtain an assertion result, comprises:
comparing the actual value of the xml type test case with the expected value to obtain a comparison difference character;
judging whether the contrast difference characters meet preset assertions or not;
if the contrast difference character meets the assertion, returning an assertion success result;
if the contrast difference character does not meet the assertion, returning an assertion failure result.
3. An assertion apparatus for automated testing, comprising:
the xml type conversion unit is used for converting the map type or list type test case to obtain an xml type test case;
the assertion result obtaining unit is used for comparing the actual value and the expected value of the xml type test case through a preset comparison class to obtain an assertion result;
the assertion device for the automated test further comprises:
the contrast class setting unit is used for presetting a parser in xmlunit and setting node neglect attributes of a contrast class neglect space, an attribute position, an annotation, a text value and an attribute value in the parser;
wherein the attribute position in the contrast class is set by an XMLUnit.setIgoreAttributeOrder (true) class;
set annotations by xmlunit.
Set ignore blank by xmlunit.
Setting a node ignore attribute of a text value and an attribute value by diff.overdiffirencelist () class;
the xml-type conversion unit includes:
a first document tree creating unit for creating a root of a document tree;
the first root element creating unit is used for creating a root element and adding a child element set corresponding to the test case of the list type into the root element;
the first conversion unit is used for correspondingly adding the root element to the root of the document tree to obtain the xml type test case;
creating an XMLDcument document through XmlDocument doc ═ new XmlDocument () in java to obtain a root of a document tree; creating a root element by XmlElement root ═ doc.createeelement (typeof (t). Name + "s"), and by foreach (t element entries) { EntityToXml (doc, root, item); adding a sub-element set corresponding to the test case of the list type into the root element; adding a root element to a root of the document tree through doc. appendix child (root), and outputting a converted xml type test case;
or the xml-type conversion unit, comprising:
a second document tree creating unit for creating a root of the document tree;
the second root element creating unit is used for creating a root element and recursively constructing a child element corresponding to the map type test case according to the root element;
the second conversion unit is used for correspondingly adding the root element to the root of the document tree to obtain the xml type test case;
creating an XMLDcument Document through Document doc () in java to obtain a root of a Document tree; creating a root Element through Element rootElmt ═ doc.addElement (typeof (T) Name + "s"), and recursively constructing sub-elements corresponding to the Map type test case to elements in the root Element through for (Map < String > test case: maps); and adding a root element into the root of the document tree through outputXml (doc, fileTo), and outputting the converted xml type test case.
4. A computer device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor implements the assertion method of the automation test of any of claims 1-2 when executing the computer program.
5. A storage medium, characterized in that the storage medium stores a computer program comprising program instructions which, when executed by a processor, cause the processor to carry out the assertion method of the automation test of any one of claims 1-2.
CN201810196488.8A 2018-03-09 2018-03-09 Assertion method and device for automatic test, computer equipment and storage medium Active CN108536583B (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN201810196488.8A CN108536583B (en) 2018-03-09 2018-03-09 Assertion method and device for automatic test, computer equipment and storage medium
PCT/CN2018/085251 WO2019169720A1 (en) 2018-03-09 2018-05-02 Automatic test assertion method and apparatus, and computer device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810196488.8A CN108536583B (en) 2018-03-09 2018-03-09 Assertion method and device for automatic test, computer equipment and storage medium

Publications (2)

Publication Number Publication Date
CN108536583A CN108536583A (en) 2018-09-14
CN108536583B true CN108536583B (en) 2021-03-16

Family

ID=63483440

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810196488.8A Active CN108536583B (en) 2018-03-09 2018-03-09 Assertion method and device for automatic test, computer equipment and storage medium

Country Status (2)

Country Link
CN (1) CN108536583B (en)
WO (1) WO2019169720A1 (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109522225B (en) * 2018-11-09 2022-06-07 网宿科技股份有限公司 Automatic test assertion method and device, test platform and storage medium

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105760292A (en) * 2014-12-18 2016-07-13 阿里巴巴集团控股有限公司 Assertion verification method and device for unit testing
CN106886390A (en) * 2015-12-15 2017-06-23 大唐软件技术股份有限公司 A kind of Java object generation and conversion method and Java object generation and conversion equipment

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030003432A1 (en) * 2001-05-16 2003-01-02 Kinzhalin Arzhan I System and method for automated assertion acquisition in a Java compatibility testing environment
US7272829B1 (en) * 2003-07-22 2007-09-18 Sun Microsystems, Inc. Factored assert chains
CN103136095A (en) * 2011-11-28 2013-06-05 阿里巴巴集团控股有限公司 Method, device and system of test application program interface
CN104484269A (en) * 2014-11-27 2015-04-01 北京广利核系统工程有限公司 Method for automatically generating testing script
CN107483283B (en) * 2017-06-28 2020-03-06 珠海格力电器股份有限公司 Communication reliability test method and device

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105760292A (en) * 2014-12-18 2016-07-13 阿里巴巴集团控股有限公司 Assertion verification method and device for unit testing
CN106886390A (en) * 2015-12-15 2017-06-23 大唐软件技术股份有限公司 A kind of Java object generation and conversion method and Java object generation and conversion equipment

Also Published As

Publication number Publication date
CN108536583A (en) 2018-09-14
WO2019169720A1 (en) 2019-09-12

Similar Documents

Publication Publication Date Title
US8887135B2 (en) Generating test cases for functional testing of a software application
US10949381B2 (en) Reusable transformation mechanism to allow mappings between incompatible data types
CN107885499A (en) A kind of interface document generation method and terminal device
US20120143893A1 (en) Pattern Matching Framework for Log Analysis
US20170300305A1 (en) Executable guidance experiences based on implicitly generated guidance models
CN107729452B (en) Webpage loading method and device, electronic equipment and computer readable storage medium
US9208249B2 (en) Profiler for page rendering
CN110673847A (en) Configuration page generation method and device, electronic equipment and readable storage medium
US20140188929A1 (en) Computer-readable storage medium, file management apparatus, and file management method
CN107766036B (en) Module construction method and device and terminal equipment
CN113032393A (en) Method and device for binding associated object
CN112181924A (en) File conversion method, device, equipment and medium
CN108536583B (en) Assertion method and device for automatic test, computer equipment and storage medium
US7917873B1 (en) System and method for verification of integrated circuit design
CN111078217A (en) Brain graph generation method, apparatus and computer-readable storage medium
US8909579B2 (en) Identifying invariant candidates based on proofs
CN114048415A (en) Form generation method and device, electronic equipment and computer readable storage medium
CN114047970A (en) Configuration method and system of AUTOSAR (automotive open system architecture) architecture software
US20080162531A1 (en) Object-Oriented Framework for Data-Analysis Having Pluggable Platform Runtimes and Export Services
CN109189388A (en) Page configuration method, server and computer-readable medium
Balachander et al. LTL reactive synthesis with a few hints
US11861329B2 (en) Method and apparatus for codifying user experience designs and managing the codified user experience designs
CN115629763A (en) Target code generation method and NPU instruction display method and device
CN108089973A (en) A kind of information processing method and equipment
CN110737431A (en) Software development method, development platform, terminal device and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant