CN111008147B - Application program testing method, terminal and computer readable storage medium - Google Patents
Application program testing method, terminal and computer readable storage medium Download PDFInfo
- Publication number
- CN111008147B CN111008147B CN201911333810.8A CN201911333810A CN111008147B CN 111008147 B CN111008147 B CN 111008147B CN 201911333810 A CN201911333810 A CN 201911333810A CN 111008147 B CN111008147 B CN 111008147B
- Authority
- CN
- China
- Prior art keywords
- assertion
- program
- tested
- test
- testing method
- 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
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Prevention of errors by analysis, debugging or testing of software
- G06F11/3668—Testing of software
- G06F11/3672—Test management
- G06F11/3684—Test management for test design, e.g. generating new test cases
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Prevention of errors by analysis, debugging or testing of software
- G06F11/3668—Testing of software
- G06F11/3672—Test management
- G06F11/3688—Test management for test execution, e.g. scheduling of test suites
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Computer Hardware Design (AREA)
- Quality & Reliability (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Debugging And Monitoring (AREA)
Abstract
Description
技术领域Technical field
本发明涉及测试技术领域,尤其涉及一种应用程序的测试方法、终端及计算机可读存储介质。The present invention relates to the field of testing technology, and in particular, to an application testing method, a terminal and a computer-readable storage medium.
背景技术Background technique
衡量自动化测试用例质量的基本标准是自动化测试用例是否存在断言。单元测试通常包括断言验证,即:对被测代码的返回值进行验证,从而判定被测代码是否正确。所谓断言,是指编写代码时,程序员做出的一些假设,断言就是用于在代码中捕捉这些假设,因此可以将断言看作是异常处理的一种高级形式。The basic criterion for measuring the quality of automated test cases is whether there are assertions in the automated test cases. Unit testing usually includes assertion verification, that is, verifying the return value of the code under test to determine whether the code under test is correct. The so-called assertions refer to some assumptions made by programmers when writing code. Assertions are used to capture these assumptions in the code, so assertions can be regarded as an advanced form of exception handling.
目前,在互联网行业中,程序员经常选择不写断言,而直接把返回值打印出来的情况非常常见。在一个大型软件中,大部分的单元测试都没有做到完整的断言而导致部分程序缺陷无法被检测出来,甚至有上千个单元测试用例由于没有断言从而严重地影响自动化测试用例的测试效果。Currently, in the Internet industry, it is very common for programmers to choose not to write assertions but to print the return value directly. In a large software, most unit tests do not make complete assertions, which results in some program defects not being detected. There are even thousands of unit test cases that have no assertions, which seriously affects the testing effect of automated test cases.
上述内容仅用于辅助理解本发明的技术方案,并不代表承认上述内容是现有技术。The above content is only used to assist in understanding the technical solution of the present invention, and does not represent an admission that the above content is prior art.
发明内容Contents of the invention
本发明的主要目的在于提供一种应用程序的测试方法、终端及计算机可读存储介质,旨在解决单元测试用例由于没有设置断言导致被测试程序无法被检测导致影响测试效果的问题。The main purpose of the present invention is to provide an application program testing method, a terminal and a computer-readable storage medium, aiming to solve the problem that the unit test case does not have an assertion set and the tested program cannot be detected, thus affecting the test effect.
为实现上述目的,本发明听过一种应用程序的测试方法,所属应用程序的测试方法的步骤包括:In order to achieve the above object, the present invention provides an application testing method. The steps of the application testing method include:
在检测到待测试程序的加载指令时,获取所述待测试程序的调用信息;When detecting the loading instruction of the program to be tested, obtain the calling information of the program to be tested;
在所述调用信息与预设的断言调用信息匹配时,将断言检测标识加载至所述调用信息对应的目标程序中;When the calling information matches the preset assertion calling information, load the assertion detection identification into the target program corresponding to the calling information;
根据所述调用信息以及所述断言检测标识生成测试报告。Generate a test report based on the calling information and the assertion detection identification.
可选地,根据所述调用信息以及所述断言检测标识生成测试报告的步骤之前,包括:Optionally, before the step of generating a test report according to the call information and the assertion detection identification, the step includes:
执行待测试程序;Execute the program to be tested;
在获取到所述目标程序的执行结果的返回值时,将所述断言检测标识设置为断言已执行;或者When the return value of the execution result of the target program is obtained, the assertion detection flag is set to assertion executed; or
在未获取到所述目标程序的执行结果的返回值时,将所述断言检测标识设置为断言未执行。When the return value of the execution result of the target program is not obtained, the assertion detection flag is set to assertion not executed.
可选地,在获取到所述目标程序的执行结果的返回值时,将所述断言检测标识设置为断言已执行的步骤包括:Optionally, when the return value of the execution result of the target program is obtained, the step of setting the assertion detection flag to assertion executed includes:
在获取到所述目标程序的执行结果的返回值时,对比所述目标程序的执行结果的返回值与预设的期待值;When obtaining the return value of the execution result of the target program, compare the return value of the execution result of the target program with a preset expected value;
在所述返回值与预设的期待值匹配时,输出满足测试要求的提示信息;When the return value matches the preset expected value, a prompt message that meets the test requirements is output;
将所述断言检测标识设置为断言已执行。The assertion detection flag is set to assertion executed.
可选地,根据所述调用信息以及所述断言检测标识生成测试报告的步骤包括:Optionally, the step of generating a test report based on the call information and the assertion detection identification includes:
根据所述调用信息、所述目标程序的执行结果以及所述断言检测标识生成测试报告。Generate a test report based on the calling information, the execution result of the target program, and the assertion detection identification.
可选地,根据所述调用信息以及所述断言检测标识生成测试报告的步骤之后包括:Optionally, the step of generating a test report based on the call information and the assertion detection identification includes:
输出所述测试报告。Output the test report.
可选地,预设的断言调用信息包括默认的断言调用信息以及自定义的断言调用信息。Optionally, the preset assertion calling information includes default assertion calling information and customized assertion calling information.
此外,为实现上述目的,本发明还提供一种终端,终端包括:存储器、处理器以及存储在所述存储器里并可在所述处理器上运行的应用程序的测试程序,所述应用程序的测试程序被所述处理器执行时实现上述应用程序的测试方法的步骤。In addition, to achieve the above object, the present invention also provides a terminal. The terminal includes: a memory, a processor, and a test program of an application program stored in the memory and capable of running on the processor. The application program has When the test program is executed by the processor, the steps of the test method of the above-mentioned application program are implemented.
此外,为实现上述目的,本发明还提供一种计算机可读存储介质,计算机可读存储介质存储有应用程序的测试程序,所述应用程序的测试程序被处理器执行时实现上述应用程序的测试方法的步骤。In addition, in order to achieve the above object, the present invention also provides a computer-readable storage medium. The computer-readable storage medium stores a test program of the application program. When the test program of the application program is executed by the processor, the test of the above-mentioned application program is realized. Method steps.
本发明提出的应用程序的测试方法,通过获取待测试程序的调用信息,在调用信息与预设的断言调用信息匹配时,也即对待测试程序中的断言进行定位以确定断言所在的目标程序,将断言检测标识加入目标程序以对断言进行标记,通过查看待测试程序的调用信息以及断言检测标识生成的测试报告,可便于测试人员一目了然知道待测试程序是否设置断言以便评估待测试程序的测试效果,提高待测试程序的测试质量。The application testing method proposed by the present invention obtains the calling information of the program to be tested, and when the calling information matches the preset assertion calling information, that is, the assertion in the program to be tested is located to determine the target program where the assertion is located. Add the assertion detection flag to the target program to mark assertions. By viewing the call information of the program under test and the test report generated by the assertion detection flag, the tester can easily know at a glance whether the program under test sets assertions so as to evaluate the testing effect of the program under test. , improve the testing quality of the program to be tested.
附图说明Description of drawings
图1是为实现本发明各个实施例的一种终端的硬件结构示意图;Figure 1 is a schematic diagram of the hardware structure of a terminal for implementing various embodiments of the present invention;
图2为本发明的应用程序的测试方法第一实施例的流程示意图;Figure 2 is a schematic flow chart of the first embodiment of the application testing method of the present invention;
图3为本发明的应用程序的测试方法第二实施例的流程示意图;Figure 3 is a schematic flow chart of a second embodiment of the application testing method of the present invention;
图4为本发明的应用程序的测试方法第三实施例的流程示意图。FIG. 4 is a schematic flowchart of a third embodiment of the application testing method of the present invention.
本发明目的的实现、功能特点及优点将结合实施例,参照附图做进一步说明。The realization of the purpose, functional features and advantages of the present invention will be further described with reference to the embodiments and the accompanying drawings.
具体实施方式Detailed ways
应当理解,此处所描述的具体实施例仅仅用以解释本发明,并不用于限定本发明。It should be understood that the specific embodiments described here are only used to explain the present invention and are not intended to limit the present invention.
在后续的描述中,使用用于表示元件的诸如“模块”、“部件”或者“单元”的后缀仅为了有利于本发明的说明,其本身没有特定的意义。因此,“模块”、“部件”或者“单元”可以混合地使用。In the following description, suffixes such as "module", "component" or "unit" used to represent elements are only used to facilitate the description of the present invention and have no specific meaning in themselves. Therefore, "module", "component" or "unit" may be used interchangeably.
终端可以以各种形式来实施。例如,本发明中描述的终端设备可以包括诸如手机、平板电脑、笔记本电脑以及掌上电脑等终端。Terminals can be implemented in various forms. For example, the terminal devices described in the present invention may include terminals such as mobile phones, tablet computers, notebook computers, and PDAs.
本领域技术人员将理解的是,除了特别用于移动目的元件之外,根据本发明的实施方式的构造也能够应用于固定类型的终端。Those skilled in the art will understand that, in addition to being specifically used for mobile-purpose elements, the construction according to embodiments of the present invention can also be applied to fixed-type terminals.
请参阅图1,其为实现本发明各个实施例的一种终端的硬件结构示意图,该终端可以包括:存储器101、处理器102以及显示单元103。本领域技术人员可以理解,图1示出的终端结构并不构成对移动终端的限定,终端可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置。Please refer to FIG. 1 , which is a schematic diagram of the hardware structure of a terminal that implements various embodiments of the present invention. The terminal may include: a memory 101, a processor 102, and a display unit 103. Those skilled in the art can understand that the terminal structure shown in Figure 1 does not constitute a limitation on the mobile terminal. The terminal may include more or fewer components than shown in the figure, or combine certain components, or arrange different components.
其中,存储器101中存储有中控系统以及应用程序的测试程序。处理器102是终端的控制中心,处理器102执行存储在存储器101的内的应用程序的测试程序程序,以实现本发明的应用程序的测试方法各实施例的步骤。Among them, the memory 101 stores test programs of the central control system and application programs. The processor 102 is the control center of the terminal. The processor 102 executes the application testing program stored in the memory 101 to implement the steps of each embodiment of the application testing method of the present invention.
显示单元103包括显示面板,可采用液晶显示器(Liquid Crystal Display,LCD)、有机发光二极管(Organic Light-Emitting Diode,OLED)等形式来配置显示面板,用于输出显示应用程序的测试程序被处理器102执行后的测试结果。The display unit 103 includes a display panel, which can be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), etc., and is used to output the test program of the display application to be processed. 102 Test results after execution.
本发明提供一种应用程序的测试方法,请参考图2,图2为本发明的应用程序的测试方法第一实施例的流程示意图。该实施例中,应用程序的测试方法包括以下步骤:The present invention provides a method for testing an application program. Please refer to FIG. 2 . FIG. 2 is a schematic flow chart of a first embodiment of the method for testing an application program according to the present invention. In this embodiment, the application testing method includes the following steps:
步骤S10,在检测到待测试程序的加载指令时,获取所述待测试程序的调用信息;Step S10: When the loading instruction of the program to be tested is detected, the calling information of the program to be tested is obtained;
衡量自动化测试用例质量的基本标准是自动化测试用例是否存在断言,单元测试程序通常包括断言验证,其中,单元测试程序是指对软件中的最小可测试单元进行检查和验证的测试程序,例如:以JAVA语言开发的程序为例,方法、函数等为最小可测试单元。需要说明的是,待测试程序为自动化测试项目中的测试用例,测试人员可根据根据测试用例来确定应用软件或软件系统是否正确工作。调用信息为待测试程序的执行调用路径信息,执行调用路径信息包括调用类名及调用函数名。获取待测试程序的调用信息可通过获取待测试程序的MAP文件,其中,MAP文件用以保存程序全局符号、源文件和代码行号等信息,其中包括函数地址与函数名之间的映射关系,可基于MAP文件获得待测试程序运行过程中调用的函数的函数名。The basic criterion for measuring the quality of automated test cases is whether there are assertions in the automated test cases. Unit test procedures usually include assertion verification, where unit test procedures refer to test procedures that check and verify the smallest testable unit in the software, for example: Take a program developed in JAVA language as an example. Methods, functions, etc. are the smallest testable units. It should be noted that the program to be tested is the test case in the automated test project, and the tester can determine whether the application software or software system is working correctly based on the test case. The calling information is the execution calling path information of the program to be tested, and the execution calling path information includes the calling class name and the calling function name. The calling information of the program under test can be obtained by obtaining the MAP file of the program under test. The MAP file is used to save information such as program global symbols, source files, and code line numbers, including the mapping relationship between function addresses and function names. The function name of the function called during the running of the program under test can be obtained based on the MAP file.
步骤S20,在所述调用信息与预设的断言调用信息匹配时,将断言检测标识加载至所述调用信息对应的目标程序中;Step S20: When the calling information matches the preset assertion calling information, load the assertion detection identification into the target program corresponding to the calling information;
步骤S30,根据所述调用信息以及所述断言检测标识生成测试报告。Step S30: Generate a test report based on the calling information and the assertion detection identification.
需要说明的是,预设的断言调用信息包括默认的断言调用信息以及自定义的断言调用信息。其中,自定义的断言调用信息可由用户预先通过配置文件按需进行配置。可以理解的是,预设的断言调用信息可以存储在断言检测装置能够获取的任何设备中,设备既可以是服务器,也可以是开发人员的客户端设备。由于自动化测试项目中的待测试程序也即测试用例有多组或者多个,预设的断言调用信息为一断言调用路径信息集合。待测试程序的调用信息与预设的断言调用信息是否匹配,即通过待测试程序的执行调用路径信息与预设的断言调用路径信息的匹配结果获得,可以理解的是,当匹配结果为匹配时,则表明待测试程序中设置有断言验证方法,实现对待测试程序中的断言进行定位确定断言所在的目标程序,进而将断言检测标识加载至目标程序以对待测试程序中是否存在断言进行标记,其中,断言检测标识可以是注解标识;也可以是埋点,埋点通过AssertionClassTransformer类实现,将断言检测标识加载至目标程序可通过API提供的transform接口在待测试程序编译前将断言检测标识加载至待测试程序中,以标记待测试程序中的断言。It should be noted that the preset assertion calling information includes default assertion calling information and customized assertion calling information. Among them, the customized assertion calling information can be configured by the user in advance through the configuration file as needed. It can be understood that the preset assertion calling information can be stored in any device that the assertion detection device can obtain, and the device can be either a server or a developer's client device. Since there are multiple groups or multiple test cases of the program to be tested in the automated test project, the preset assertion calling information is a set of assertion calling path information. Whether the calling information of the program under test matches the preset assertion calling information is obtained by the matching result of the execution calling path information of the program under test and the preset assertion calling path information. It can be understood that when the matching result is a match , it indicates that there is an assertion verification method in the program to be tested, which can locate the assertion in the program to be tested and determine the target program where the assertion is located, and then load the assertion detection identifier into the target program to mark whether there is an assertion in the program to be tested, where , the assertion detection identifier can be an annotation identifier; it can also be a buried point, which is implemented through the AssertionClassTransformer class. The assertion detection identifier can be loaded into the target program through the transform interface provided by the API before the program to be tested is compiled. In the test program, to mark the assertions in the program under test.
根据所述调用信息以及所述断言检测标识生成测试报告可通过预设的测试报告格式,将调用信息以及断言检测标识分别对应输出至与预设的测试报告格式相关联的区域;也可以直接关联保存调用信息以及断言检测标识后间接导出数据表格形式生成测试报告,可以理解的是,测试报告可以是电子形式也可以是纸质形式,本实施例对此步骤的具体实现不做限定。可选地,生成测试报告后输出测试报告,可通过直接输出至断言检测装置的显示屏;也可根据配置文件获取目标服务器的地址,将测试报告上传至服务器,本实施例对此步骤的具体实现不做限定。Generating a test report based on the calling information and the assertion detection identification can use a preset test report format, and the calling information and assertion detection identification can be output to the area associated with the preset test report format respectively; it can also be directly associated After saving the call information and assertion detection identification, the data is indirectly exported in table form to generate a test report. It can be understood that the test report can be in electronic form or in paper form. This embodiment does not limit the specific implementation of this step. Optionally, after generating the test report, the test report can be output directly to the display screen of the assertion detection device; the address of the target server can also be obtained according to the configuration file, and the test report can be uploaded to the server. This embodiment is specific to this step. The implementation is not limited.
本实施例公开的技术方案中,通过获取待测试程序的调用信息,在调用信息与预设的断言调用信息匹配时,也即对待测试程序中的断言进行定位以确定断言所在的目标程序,将断言检测标识加入目标程序以对断言进行标记,通过查看待测试程序的调用信息以及断言检测标识生成的测试报告,可便于测试人员一目了然知道待测试程序是否设置断言以便评估待测试程序的测试效果,提高待测试程序的测试质量。In the technical solution disclosed in this embodiment, by obtaining the calling information of the program to be tested, when the calling information matches the preset assertion calling information, that is, the assertion in the program to be tested is located to determine the target program where the assertion is located. The assertion detection flag is added to the target program to mark assertions. By viewing the call information of the program under test and the test report generated by the assertion detection flag, the tester can easily know at a glance whether the program under test sets assertions in order to evaluate the testing effect of the program under test. Improve the testing quality of programs under test.
基于上述实施例提出本发明的第二实施例,请参考图3,图3为本发明的应用程序的测试方法第二实施例的流程示意图。该实施例中,步骤S30之前包括:Based on the above embodiments, a second embodiment of the present invention is proposed. Please refer to FIG. 3 . FIG. 3 is a schematic flow chart of a second embodiment of an application testing method of the present invention. In this embodiment, step S30 includes:
步骤S40,执行待测试程序;Step S40, execute the program to be tested;
步骤S50,在获取到所述目标程序的执行结果的返回值时,将所述断言检测标识设置为断言已执行;或者Step S50: When obtaining the return value of the execution result of the target program, set the assertion detection flag to assertion executed; or
步骤S60,在未获取到所述目标程序的执行结果的返回值时,将所述断言检测标识设置为断言未执行。Step S60: When the return value of the execution result of the target program is not obtained, the assertion detection flag is set to assertion not executed.
被测程序的执行结果的返回值,可以是基本类型的返回值,例如:布尔型、字符型、字节或整型等,也可以是扩展类型的返回值,即:返回值是一个对象。在实际的应用过程中,待测试程序中即便设置有断言验证,却无法知道待测试程序的实际执行过程中,执行待测试程序的调用信息即待测试程序的执行调用信息是否有执行断言。前期通过对待测试程序中的断言进行定位确定断言所在的目标程序,将断言检测标识加载至目标程序后,在执行待测试程序时,根据是否接收到断言所在的目标程序的执行结果的返回值以判断断言验证是否被执行。可以理解的是,在接收到返回值时,则表明断言被调用执行,通过将断言检测标识设置为断言已执行以标记待测试程序中有执行断言;在未接收到返回值时,则表明断言未被调用执行,通过将断言检测标识设置为断言未执行以标记待测试程序中未执行断言,其中,断言检测标识可通过设置“ture”表示断言已执行,如可通过AssertionHolder.setTrue方法予以实现,可通过设置“false”表示断言未执行。The return value of the execution result of the program under test can be a return value of a basic type, such as Boolean, character, byte or integer, etc., or a return value of an extended type, that is, the return value is an object. In the actual application process, even if the program under test is set with assertion verification, it is impossible to know whether the call information of the program under test, that is, the execution call information of the program under test, has execution assertions during the actual execution of the program under test. In the early stage, the assertion in the program to be tested is determined to determine the target program where the assertion is located. After the assertion detection flag is loaded into the target program, when the program to be tested is executed, the return value of the execution result of the target program where the assertion is located is received based on whether Determine whether assertion verification has been performed. It can be understood that when a return value is received, it indicates that the assertion has been called and executed. By setting the assertion detection flag to Assertion Executed to mark that there is an execution assertion in the program under test; when a return value is not received, it indicates that the assertion If the assertion has not been executed, set the assertion detection flag to Assertion Not Executed to mark that the assertion has not been executed in the program to be tested. The assertion detection flag can be set to "true" to indicate that the assertion has been executed. For example, it can be implemented through the AssertionHolder.setTrue method. , you can set "false" to indicate that the assertion is not executed.
步骤S30步骤包括:步骤S31,根据所述调用信息、所述目标程序的执行结果以及所述断言检测标识生成测试报告。将调用信息、目标程序的执行结果以及断言检测标识分别对应输出至与预设的测试报告格式相关联的区域;也可以直接关联保存调用信息、目标程序的执行结果以及断言检测标识后间接导出数据表格形式生成测试报告,可以理解的是,测试报告可以是电子形式也可以是纸质形式,本实施例对此步骤的具体实现不做限定。可选地,生成测试报告后输出测试报告,可通过直接输出至断言检测装置的显示屏;也可根据配置文件获取目标服务器的地址,将测试报告上传至服务器,本实施例对此步骤的具体实现不做限定。Step S30 includes: step S31, generating a test report based on the call information, the execution result of the target program, and the assertion detection identification. Output the call information, target program execution results, and assertion detection identifiers to the area associated with the preset test report format respectively; you can also directly save the call information, target program execution results, and assertion detection identifiers and then export the data indirectly. The test report is generated in tabular form. It can be understood that the test report can be in electronic form or paper form. This embodiment does not limit the specific implementation of this step. Optionally, after generating the test report, the test report can be output directly to the display screen of the assertion detection device; the address of the target server can also be obtained according to the configuration file, and the test report can be uploaded to the server. This embodiment is specific to this step. The implementation is not limited.
本实施例公开的技术方案中,在执行待测试程序后,通过获取所述目标程序的执行结果的返回值来判断待测试程序中的断言是否被调用执行,在获取到目标程序的执行结果的返回值时,也即待测试程序中的断言被调用执行时,设置断言检测标识为断言已执行以标记断言被调用执行,可以理解的是,在未获取到目标程序的执行结果的返回值时,设置断言检测标识为断言未执行以标记断言未被调用执行,如此,在待测试程序中设置了断言的基础上,可以检测出待测试程序中的断言是否被调用执行,最后通过查看生成的测试报告,便于测试人员发现待测试程序中不规范和缺断言情况,以进一步改进待测试程序,提高待测试程序的测试效果。In the technical solution disclosed in this embodiment, after the program to be tested is executed, whether the assertion in the program to be tested is called and executed is determined by obtaining the return value of the execution result of the target program. After obtaining the execution result of the target program, When returning a value, that is, when the assertion in the program under test is called and executed, set the assertion detection flag to Assertion Executed to mark the assertion as being called and executed. It is understandable that when the return value of the execution result of the target program is not obtained , set the assertion detection flag to assertion not executed to mark that the assertion has not been called and executed. In this way, based on the assertion being set in the program to be tested, it can be detected whether the assertion in the program to be tested has been called and executed. Finally, by viewing the generated Test reports allow testers to discover irregularities and missing assertions in the program to be tested, so as to further improve the program to be tested and improve the testing effect of the program to be tested.
基于上述任一实施例提出本发明的第三实施例,请参考图4,图4为本发明的应用程序的测试方法第三实施例的流程示意图。该实施例中,步骤S50包括:A third embodiment of the present invention is proposed based on any of the above embodiments. Please refer to FIG. 4 , which is a schematic flow chart of a third embodiment of an application testing method of the present invention. In this embodiment, step S50 includes:
步骤S51,在获取到所述目标程序的执行结果的返回值时,对比所述目标程序的执行结果的返回值与预设的期待值;Step S51: When obtaining the return value of the execution result of the target program, compare the return value of the execution result of the target program with a preset expected value;
步骤S52,在所述返回值与预设的期待值匹配时,输出满足测试要求的提示信息;Step S52: When the return value matches the preset expected value, output prompt information that meets the test requirements;
步骤S53,将所述断言检测标识设置为断言已执行。Step S53: Set the assertion detection flag to assertion executed.
需要说明的是,用于单元测试的断言验证方法基于的总体构思为采用自动化的方法,预先自动获取并存储对应特定待测试程序及其特定参数值的期待值,将其作为断言验证处理时预设的期待值。由于预设的期待值可通过程序自动获取的,因此在进行断言验证处理时,能够避免人工编写断言验证语句导致的容易出错的问题,达到减少工作量的效果。可以理解的是,预设的期待值可以存储在断言验证装置能够获取的任何设备中,设备既可以是服务器,也可以是开发人员的客户端设备。在具体实施过程中,可以采取配置参数的方式指定期待值的存储位置,例如:可以在断言验证装置中设置一个存储位置选项。It should be noted that the overall concept of the assertion verification method for unit testing is to use an automated method to automatically obtain and store the expected values corresponding to the specific program to be tested and its specific parameter values in advance, and use them as predetermined values during assertion verification processing. set expected value. Since the preset expected value can be automatically obtained through the program, when performing assertion verification processing, error-prone problems caused by manually writing assertion verification statements can be avoided, thereby reducing the workload. It can be understood that the preset expected value can be stored in any device that the assertion verification device can obtain, and the device can be either a server or a developer's client device. In the specific implementation process, the storage location of the expected value can be specified in the form of configuration parameters. For example, a storage location option can be set in the assertion verification device.
在进行单元测试过程中,待测试程序可能出现错误导致抛出异常。因此,除了待测试程序正常运行时的普通返回值外,待测试程序的返回值可能存在异常。与错误不同的是,异常是程序本身可以处理的。程序可以根据捕获到的具体异常,进行相应的后续处理。同理地,在接收到待测试程序中的目标程序的执行结果的返回值后,通过对比返回值与预设的期待值可以获知目标程序是否正常执行,在返回值与预设的期待值匹配时,通过输出满足测试要求的提示信息可直接获知目标程序正常执行,并且将断言检测标识设置为断言已执行,可通过断言检测标识获取到测试程序中的目标程序是否被执行。During unit testing, errors may occur in the program to be tested, causing exceptions to be thrown. Therefore, in addition to the normal return value when the program under test runs normally, the return value of the program under test may have exceptions. Unlike errors, exceptions can be handled by the program itself. The program can perform corresponding subsequent processing based on the specific exception captured. Similarly, after receiving the return value of the execution result of the target program in the program to be tested, whether the target program is executed normally can be known by comparing the return value with the preset expected value. When the return value matches the preset expected value When, you can directly know that the target program is executed normally by outputting prompt information that meets the test requirements, and by setting the assertion detection flag to Assert Executed, you can use the assertion detection flag to obtain whether the target program in the test program has been executed.
本实施例公开的技术方案中,通过对比目标程序的执行结果的返回值与预设的期待值可获知目标程序是否正常执行,在返回值与预设的期待值匹配时,也即目标程序正常执行时且表明待测试程序中的目标程序的执行返回值符合测试要求,通过输出提示信息以便测试人员快速了解目标程序执行正常且符合测试要求。In the technical solution disclosed in this embodiment, by comparing the return value of the execution result of the target program with the preset expected value, it can be known whether the target program is executed normally. When the return value matches the preset expected value, that is, the target program is normal. When executed, it indicates that the execution return value of the target program in the program to be tested meets the test requirements. Prompt information is output so that the tester can quickly understand that the target program executes normally and meets the test requirements.
本发明还提供一种终端,终端包括:存储器、处理器以及存储在存储器并可在处理器上运行的应用程序的测试程序,应用程序的测试程序被处理器执行时实现上述任一实施例中的应用程序的测试方法的步骤。The present invention also provides a terminal. The terminal includes: a memory, a processor, and a test program of an application program stored in the memory and executable on the processor. When the test program of the application program is executed by the processor, any of the above embodiments can be realized. Steps of the application testing method.
本发明还提供一种计算机可读存储介质,计算机可读存储介质上存储有应用程序的测试程序,应用程序的测试程序被处理器执行时实现上述任一实施例中的应用程序的测试方法的步骤。The present invention also provides a computer-readable storage medium. The computer-readable storage medium stores a test program of an application program. When the test program of the application program is executed by the processor, the test method of the application program in any of the above embodiments is implemented. step.
在本发明提供的终端和计算机可读存储介质的实施例中,包含了上述应用程序的测试方法各实施例的全部技术特征,说明书拓展和解释内容与上述应用程序的测试方法的各实施例基本相同,在此不做赘述。The embodiments of the terminal and the computer-readable storage medium provided by the present invention include all the technical features of the above-mentioned embodiments of the application program testing method, and the expansion and explanation content of the description are basically the same as the above-mentioned embodiments of the application program testing method. They are the same and will not be described in detail here.
需要说明的是,在本文中,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者系统不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者系统所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、方法、物品或者系统中还存在另外的相同要素。It should be noted that, as used herein, the terms "include", "comprising" or any other variation thereof are intended to cover a non-exclusive inclusion, such that a process, method, article or system that includes a list of elements not only includes those elements, but It also includes other elements not expressly listed or that are inherent to the process, method, article or system. Without further limitation, an element defined by the statement "comprises a..." does not exclude the presence of other identical elements in the process, method, article, or system that includes that element.
上述本发明实施例序号仅仅为了描述,不代表实施例的优劣。The above serial numbers of the embodiments of the present invention are only for description and do not represent the advantages and disadvantages of the embodiments.
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在如上的一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端设备(可以是手机,计算机,服务器,被控终端,或者网络设备等)执行本发明每个实施例的方法。Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus the necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases the former is better. implementation. Based on this understanding, the technical solution of the present invention can be embodied in the form of a software product in essence or that contributes to the existing technology. The computer software product is stored in one of the above storage media (such as ROM/RAM, magnetic disc, optical disk), including several instructions to cause a terminal device (which can be a mobile phone, a computer, a server, a controlled terminal, or a network device, etc.) to execute the method of each embodiment of the present invention.
以上仅为本发明的优选实施例,并非因此限制本发明的专利范围,凡是利用本发明说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其他相关的技术领域,均同理包括在本发明的专利保护范围内。The above are only preferred embodiments of the present invention, and do not limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the description and drawings of the present invention may be directly or indirectly used in other related technical fields. , are all similarly included in the scope of patent protection of the present invention.
Claims (8)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201911333810.8A CN111008147B (en) | 2019-12-20 | 2019-12-20 | Application program testing method, terminal and computer readable storage medium |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201911333810.8A CN111008147B (en) | 2019-12-20 | 2019-12-20 | Application program testing method, terminal and computer readable storage medium |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN111008147A CN111008147A (en) | 2020-04-14 |
| CN111008147B true CN111008147B (en) | 2023-12-26 |
Family
ID=70116780
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201911333810.8A Active CN111008147B (en) | 2019-12-20 | 2019-12-20 | Application program testing method, terminal and computer readable storage medium |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN111008147B (en) |
Families Citing this family (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN112116439A (en) * | 2020-08-10 | 2020-12-22 | 杭州优行科技有限公司 | Clearing and settlement testing method, device, terminal and storage medium |
| CN112882948A (en) * | 2021-03-15 | 2021-06-01 | 数字广东网络建设有限公司 | Stability testing method, device and system for application and storage medium |
Citations (6)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US8127275B1 (en) * | 2007-04-18 | 2012-02-28 | Parasoft Corporation | System and method for recording the state of variables and objects when running unit tests |
| CN102609352A (en) * | 2011-01-19 | 2012-07-25 | 阿里巴巴集团控股有限公司 | Parallel testing method and parallel testing server |
| CN105760292A (en) * | 2014-12-18 | 2016-07-13 | 阿里巴巴集团控股有限公司 | Assertion verification method and device for unit testing |
| CN110427188A (en) * | 2019-08-02 | 2019-11-08 | 深圳前海微众银行股份有限公司 | It is single to survey configuration method, device, equipment and the storage medium for asserting program |
| CN110532185A (en) * | 2019-08-29 | 2019-12-03 | 中国工商银行股份有限公司 | Test method, device, electronic equipment and computer readable storage medium |
| CN110569194A (en) * | 2019-09-09 | 2019-12-13 | 五八有限公司 | interface testing method and device, electronic equipment and storage medium |
-
2019
- 2019-12-20 CN CN201911333810.8A patent/CN111008147B/en active Active
Patent Citations (6)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US8127275B1 (en) * | 2007-04-18 | 2012-02-28 | Parasoft Corporation | System and method for recording the state of variables and objects when running unit tests |
| CN102609352A (en) * | 2011-01-19 | 2012-07-25 | 阿里巴巴集团控股有限公司 | Parallel testing method and parallel testing server |
| CN105760292A (en) * | 2014-12-18 | 2016-07-13 | 阿里巴巴集团控股有限公司 | Assertion verification method and device for unit testing |
| CN110427188A (en) * | 2019-08-02 | 2019-11-08 | 深圳前海微众银行股份有限公司 | It is single to survey configuration method, device, equipment and the storage medium for asserting program |
| CN110532185A (en) * | 2019-08-29 | 2019-12-03 | 中国工商银行股份有限公司 | Test method, device, electronic equipment and computer readable storage medium |
| CN110569194A (en) * | 2019-09-09 | 2019-12-13 | 五八有限公司 | interface testing method and device, electronic equipment and storage medium |
Also Published As
| Publication number | Publication date |
|---|---|
| CN111008147A (en) | 2020-04-14 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US8397104B2 (en) | Creation of test plans | |
| CN112052169A (en) | Test management method, system, device, and computer-readable storage medium | |
| WO2019161619A1 (en) | Automatic interface test method and apparatus, and device and computer-readable storage medium | |
| CN111008147B (en) | Application program testing method, terminal and computer readable storage medium | |
| CN104915297A (en) | APP electricity consumption automatic test method for android device | |
| CN112612706A (en) | Automated testing method, computer device and storage medium | |
| CN110267215B (en) | Data detection method, equipment and storage medium | |
| CN110413522A (en) | A method, device, storage medium and electronic device for determining a test database | |
| CA2811617C (en) | Commit sensitive tests | |
| CN108829575B (en) | Test case recommendation method, electronic device and readable storage medium | |
| CN114218072A (en) | Test script generation method and device, storage medium and computer equipment | |
| CN107391087A (en) | A kind of method and device of hardware information read-write | |
| CN110795341A (en) | A kind of automatic testing method, system and device of server | |
| CN113918384A (en) | Data storage method, device, equipment and storage medium | |
| CN109446105A (en) | Web application test method, device, readable medium and electronic equipment | |
| CN116860608A (en) | An interface testing method, device, computing equipment and storage medium | |
| CN112015658B (en) | A method and device for generating software integration test cases | |
| CN116541847A (en) | Security detection method and device for application program | |
| CN115599683A (en) | Automatic testing method, device, equipment and storage medium | |
| CN116820915A (en) | A code detection method, device and electronic equipment | |
| CN114942887A (en) | Program safety testing method, device, equipment and medium | |
| CN112559370A (en) | Front-end-based React project unit testing method and related equipment | |
| CN112346994A (en) | Test information correlation method and device, computer equipment and storage medium | |
| CN119512938B (en) | Software suitability test method and device, electronic equipment and storage medium | |
| CN117234949B (en) | Test data noise reduction method and device, storage medium and computer equipment |
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 |