WO2019169720A1 - 自动化测试的断言方法、装置、计算机设备及存储介质 - Google Patents

自动化测试的断言方法、装置、计算机设备及存储介质 Download PDF

Info

Publication number
WO2019169720A1
WO2019169720A1 PCT/CN2018/085251 CN2018085251W WO2019169720A1 WO 2019169720 A1 WO2019169720 A1 WO 2019169720A1 CN 2018085251 W CN2018085251 W CN 2018085251W WO 2019169720 A1 WO2019169720 A1 WO 2019169720A1
Authority
WO
WIPO (PCT)
Prior art keywords
test case
assertion
root
type
xml
Prior art date
Application number
PCT/CN2018/085251
Other languages
English (en)
French (fr)
Inventor
周思聪
Original Assignee
平安科技(深圳)有限公司
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 平安科技(深圳)有限公司 filed Critical 平安科技(深圳)有限公司
Publication of WO2019169720A1 publication Critical patent/WO2019169720A1/zh

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

Definitions

  • the present application relates to the field of java automatic testing technology, and in particular, to an assertion method, device, computer device and storage medium for automated testing.
  • the present application provides an assertion method, apparatus, computer device and storage medium for automated testing, aiming at solving the problem of asserting a map or a list in the prior art, due to the possible multi-layer and sequence change of the map or list, the assertion It is more difficult.
  • the present application provides an assertion method for automated testing, comprising:
  • the actual value of the xml type test case is compared with the expected value through a preset comparison class to obtain an assertion result.
  • an assertion device for automated testing comprising:
  • An xml type conversion unit is configured to convert a test case of a map type or a list type to obtain an xml type test case
  • the assertion result obtaining unit is configured to compare the actual value of the xml type test case with the expected value through a preset comparison class to obtain an assertion result.
  • the present application further provides a computer device comprising a memory, a processor, and a computer program stored on the memory and operable on the processor, the processor implementing the computer program An assertion method for automated testing as described in any one of the applications provided herein.
  • the present application also provides a storage medium, wherein the storage medium stores a computer program, the computer program comprising program instructions, the program instructions, when executed by a processor, causing the processor to execute the application An assertion method for automated testing as described in any of the provided.
  • the application provides an assertion method, apparatus, computer device and storage medium for automated testing.
  • This method implements test cases that convert test cases of map or list into xml, reduces the existence of multiple layers and sequence changes in test cases, and makes assertions more convenient and flexible.
  • FIG. 1 is a schematic flowchart of an assertion method for an automated test according to an embodiment of the present application
  • FIG. 2 is a schematic diagram of a sub-flow of an assertion method for an automated test according to an embodiment of the present application
  • FIG. 3 is a schematic diagram of another sub-flow of an assertion method for automated testing according to an embodiment of the present application.
  • FIG. 4 is another schematic flowchart of an assertion method for an automated test according to an embodiment of the present application.
  • FIG. 5 is a schematic diagram of another sub-flow of an assertion method for automated testing 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 schematic block diagram of a subunit 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 according to an embodiment 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.
  • FIG. 1 is a schematic flow chart of an assertion method for an automated test according to an embodiment of the present application.
  • the method is applied to terminals such as desktop computers, laptop computers, and tablet computers.
  • the method includes steps S101 to S102.
  • S101 Convert a test case of a map type or a list type to obtain an xml type test use case.
  • the test case is converted from the original test type or list type test case to an xml type test case, in order to eliminate the data multi-layer storage and the data existence order in the test case of the map type or the list type.
  • the problem is to convert test cases into xml type test cases.
  • the step S101 includes the following sub-steps:
  • S1013a adds the root element corresponding to the root of the document tree to obtain an xml type test case.
  • step S101 includes the following sub-steps:
  • S1013b adds the root element corresponding to the root of the document tree to obtain an xml type test case.
  • Document doc DocumentHelper.createDocument() to implement the above XMLDocument document creation.
  • the method further includes:
  • the xmlunit when the parser in the xmlunit is set in advance, the xmlunit is called by System.setProperty to instantiate the parser of the xmlunit, and only after the parser of the xmlunit is instantiated, the comparison class can be used to compare between the two xml files. The difference.
  • Xmlunit is an XML validation tool for Java developers that demonstrates the process of validating XML documents to testers.
  • the xmlunit parser is also a type of xml parser that loads XML into memory and converts it into an XML DOM object that can be accessed via JavaScript.
  • the parser of xmlunit mainly includes functions for traversing the XML tree, accessing and deleting nodes (elements) and their attributes. In this application, a function is mainly selected in which an XML tree is traversed and an inserted element is accessed.
  • the location of the attribute in the comparison class is set by the XMLUnit.setIgnoreAttributeOrder(true) class;
  • the node that ignores the text value and the attribute value is ignored by the diff.overrideDifferenceListener() class; more specifically, the newIgnoreTextAndAttributeValuesDifferenceListener() is used as the input parameter of the diff.overrideDifferenceListener() class to set the text value and the attribute value of the node ignore attribute.
  • the Diff class overrideDifferenceListener() can be used to ignore node configuration. This is mainly when comparing, some values do not need to be compared, and may change every time, such as the timestamp on the return value (actual value).
  • the xml type test case can be asserted from front to back according to the data, without considering the multi-layer structure of the data and Multiple changes in the order reduce the difficulty of assertions.
  • the step S102 includes the following sub-steps:
  • the difference between the two xml files can be compared by the Diff class provided in the xmlunit.
  • the actual value refers to the result value obtained by the actual execution of the test case.
  • the expected value refers to the result value that the user expects the test case to execute.
  • the difference between the two values is their difference. If there is no difference, the assertion is passed, otherwise it fails.
  • testXML “ ⁇ account> ⁇ name>acme ⁇ /name> ⁇ id>3A-00 ⁇ /id> ⁇ /account>”;
  • Diff diff new Diff(controlXML, testXML), and the assertion of assertFalse(diff.identical()) is used to determine whether the two are identical.
  • the comparison difference character satisfies the assertion
  • the assertion success result is returned; when the comparison difference character satisfies the assertion, the assertion success result is returned.
  • this method implements a test case that converts the test case of map or list into xml, reduces the existence of multiple layers and sequential changes in the test case, and makes assertion more convenient and flexible.
  • FIG. 6 is a schematic block diagram of an assertion apparatus for automated testing according to an embodiment of the present application.
  • the assertion device 100 of the automated test can be installed in a desktop computer, a tablet computer, a laptop computer, or the like.
  • the assertion apparatus 100 of the automated test includes an xml type conversion unit 101 and an assertion result acquisition unit 102.
  • the xml type conversion unit 101 is configured to convert a test case of a map type or a list type to obtain an xml type test use case.
  • the test case is converted from the original test type or list type test case to an xml type test case, in order to eliminate the data multi-layer storage and the data existence order in the test case of the map type or the list type.
  • the problem is to convert test cases into xml type test cases.
  • the xml type conversion unit 101 includes the following subunits:
  • a first document tree creation unit 1011a for creating a root of a document tree
  • the first element creation unit 1012a is configured to create a root element, and add a set of child elements corresponding to the test case of the list type to the root element;
  • the first converting unit 1013a is configured to add a root element corresponding to the root of the document tree to obtain an xml type test case.
  • the xml type conversion unit 101 includes the following subunits:
  • 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 test case of the map type according to the root element;
  • the second converting unit 1013b is configured to add the root element corresponding to the root of the document tree to obtain an xml type test case.
  • the assertion apparatus 100 of the automated test further includes:
  • the comparison class setting unit 102a is configured to pre-set the parser in the xmlunit, and set the node ignore attribute of the comparison class of the ignore class, the attribute position, the annotation, the text value, and the attribute value in the parser.
  • the xmlunit when the parser in the xmlunit is set in advance, the xmlunit is called by System.setProperty to instantiate the parser of the xmlunit, and only after the parser of the xmlunit is instantiated, the comparison class can be used to compare between the two xml files. The difference.
  • Xmlunit is an XML validation tool for Java developers that demonstrates the process of validating XML documents to testers.
  • the xmlunit parser is also a type of xml parser that loads XML into memory and converts it into an XML DOM object that can be accessed via JavaScript.
  • the parser of xmlunit mainly includes functions for traversing the XML tree, accessing and deleting nodes (elements) and their attributes. In this application, a function is mainly selected in which an XML tree is traversed and an inserted element is accessed.
  • the location of the attribute in the comparison class is set by the XMLUnit.setIgnoreAttributeOrder(true) class;
  • the Diff class overrideDifferenceListener() can be used to ignore node configuration. This is mainly when comparing, some values do not need to be compared, and may change every time, such as the timestamp on the return value (actual value).
  • the xml type test case can be asserted from front to back according to the data, without considering the multi-layer structure of the data and Multiple changes in the order reduce the difficulty of assertions.
  • the assertion result obtaining unit 102 is configured to compare the actual value of the xml type test case with the expected value by using a preset comparison class to obtain an assertion result.
  • the assertion result obtaining unit 102 includes the following subunits:
  • the comparing unit 1021 is configured to compare the actual value of the xml type test case with the expected value to obtain a comparison difference character
  • the determining unit 1022 is configured to determine whether the comparison difference character satisfies the preset assertion
  • the assertion success return unit 1023 is configured to return a successful result of the assertion if the comparison difference character satisfies the assertion;
  • the assertion failure returns to unit 1024 for returning the assertion failure result if the comparison difference character does not satisfy the assertion.
  • the difference between the two xml files can be compared by the Diff class provided in the xmlunit.
  • the actual value refers to the result value obtained by the actual execution of the test case.
  • the expected value refers to the result value that the user expects the test case to execute.
  • the difference between the two values is their difference. If there is no difference, the assertion is passed, otherwise it fails.
  • testXML “ ⁇ account> ⁇ name>acme ⁇ /name> ⁇ id>3A-00 ⁇ /id> ⁇ /account>”;
  • Diff diff new Diff(controlXML, testXML), and the assertion of assertFalse(diff.identical()) is used to determine whether the two are identical.
  • the comparison difference character satisfies the assertion
  • the assertion success result is returned; when the comparison difference character satisfies the assertion, the assertion success result is returned.
  • the device implements a test case for converting a test case of a map or a list into an xml, and reduces the multi-layer and sequence changes existing in the test case, and the assertion can be more convenient and flexible.
  • the above-described automated test assertion device can be implemented in the form of a computer program that can be run on a computer device as shown in FIG.
  • FIG. 11 is a schematic block diagram of a computer device according to an embodiment of the present application.
  • the computer device 500 device can be a terminal.
  • the terminal can be an electronic device such as a tablet computer, a notebook computer, a desktop computer, or a personal digital assistant.
  • the computer device 500 includes a processor 502, a memory, and a network interface 505 connected by a system bus 501, wherein the memory can include a non-volatile storage medium 503 and an internal memory 504.
  • the non-volatile storage medium 503 can store an operating system 5031 and a computer program 5032.
  • the computer program 5032 includes program instructions that, when executed, cause the processor 502 to perform an assertion method for automated testing.
  • the processor 502 is used to provide computing and control capabilities to support the operation of the entire computer device 500.
  • the internal memory 504 provides an environment for operation of the computer program 5032 in the non-volatile storage medium 503, which when executed by the processor 502, may cause the processor 502 to perform an assertion method of automated testing.
  • the network interface 505 is used for network communication, such as sending assigned tasks and the like. It will be understood by those skilled in the art that the structure shown in FIG. 11 is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation of the computer device 500 to which the solution of the present application is applied, and a specific computer device. 500 may include more or fewer components than shown, or some components may be combined, or have different component arrangements.
  • the processor 502 is configured to run a computer program 5032 stored in the memory to implement the following functions: converting a test case of a map type or a list type to obtain an xml type test case; and using a preset comparison class to execute the xml The actual value of the type test case is compared with the expected value to obtain the asserted result.
  • the processor 502 further performs the operations of: creating a root of the document tree; creating a root element, and adding a set of child elements corresponding to the test case of the list type to the root element; adding the root element corresponding to the document The root of the tree gets the xml type test case.
  • the processor 502 also performs the operations of: creating a root of the document tree; creating a root element, and recursively constructing a child element corresponding to the test case of the map type according to the root element; adding the root element corresponding to the document tree Root, get the xml type test case.
  • the processor 502 also performs the following operations: pre-setting the parser in the xmlunit, and setting the node ignore attribute of the comparison class in the parser for ignoring spaces, attribute positions, annotations, text values, and attribute values.
  • the processor 502 further performs the following operations: comparing the actual value of the xml type test case with the expected value to obtain a comparison difference character; determining whether the comparison difference character satisfies the preset assertion; and if the comparison difference character satisfies the assertion Returns the successful result of the assertion; if the comparison difference character does not satisfy the assertion, the result of the assertion failure is returned.
  • the embodiment of the computer device shown in FIG. 11 does not constitute a limitation on the specific configuration of the computer device.
  • the computer device may include more or fewer components than illustrated. Or combine some parts, or different parts.
  • the computer device may include only a memory and a processor. In such an embodiment, the structure and function of the memory and the processor are the same as those of the embodiment shown in FIG. 11, and details are not described herein again.
  • the processor 502 may be a central processing unit (CPU), and the processor 502 may also be another general-purpose processor, a digital signal processor (DSP), Application Specific Integrated Circuit (ASIC), Field-Programmable Gate Array (FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware component, etc.
  • the general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
  • a storage medium in another embodiment of the present application, can be a non-transitory computer readable storage medium.
  • the storage medium stores a computer program, wherein the computer program includes program instructions.
  • the program instruction is executed by the processor, the test case of the map type or the list type is converted to obtain an xml type test case; the actual value of the xml type test case is compared with the expected value by a preset comparison class to obtain an assertion. result.
  • the program instruction is implemented by the processor: creating a root of the document tree; creating a root element, and adding a set of child elements corresponding to the test case of the list type to the root element; increasing the root element correspondingly Go to the root of the document tree and get the xml type test case.
  • the program instructions are executed by the processor to: create a root of the document tree; create a root element, and recursively construct a child element corresponding to the test case of the map type according to the root element; and add the root element corresponding to the document
  • the root of the tree gets the xml type test case.
  • the program instructions are implemented by the processor: pre-set the parser in the xmlunit, and set the node ignore attribute of the comparison class in the parser to ignore spaces, attribute positions, annotations, text values, and attribute values.
  • the actual value of the xml type test case is compared with the expected value to obtain a comparison difference character; whether the comparison difference character satisfies the preset assertion; Satisfies the assertion and returns the assertion success result; if the comparison difference character does not satisfy the assertion, the assertion failure result is returned.
  • 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 equipped on the device, a smart memory card (SMC), a secure digital (SD) card, and a flash memory card. (Flash Card), etc.
  • the storage medium may also include both an internal storage unit of the device and an external storage device.
  • the disclosed apparatus, apparatus, and method may be implemented in other manners.
  • the device embodiments described above are merely illustrative.
  • the division of the unit is only a logical function division.
  • the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interface, device or unit, or an electrical, mechanical or other form of connection.
  • 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, may be located in one place, or may be distributed to multiple network units. Some or all of the units may be selected according to actual needs to achieve the objectives of the embodiments of the present invention.
  • each functional unit in each embodiment of the present invention 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 integrated unit can be implemented in the form of hardware or in the 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 standalone product, may be stored in a storage medium.
  • the technical solution of the present invention contributes in essence or to the prior art, or all or part of the technical solution may be embodied in the form of a software product stored in a storage medium.
  • a number of instructions are included to cause a computer device (which may be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods described in various embodiments of the present invention.
  • the foregoing storage medium includes: a U disk, a removable hard disk, a read-only memory (ROM), a magnetic disk, or an optical disk, and the like, which can store program codes.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Computational Linguistics (AREA)
  • General Health & Medical Sciences (AREA)
  • Health & Medical Sciences (AREA)
  • Artificial Intelligence (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Multimedia (AREA)
  • Debugging And Monitoring (AREA)

Abstract

一种自动化测试的断言方法、装置、计算机设备及存储介质。该方法包括:通过将map类型或list类型的测试用例进行转化,得到xml类型测试用例(S101);通过预先设置的对比类将xml类型测试用例的实际值与期望值进行比对,得到断言结果(S102)。该方法实现了将map或list的测试用例转化为xml的测试用例,降低测试用例中存在的多层以及顺序变化,进行断言可以更加便捷和灵活。

Description

自动化测试的断言方法、装置、计算机设备及存储介质
本申请要求于2018年3月9日提交中国专利局、申请号为201810196488.8、申请名称为“自动化测试的断言方法、装置、计算机设备及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及java自动化测试技术领域,尤其涉及一种自动化测试的断言方法、装置、计算机设备及存储介质。
背景技术
在编写代码时总是会做出一些假设,断言就是用于在代码中捕捉假设,即可将断言看作是异常处理的一种高级形式。断言表示为一些布尔表达式,用于对某些关键数据的判断,如果这一关键数据并非所预期的数据,程序就提出警告或退出。目前,java自动化测试中对map或list的断言时,由于map或list可能存在多层以及顺序变化的问题,断言难度比较大。
发明内容
本申请提供了一种自动化测试的断言方法、装置、计算机设备及存储介质,旨在解决现有技术中对map或list的断言时,由于map或list可能存在多层以及顺序变化的问题,断言难度比较大。
第一方面,本申请提供了一种自动化测试的断言方法,其包括:
将map类型或list类型的测试用例进行转化,得到xml类型测试用例;
通过预先设置的对比类将xml类型测试用例的实际值与期望值进行比对,得到断言结果。
第二方面,本申请提供了一种自动化测试的断言装置,其包括:
xml类型转化单元,用于将map类型或list类型的测试用例进行转化,得到xml类型测试用例;
断言结果获取单元,用于通过预先设置的对比类将xml类型测试用例的实 际值与期望值进行比对,得到断言结果。
第三方面,本申请又提供了一种计算机设备,包括存储器、处理器及存储在所述存储器上并可在所述处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现本申请提供的任一项所述的自动化测试的断言方法。
第四方面,本申请还提供了一种存储介质,其中所述存储介质存储有计算机程序,所述计算机程序包括程序指令,所述程序指令当被处理器执行时使所述处理器执行本申请提供的任一项所述的自动化测试的断言方法。
本申请提供一种自动化测试的断言方法、装置、计算机设备及存储介质。该方法实现了将map或list的测试用例转化为xml的测试用例,降低测试用例中存在的多层以及顺序变化,进行断言可以更加便捷和灵活。
附图说明
为了更清楚地说明本申请实施例技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。
图1为本申请实施例提供的一种自动化测试的断言方法的示意流程图;
图2是本申请实施例提供的一种自动化测试的断言方法的子流程示意图;
图3是本申请实施例提供的一种自动化测试的断言方法的另一子流程示意图;
图4为本申请实施例提供的一种自动化测试的断言方法的另一示意流程图;
图5为本申请实施例提供的一种自动化测试的断言方法的另一子流程示意图;
图6为本申请实施例提供的一种自动化测试的断言装置的示意性框图;
图7为本申请实施例提供的一种自动化测试的断言装置的子单元示意性框图;
图8为本申请实施例提供的一种自动化测试的断言装置的另一子单元示意性框图;
图9为本申请实施例提供的一种自动化测试的断言装置的另一示意性框图;
图10为本申请实施例提供的一种自动化测试的断言装置的另一子单元示意 性框图;
图11为本申请实施例提供的一种计算机设备的示意性框图。
具体实施方式
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。
请参阅图1,图1是本申请实施例提供的一种自动化测试的断言方法的示意流程图。该方法应用于台式电脑、手提电脑、平板电脑等终端中。如图1所示,该方法包括步骤S101~S102。
S101、将map类型或list类型的测试用例进行转化,得到xml类型测试用例。
在本实施例中,将测试用例由原有的map类型或list类型的测试用例,转化为xml类型测试用例,是为了消除map类型或list类型的测试用例中数据多层存储及数据存在顺序的问题,将测试用例转化为xml类型测试用例。
如图2所示,该步骤S101包括以下子步骤:
S1011a、创建文档树的根;
S1012a、创建根元素,并向根元素中增加设置与list类型的测试用例对应的子元素集;
S1013a、将根元素对应增加至文档树的根,得到xml类型测试用例。
在本实施例中,先通过java中的XmlDocument doc=new XmlDocument()来实现XMLDocument文档的创建(XMLDocument文档即为文档树的根)。然后通过XmlElement root=doc.CreateElement(typeof(T).Name+″s″)来实现根元素的创建,并通过foreach(T item in items){EntityToXml(doc,root,item);}来实现在根元素中添加与list类型的测试用例对应的子元素集。最后通过doc.AppendChild(root)向XMLDocument文档中添加根元素,输出转化后的xml类型测试用例。
如图3所示,作为步骤S101的另一实施例,该步骤S101包括以下子步骤:
S1011b、创建文档树的根;
S1012b、创建根元素,并根据根元素递归构造与map类型的测试用例对应的子元素;
S1013b、将根元素对应增加至文档树的根,得到xml类型测试用例。
在本实施例中,先通过java中:
Document doc=DocumentHelper.createDocument()来实现上述XMLDocument文档创建。
然后通过Element rootElmt=doc.addElement(typeof(T).Name+″s″)来实现根元素的创建,并通过for(Map<String,String>Testcase:maps)来实现在根元素中递归构造与map类型的测试用例对应的子元素。最后通过outPutXml(doc,fileTo)向XMLDocument文档中添加根元素,输出转化后的xml类型测试用例。
更具体的,在根元素中递归构造与map类型的测试用例对应的子元素时通过Element Testcase Elmt=rootElmt.addElement(″Testcase″)来为测试用例增加属性。
如图4所示,在所述步骤S102之前还包括:
S102a、预先设置xmlunit中的解析器,并设置解析器中对比类的忽略空格、属性位置、注解、文本值和属性值的节点忽略属性。
在本实施例中,预先设置xmlunit中的解析器时,通过System.setProperty调用xmlunit,以实例化xmlunit的解析器,只有在xmlunit的解析器实例化后才能使用对比类比较两个xml文件之间的区别。Xmlunit是可用于Java开发人员的XML验证工具,可向测试人员展示验证XML文档的过程。
xmlunit的解析器也是xml解析器的一种,用于将XML载入内存,然后把它转换为可通过JavaScript访问的XML DOM对象。xmlunit的解析器中主要包括遍历XML树、访问插入及删除节点(元素)及其属性的函数。本申请中主要选择其中遍历XML树、访问插入元素的函数。
在实例化xmlunit的解析器后,需设置解析器中对比类的忽略空格、属性位置、注解、文本值和属性值的节点忽略属性。
具体的,通过XMLUnit.setIgnoreAttributeOrder(true)类来设置对比类中的属性位置;
通过XMLUnit.setIgnoreComments(true)类来设置注解;
通过XMLUnit.setIgnoreWhitespace(true)类来设置空格(空格也即空白);
通过diff.overrideDifferenceListener()类来设置文本值和属性值的节点忽略属 性;更具体的是将newIgnoreTextAndAttributeValuesDifferenceListener()作为diff.overrideDifferenceListener()类的入参来设置文本值和属性值的节点忽略属性。
简单来说,Diff类的overrideDifferenceListener()可进行忽略节点配置。这个主要是在对比的时候,有的值不需要进行对比,而且可能每次返回都有变化,如在返回值(实际值)上的时间戳。当完成了xmlunit中的解析器的初始化、及解析器中对比类的各种基本属性设置后,即可将xml类型测试用例按照其中的数据从前至后进行断言,无需考虑数据的多层结构及顺序的多种变化,降低了断言的难度。
S102、通过预先设置的对比类将xml类型测试用例的实际值与期望值进行比对,得到断言结果。
如图5所示,该步骤S102包括以下子步骤:
S1021、将xml类型测试用例的实际值与期望值进行比对,得到对比差异字符;
S1022、判断对比差异字符是否满足预设的断言;
S1023、若对比差异字符满足断言,返回断言成功结果;
S1024、若对比差异字符不满足断言,返回断言失败结果。
在本实施例中,由xmlunit中提供的Diff类可对比两个xml文件的差异。实际值指测试用例实际执行得到的结果值,期望值指用户期望测试用例执行得到的结果值。两个值比较得到的是它们的差异,如果没有差异,就是断言通过,否则失败。
例如xml类型的测试用例的期望值记为String controlXML=″<account><id>3A-00</id><name>acme</name></account>″;
xml类型的测试用例的实际值记为String testXML=″<account><name>acme</name><id>3A-00</id></account>″;
通过Diff diff=new Diff(controlXML,testXML)来进行两者之间的对比,并通过assertFalse(diff.identical())这一断言来判断两者之间是否完全相同。当对比差异字符满足断言,返回断言成功结果;当对比差异字符满足断言,返回断言成功结果。通过xmlunit中提供的Diff类,实现了快速且准确的将xml类型测试用例的实际值与期望值进行比对。
可见,该方法实现了将map或list的测试用例转化为xml的测试用例,降 低测试用例中存在的多层以及顺序变化,进行断言可以更加便捷和灵活。
本申请实施例还提供一种自动化测试的断言装置,该自动化测试的断言装置用于执行前述任一项自动化测试的断言方法。具体地,请参阅图6,图6是本申请实施例提供的一种自动化测试的断言装置的示意性框图。自动化测试的断言装置100可以安装于台式电脑、平板电脑、手提电脑、等终端中。
如图6所示,自动化测试的断言装置100包括xml类型转化单元101、断言结果获取单元102。
xml类型转化单元101,用于将map类型或list类型的测试用例进行转化,得到xml类型测试用例。
在本实施例中,将测试用例由原有的map类型或list类型的测试用例,转化为xml类型测试用例,是为了消除map类型或list类型的测试用例中数据多层存储及数据存在顺序的问题,将测试用例转化为xml类型测试用例。
其他发明实施例中,如图7所示,所述xml类型转化单元101包括以下子单元:
第一文档树创建单元1011a,用于创建文档树的根;
第一根元素创建单元1012a,用于创建根元素,并向根元素中增加设置与list类型的测试用例对应的子元素集;
第一转化单元1013a,用于将根元素对应增加至文档树的根,得到xml类型测试用例。
在本实施例中,先通过java中的XmlDocument doc=new XmlDocument()来实现XMLDocument文档的创建(XMLDocument文档即为文档树的根)。然后通过XmlElement root=doc.CreateElement(typeof(T).Name+″s″)来实现根元素的创建,并通过foreach(T item in items){EntityToXml(doc,root,item);}来实现在根元素中添加与list类型的测试用例对应的子元素集。最后通过doc.AppendChild(root)向XMLDocument文档中添加根元素,输出转化后的xml类型测试用例。
如图8所示,作为xml类型转化单元101的另一实施例,所述xml类型转化单元101包括以下子单元:
第二文档树创建单元1011b,用于创建文档树的根;
第二根元素创建单元1012b,用于创建根元素,并根据根元素递归构造与 map类型的测试用例对应的子元素;
第二转化单元1013b,用于将根元素对应增加至文档树的根,得到xml类型测试用例。
在本实施例中,先通过java中的XmlDocument doc=new XmlDocument()来实现XMLDocument文档的创建(XMLDocument文档即为文档树的根)。然后通过XmlElement root=doc.CreateElement(typeof(T).Name+″s″)来实现根元素的创建,并通过foreach(T item in items){EntityToXml(doc,root,item);}来实现在根元素中添加与list类型的测试用例对应的子元素集。最后通过doc.AppendChild(root)向XMLDocument文档中添加根元素,输出转化后的xml类型测试用例。
其他发明实施例中,如图9所示,所述自动化测试的断言装置100还包括:
对比类设置单元102a,用于预先设置xmlunit中的解析器,并设置解析器中对比类的忽略空格、属性位置、注解、文本值和属性值的节点忽略属性。
在本实施例中,预先设置xmlunit中的解析器时,通过System.setProperty调用xmlunit,以实例化xmlunit的解析器,只有在xmlunit的解析器实例化后才能使用对比类比较两个xml文件之间的区别。Xmlunit是可用于Java开发人员的XML验证工具,可向测试人员展示验证XML文档的过程。
xmlunit的解析器也是xml解析器的一种,用于将XML载入内存,然后把它转换为可通过JavaScript访问的XML DOM对象。xmlunit的解析器中主要包括遍历XML树、访问插入及删除节点(元素)及其属性的函数。本申请中主要选择其中遍历XML树、访问插入元素的函数。
在实例化xmlunit的解析器后,需设置解析器中对比类的忽略空格、属性位置、注解、文本值和属性值的节点忽略属性。
具体的,通过XMLUnit.setIgnoreAttributeOrder(true)类来设置对比类中的属性位置;
通过XMLUnit.setIgnoreComments(true)类来设置注解;
通过XMLUnit.setIgnoreWhitespace(true)类来设置空格(空格也即空白);
通过diff.overrideDifferenceListener()类来设置文本值和属性值的节点忽略属性;更具体的是将newIgnoreTextAndAttributeValuesDifferenceListener()作为diff.overrideDifferenceListener()类的入参来设置文本值和属性值的节点忽略属性。
简单来说,Diff类的overrideDifferenceListener()可进行忽略节点配置。这个主要是在对比的时候,有的值不需要进行对比,而且可能每次返回都有变化,如在返回值(实际值)上的时间戳。当完成了xmlunit中的解析器的初始化、及解析器中对比类的各种基本属性设置后,即可将xml类型测试用例按照其中的数据从前至后进行断言,无需考虑数据的多层结构及顺序的多种变化,降低了断言的难度。
断言结果获取单元102,用于通过预先设置的对比类将xml类型测试用例的实际值与期望值进行比对,得到断言结果。
其他发明实施例中,如图10所示,所述断言结果获取单元102包括以下子单元:
比对单元1021,用于将xml类型测试用例的实际值与期望值进行比对,得到对比差异字符;
判断单元1022,用于判断对比差异字符是否满足预设的断言;
断言成功返回单元1023,用于若对比差异字符满足断言,返回断言成功结果;
断言失败返回单元1024,用于若对比差异字符不满足断言,返回断言失败结果。
在本实施例中,由xmlunit中提供的Diff类可对比两个xml文件的差异。实际值指测试用例实际执行得到的结果值,期望值指用户期望测试用例执行得到的结果值。两个值比较得到的是它们的差异,如果没有差异,就是断言通过,否则失败。
例如xml类型的测试用例的期望值记为String controlXML=″<account><id>3A-00</id><name>acme</name></account>″;
xml类型的测试用例的实际值记为String testXML=″<account><name>acme</name><id>3A-00</id></account>″;
通过Diff diff=new Diff(controlXML,testXML)来进行两者之间的对比,并通过assertFalse(diff.identical())这一断言来判断两者之间是否完全相同。当对比差异字符满足断言,返回断言成功结果;当对比差异字符满足断言,返回断言成功结果。通过xmlunit中提供的Diff类,实现了快速且准确的将xml类型测试用例的实际值与期望值进行比对。
可见,该装置实现了将map或list的测试用例转化为xml的测试用例,降低测试用例中存在的多层以及顺序变化,进行断言可以更加便捷和灵活。
上述自动化测试的断言装置可以实现为一种计算机程序的形式,该计算机程序可以在如图11所示的计算机设备上运行。
请参阅图11,图11是本申请实施例提供的一种计算机设备的示意性框图。该计算机设备500设备可以是终端。该终端可以是平板电脑、笔记本电脑、台式电脑、个人数字助理等电子设备。
参阅图11,该计算机设备500包括通过系统总线501连接的处理器502、存储器和网络接口505,其中,存储器可以包括非易失性存储介质503和内存储器504。
该非易失性存储介质503可存储操作系统5031和计算机程序5032。该计算机程序5032包括程序指令,该程序指令被执行时,可使得处理器502执行一种自动化测试的断言方法。
该处理器502用于提供计算和控制能力,支撑整个计算机设备500的运行。
该内存储器504为非易失性存储介质503中的计算机程序5032的运行提供环境,该计算机程序5032被处理器502执行时,可使得处理器502执行一种自动化测试的断言方法。
该网络接口505用于进行网络通信,如发送分配的任务等。本领域技术人员可以理解,图11中示出的结构,仅仅是与本申请方案相关的部分结构的框图,并不构成对本申请方案所应用于其上的计算机设备500的限定,具体的计算机设备500可以包括比图中所示更多或更少的部件,或者组合某些部件,或者具有不同的部件布置。
其中,所述处理器502用于运行存储在存储器中的计算机程序5032,以实现如下功能:将map类型或list类型的测试用例进行转化,得到xml类型测试用例;通过预先设置的对比类将xml类型测试用例的实际值与期望值进行比对,得到断言结果。
在一实施例中,处理器502还执行如下操作:创建文档树的根;创建根元素,并向根元素中增加设置与list类型的测试用例对应的子元素集;将根元素对应增加至文档树的根,得到xml类型测试用例。
在一实施例中,处理器502还执行如下操作:创建文档树的根;创建根元 素,并根据根元素递归构造与map类型的测试用例对应的子元素;将根元素对应增加至文档树的根,得到xml类型测试用例。
在一实施例中,处理器502还执行如下操作:预先设置xmlunit中的解析器,并设置解析器中对比类的忽略空格、属性位置、注解、文本值和属性值的节点忽略属性。
在一实施例中,处理器502还执行如下操作:将xml类型测试用例的实际值与期望值进行比对,得到对比差异字符;判断对比差异字符是否满足预设的断言;若对比差异字符满足断言,返回断言成功结果;若对比差异字符不满足断言,返回断言失败结果。
本领域技术人员可以理解,图11中示出的计算机设备的实施例并不构成对计算机设备具体构成的限定,在其他实施例中,计算机设备可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置。例如,在一些实施例中,计算机设备可以仅包括存储器及处理器,在这样的实施例中,存储器及处理器的结构及功能与图11所示实施例一致,在此不再赘述。
应当理解,在本申请实施例中,处理器502可以是中央处理单元(Central Processing Unit,CPU),该处理器502还可以是其他通用处理器、数字信号处理器(Digital Signal Processor,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现成可编程门阵列(Field-Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。其中,通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。
在本申请的另一实施例中提供一种存储介质。该存储介质可以为非易失性的计算机可读存储介质。该存储介质存储有计算机程序,其中计算机程序包括程序指令。该程序指令被处理器执行时实现:将map类型或list类型的测试用例进行转化,得到xml类型测试用例;通过预先设置的对比类将xml类型测试用例的实际值与期望值进行比对,得到断言结果。
在一实施例中,该程序指令被处理器执行时实现:创建文档树的根;创建根元素,并向根元素中增加设置与list类型的测试用例对应的子元素集;将根元素对应增加至文档树的根,得到xml类型测试用例。
在一实施例中,该程序指令被处理器执行时实现:创建文档树的根;创建根元素,并根据根元素递归构造与map类型的测试用例对应的子元素;将根元 素对应增加至文档树的根,得到xml类型测试用例。
在一实施例中,该程序指令被处理器执行时实现:预先设置xmlunit中的解析器,并设置解析器中对比类的忽略空格、属性位置、注解、文本值和属性值的节点忽略属性。
在一实施例中,该程序指令被处理器执行时实现:将xml类型测试用例的实际值与期望值进行比对,得到对比差异字符;判断对比差异字符是否满足预设的断言;若对比差异字符满足断言,返回断言成功结果;若对比差异字符不满足断言,返回断言失败结果。
所述存储介质可以是前述设备的内部存储单元,例如设备的硬盘或内存。所述存储介质也可以是所述设备的外部存储设备,例如所述设备上配备的插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(Flash Card)等。进一步地,所述存储介质还可以既包括所述设备的内部存储单元也包括外部存储设备。
所属领域的技术人员可以清楚地了解到,为了描述的方便和简洁,上述描述的设备、装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、计算机软件或者二者的结合来实现,为了清楚地说明硬件和软件的可互换性,在上述说明中已经按照功能一般性地描述了各示例的组成及步骤。这些功能究竟以硬件还是软件方式来执行取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本发明的范围。
在本申请所提供的几个实施例中,应该理解到,所揭露的设备、装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,也可以将具有相同功能的单元集合成一个单元,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另外,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口、装置或单元的间接耦合或通信连接,也可以是电的,机械的或其它的形式连接。
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本发明实施例方案的目的。
另外,在本发明各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以是两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。
所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个存储介质中。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分,或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本发明各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、磁碟或者光盘等各种可以存储程序代码的介质。
以上所述,仅为本发明的具体实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,可轻易想到各种等效的修改或替换,这些修改或替换都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应以权利要求的保护范围为准。

Claims (20)

  1. 一种自动化测试的断言方法,其特征在于,包括:
    将map类型或list类型的测试用例进行转化,得到xml类型测试用例;
    通过预先设置的对比类将xml类型测试用例的实际值与期望值进行比对,得到断言结果。
  2. 根据权利要求1所述的自动化测试的断言方法,其特征在于,所述将list类型的测试用例进行转化,得到xml类型测试用例,包括:
    创建文档树的根;
    创建根元素,并向根元素中增加设置与list类型的测试用例对应的子元素集;
    将根元素对应增加至文档树的根,得到xml类型测试用例。
  3. 根据权利要求1所述的自动化测试的断言方法,其特征在于,所述将map类型的测试用例进行转化,得到xml类型测试用例,包括:
    创建文档树的根;
    创建根元素,并根据根元素递归构造与map类型的测试用例对应的子元素;
    将根元素对应增加至文档树的根,得到xml类型测试用例。
  4. 根据权利要求1所述的自动化测试的断言方法,其特征在于,所述通过预先设置的对比类将xml类型测试用例的实际值与期望值进行比对,得到断言结果之前,还包括:
    预先设置xmlunit中的解析器,并设置解析器中对比类的忽略空格、属性位置、注解、文本值和属性值的节点忽略属性。
  5. 根据权利要求1所述的自动化测试的断言方法,其特征在于,所述通过预先设置的对比类将xml类型测试用例的实际值与期望值进行比对,得到断言结果,包括:
    将xml类型测试用例的实际值与期望值进行比对,得到对比差异字符;
    判断对比差异字符是否满足预设的断言;
    若对比差异字符满足断言,返回断言成功结果;
    若对比差异字符不满足断言,返回断言失败结果。
  6. 一种自动化测试的断言装置,其特征在于,包括:
    xml类型转化单元,用于将map类型或list类型的测试用例进行转化,得到 xml类型测试用例;
    断言结果获取单元,用于通过预先设置的对比类将xml类型测试用例的实际值与期望值进行比对,得到断言结果。
  7. 根据权利要求6所述的自动化测试的断言装置,其特征在于,所述xml类型转化单元,包括:
    创建文档树的根;
    创建根元素,并向根元素中增加设置与list类型的测试用例对应的子元素集;
    将根元素对应增加至文档树的根,得到xml类型测试用例。
  8. 根据权利要求6所述的自动化测试的断言装置,其特征在于,还包括:
    对比类设置单元,用于预先设置xmlunit中的解析器,并设置解析器中对比类的忽略空格、属性位置、注解、文本值和属性值的节点忽略属性。
  9. 根据权利要求6所述的自动化测试的断言装置,其特征在于,所述xml类型转化单元,包括:
    第二文档树创建单元,用于创建文档树的根;
    第二根元素创建单元,用于创建根元素,并根据根元素递归构造与map类型的测试用例对应的子元素;
    第二转化单元,用于将根元素对应增加至文档树的根,得到xml类型测试用例。
  10. 根据权利要求6所述的自动化测试的断言装置,其特征在于,所述断言结果获取单元,包括:
    比对单元,用于将xml类型测试用例的实际值与期望值进行比对,得到对比差异字符;
    判断单元,用于判断对比差异字符是否满足预设的断言;
    断言成功返回单元,用于若对比差异字符满足断言,返回断言成功结果;
    断言失败返回单元,用于若对比差异字符不满足断言,返回断言失败结果。
  11. 一种计算机设备,包括存储器、处理器及存储在所述存储器上并可在所述处理器上运行的计算机程序,其特征在于,所述处理器执行所述计算机程序时实现以下步骤:
    将map类型或list类型的测试用例进行转化,得到xml类型测试用例;
    通过预先设置的对比类将xml类型测试用例的实际值与期望值进行比对, 得到断言结果。
  12. 根据权利要求11所述的计算机设备,其特征在于,所述将list类型的测试用例进行转化,得到xml类型测试用例,包括:
    创建文档树的根;
    创建根元素,并向根元素中增加设置与list类型的测试用例对应的子元素集;
    将根元素对应增加至文档树的根,得到xml类型测试用例。
  13. 根据权利要求11所述的计算机设备,其特征在于,所述将map类型的测试用例进行转化,得到xml类型测试用例,包括:
    创建文档树的根;
    创建根元素,并根据根元素递归构造与map类型的测试用例对应的子元素;
    将根元素对应增加至文档树的根,得到xml类型测试用例。
  14. 根据权利要求11所述的计算机设备,其特征在于,所述通过预先设置的对比类将xml类型测试用例的实际值与期望值进行比对,得到断言结果之前,还包括:
    预先设置xmlunit中的解析器,并设置解析器中对比类的忽略空格、属性位置、注解、文本值和属性值的节点忽略属性。
  15. 根据权利要求11所述的计算机设备,其特征在于,所述通过预先设置的对比类将xml类型测试用例的实际值与期望值进行比对,得到断言结果,包括:
    将xml类型测试用例的实际值与期望值进行比对,得到对比差异字符;
    判断对比差异字符是否满足预设的断言;
    若对比差异字符满足断言,返回断言成功结果;
    若对比差异字符不满足断言,返回断言失败结果。
  16. 一种存储介质,其特征在于,所述存储介质存储有计算机程序,所述计算机程序包括程序指令,所述程序指令当被处理器执行时使所述处理器执行以下操作:
    将map类型或list类型的测试用例进行转化,得到xml类型测试用例;
    通过预先设置的对比类将xml类型测试用例的实际值与期望值进行比对,得到断言结果。
  17. 根据权利要求16所述的存储介质,其特征在于,所述将list类型的测试用例进行转化,得到xml类型测试用例,包括:
    创建文档树的根;
    创建根元素,并向根元素中增加设置与list类型的测试用例对应的子元素集;
    将根元素对应增加至文档树的根,得到xml类型测试用例。
  18. 根据权利要求16所述的存储介质,其特征在于,所述将map类型的测试用例进行转化,得到xml类型测试用例,包括:
    创建文档树的根;
    创建根元素,并根据根元素递归构造与map类型的测试用例对应的子元素;
    将根元素对应增加至文档树的根,得到xml类型测试用例。
  19. 根据权利要求16所述的存储介质,其特征在于,所述通过预先设置的对比类将xml类型测试用例的实际值与期望值进行比对,得到断言结果之前,还包括:
    预先设置xmlunit中的解析器,并设置解析器中对比类的忽略空格、属性位置、注解、文本值和属性值的节点忽略属性。
  20. 根据权利要求16所述的存储介质,其特征在于,所述通过预先设置的对比类将xml类型测试用例的实际值与期望值进行比对,得到断言结果,包括:
    将xml类型测试用例的实际值与期望值进行比对,得到对比差异字符;
    判断对比差异字符是否满足预设的断言;
    若对比差异字符满足断言,返回断言成功结果;
    若对比差异字符不满足断言,返回断言失败结果。
PCT/CN2018/085251 2018-03-09 2018-05-02 自动化测试的断言方法、装置、计算机设备及存储介质 WO2019169720A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201810196488.8 2018-03-09
CN201810196488.8A CN108536583B (zh) 2018-03-09 2018-03-09 自动化测试的断言方法、装置、计算机设备及存储介质

Publications (1)

Publication Number Publication Date
WO2019169720A1 true WO2019169720A1 (zh) 2019-09-12

Family

ID=63483440

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2018/085251 WO2019169720A1 (zh) 2018-03-09 2018-05-02 自动化测试的断言方法、装置、计算机设备及存储介质

Country Status (2)

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

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109522225B (zh) * 2018-11-09 2022-06-07 网宿科技股份有限公司 一种自动化测试断言方法及装置、测试平台及存储介质

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7272829B1 (en) * 2003-07-22 2007-09-18 Sun Microsystems, Inc. Factored assert chains
CN103136095A (zh) * 2011-11-28 2013-06-05 阿里巴巴集团控股有限公司 一种测试应用程序接口的方法、装置及系统
CN104484269A (zh) * 2014-11-27 2015-04-01 北京广利核系统工程有限公司 一种自动生成测试脚本的方法
CN106886390A (zh) * 2015-12-15 2017-06-23 大唐软件技术股份有限公司 一种Java对象生成和转换方法和Java对象生成和转换装置
CN107483283A (zh) * 2017-06-28 2017-12-15 珠海格力电器股份有限公司 通讯可靠性测试方法和装置

Family Cites Families (2)

* 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
CN105760292B (zh) * 2014-12-18 2019-01-08 阿里巴巴集团控股有限公司 一种用于单元测试的断言验证方法和装置

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7272829B1 (en) * 2003-07-22 2007-09-18 Sun Microsystems, Inc. Factored assert chains
CN103136095A (zh) * 2011-11-28 2013-06-05 阿里巴巴集团控股有限公司 一种测试应用程序接口的方法、装置及系统
CN104484269A (zh) * 2014-11-27 2015-04-01 北京广利核系统工程有限公司 一种自动生成测试脚本的方法
CN106886390A (zh) * 2015-12-15 2017-06-23 大唐软件技术股份有限公司 一种Java对象生成和转换方法和Java对象生成和转换装置
CN107483283A (zh) * 2017-06-28 2017-12-15 珠海格力电器股份有限公司 通讯可靠性测试方法和装置

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
HIGHTOWER R., ET AL.: "Professional Java tools for Extreme Programming", 31 January 2004, WROX PRESS, ISBN: 0764556177, article "Java tools for Extreme Programming", pages: 139 - 143 *

Also Published As

Publication number Publication date
CN108536583B (zh) 2021-03-16
CN108536583A (zh) 2018-09-14

Similar Documents

Publication Publication Date Title
CN110162296B (zh) 应用程序编程接口文档的生成方法、装置及终端设备
US10169034B2 (en) Verification of backward compatibility of software components
US8887135B2 (en) Generating test cases for functional testing of a software application
US8136031B2 (en) Comparing the content of tables containing merged or split cells
US8499006B2 (en) Data migration system and data migration method
US10394756B2 (en) System and method for customizing archive of a device driver generator tool for a user
US7469408B2 (en) Document customization for transparent execution on a client and a server
US8156459B1 (en) Detecting differences between high level block diagram models
US9547486B2 (en) Creating a virtual resource package
US20150242389A1 (en) Techniques to identify user interface elements associated with model violation events
WO2014164231A2 (en) Executable guidance experiences based on implicitly generated guidance models
CN114048415A (zh) 表单生成方法及装置、电子设备和计算机可读存储介质
WO2019169720A1 (zh) 自动化测试的断言方法、装置、计算机设备及存储介质
US10606569B2 (en) Declarative configuration elements
US20130325842A1 (en) Computer-readable storage medium storing update program, update method, and update device
US11740878B1 (en) Creating CLI packages and API playbooks from codified graphical user experience designs
US7856344B2 (en) Method for transforming overlapping paths in a logical model to their physical equivalent based on transformation rules and limited traceability
US11861329B2 (en) Method and apparatus for codifying user experience designs and managing the codified user experience designs
US10169316B2 (en) Method and system to convert document source data to XML via annotation
US8924924B2 (en) Representing the structure of a data format using a class-based representation
CN105868113B (zh) 字符串查找方法及装置
CN114253536A (zh) 界面设计组件的调用方法、终端设备以及可读存储介质
US7149995B2 (en) Graphical interface to layout processing components and connections
US11989541B2 (en) Deployment migration tool with decoding capabilities
CN114239529B (zh) 基于模板引擎的文档生成方法、装置、设备及介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 18909122

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 08.12.2020)

122 Ep: pct application non-entry in european phase

Ref document number: 18909122

Country of ref document: EP

Kind code of ref document: A1