WO2020232906A1 - 代码有效性测试方法、计算设备及存储介质 - Google Patents

代码有效性测试方法、计算设备及存储介质 Download PDF

Info

Publication number
WO2020232906A1
WO2020232906A1 PCT/CN2019/103760 CN2019103760W WO2020232906A1 WO 2020232906 A1 WO2020232906 A1 WO 2020232906A1 CN 2019103760 W CN2019103760 W CN 2019103760W WO 2020232906 A1 WO2020232906 A1 WO 2020232906A1
Authority
WO
WIPO (PCT)
Prior art keywords
code
validity test
content
validity
feature
Prior art date
Application number
PCT/CN2019/103760
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 WO2020232906A1 publication Critical patent/WO2020232906A1/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
    • 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

Definitions

  • This application belongs to the field of computer technology, and in particular relates to a method for testing code validity, a computing device, and a storage medium.
  • Unit Testing refers to the detection and verification of the smallest testable unit in the software.
  • the smallest testable unit can be a module, a function, or a class in the software.
  • Code coverage is a consideration factor in software testing to describe the proportion or extent of the code in the software code being tested. Code coverage is often used as a measure of software testing capabilities, and even used to assess the completion of software testing tasks. Existing code coverage statistics tools such as Jacoco can be used to test and collect code coverage for the code that needs to be tested, and evaluate the completion of the test work based on the code coverage.
  • the purpose of this application is to provide a code validity test method, computing device and storage medium, which aims to solve the problems existing in the prior art.
  • this application provides a code validity test method, including:
  • the unit test UT code contained in the source code is detected whether there is content that matches the validity test feature, and the validity test result is obtained.
  • the validity test feature is: an assertion keyword or an expression containing the assertion keyword
  • the validity test rule also includes a UT code feature
  • the detection source is based on the validity test rule containing the validity test feature
  • the unit test UT code contained in the code contains content that matches the validity test feature, including:
  • the validity test result correspondingly indicates that the UT code has a valid assertion
  • the validity test result correspondingly indicates that no valid assertion is written in the UT code.
  • UT code features are UT function keywords or expressions containing UT function keywords.
  • the validity test rule further includes a code experience framework for indicating the logical composition of the source code, and the code experience framework includes experience UT code position indication information,
  • the unit test UT code contained in the source code is checked for content that matches the validity test feature, which specifically includes:
  • the validity test result indicates the empirical UT code position indication information
  • the UT code corresponding to the indicated position is written with a valid assertion.
  • the empirical UT code position indication information indicates To prompt the developer to confirm the problem and/or fix the code.
  • the method further includes:
  • the validity test result contains the location information of the content, or
  • the validity test result includes: a description of the situation where the content is similar to the validity test feature, and/or , A suggestion to modify the content according to the validity test feature, or,
  • the content is automatically modified according to the validity test feature, and the developer is prompted for the modification.
  • this application also provides a code validity testing method, including:
  • the validity test rule including the validity test feature, detect whether there is content matching the validity test feature in the UT code included in the incremental content, and obtain the incremental validity test result;
  • the previous validity test result is combined with the incremental validity test result to obtain the current validity test result of the current version of the source code.
  • the validity test rule also includes a first code experience frame and a second code experience frame, there is a frame difference content between the first code experience frame and the second code experience frame, and the frame difference
  • the content contains the position indication information of the experience UT code
  • the validity test rule containing the validity test feature detecting whether there is content matching the validity test feature in the UT code included in the incremental content, which specifically includes:
  • the experience UT code location indication information indicates Whether the validity test feature exists in the UT code corresponding to the position of
  • the validity test feature exists in the UT code corresponding to the position indicated by the empirical UT code position indication information, then when the previous validity test result indicates the UT of the previous version source code When the code passes the validity test, the current validity test result indicates that the current version of the source code passes the validity test.
  • this application provides a computing device including a memory and a processor, and the processor implements the following steps when executing the computer instructions stored in the memory:
  • the unit test UT code contained in the source code is detected whether there is content that matches the validity test feature, and the validity test result is obtained.
  • this application provides a computing device including a memory and a processor, and the processor implements the following steps when executing the computer instructions stored in the memory:
  • the validity test rule including the validity test feature, detect whether there is content matching the validity test feature in the UT code included in the incremental content, and obtain the incremental validity test result;
  • the previous validity test result is combined with the incremental validity test result to obtain the current validity test result of the current version of the source code.
  • the present application provides one or more readable storage media storing computer readable instructions, the computer readable storage medium storing computer readable instructions, and the computer readable instructions are executed by one or more processors When executed, the one or more processors are caused to execute the following steps:
  • the unit test UT code contained in the source code is detected whether there is content that matches the validity test feature, and the validity test result is obtained.
  • the present application provides one or more readable storage media storing computer readable instructions, the computer readable storage medium storing computer readable instructions, and the computer readable instructions are executed by one or more processors When executed, the one or more processors are caused to execute the following steps:
  • the validity test rule including the validity test feature, detect whether there is content matching the validity test feature in the UT code included in the incremental content, and obtain the incremental validity test result;
  • the previous validity test result is combined with the incremental validity test result to obtain the current validity test result of the current version of the source code.
  • FIG. 1 is an implementation flow chart of the code validity testing method provided in Embodiment 2 of the present application.
  • Figure 2 is a schematic diagram of the logical composition of the source code in the third embodiment of the application.
  • FIG. 3 is a partial flowchart of the code validity testing method provided by Embodiment 3 of the present application.
  • FIG. 4 is a partial flowchart of the code validity testing method provided by the fourth embodiment of the present application.
  • FIG. 5 is an implementation flowchart of the code validity testing method provided by Embodiment 5 of the present application.
  • FIG. 6 is a partial flowchart of the code validity testing method provided by Embodiment 6 of the present application.
  • FIG. 7 is a schematic structural diagram of a computing device provided by Embodiment 7 of the present application.
  • the code validity test method proposed in the embodiment of the application mainly determines whether the UT code contained in the source code to be tested contains the validity test feature, especially when the current UT code must use the assertion function. Whether to include valid assertions for testing, so as to achieve the purpose of testing the validity of the code.
  • This embodiment provides a code validity test method, which mainly includes:
  • the source code with UT code is traversed to determine whether there is content in the UT code that matches the validity test feature, and the validity test result is obtained.
  • a validity test rule can be established in advance, and the validity test rule can be used to test the validity of the source code to be tested.
  • the source code is a code file written by the developer in the language supported by the development tool, and a series of computer language instructions are composed of corresponding characters, symbols, or signal symbols.
  • the source code generally realizes a complete system function, and the smallest testable unit such as the class, module or function that composes the source code realizes the basic function of the system function.
  • UT code is usually loaded into the source code to achieve the purpose of the inspection.
  • UT code usually necessarily contains assertion functions, and it usually contains test cases. Whether it contains valid assertions, whether test cases cover commonly used input combinations or boundary conditions, etc., usually become the test criteria for code validity. Among them, especially whether to include valid assertions as an important test standard for code validity.
  • the validity test feature can be assertion keywords or expressions containing assertion keywords, etc. If there are no assertion keywords or expressions containing assertion keywords in the UT code, it can be considered The UT code has no valid assertion and cannot pass the validity test.
  • UT code has content that is neither similar nor identical to assertion keywords or expressions containing assertion keywords, that is, UT code There is no content similar to or the same as the assertion keyword in the UT code; or, there is content that is similar to but not the same as the assertion keyword or the expression containing the assertion keyword in the UT code, for example: the assertion keyword is "assert”, and The UT code has a similar but different content "asert”; the expression containing the assertion keyword is "assertTrue()", and the UT code has a similar but different content "assertTrue(".
  • the validity test feature can also be a test case experience data set, which includes: different use case experience data with relative attributes, for example: in a test scenario, a test case The experience data set includes: the first use case experience data is “1", the second use case experience data is “0", using "1” and "0” as different inputs for the UT code to test the validity of the UT code; or, In another test scenario, the test case experience data set includes: the first use case experience data is "1", the second use case experience data is "-1", the third use case experience data is "0”, the fourth use case experience The data is "none", and "1", "-1", "0” and “none” are used as different inputs for the UT code to test the validity of the UT code.
  • the amount and type of use case experience data in the above test case experience data set can be set according to actual needs, but all need to be satisfied: for a UT code, all use case experience data in the use case experience data set can meet the test case coverage as much as possible The input combination requirements.
  • test case experience data set you can judge whether all the use case experience data in the UT code can meet the common input combination requirements of the test case coverage as much as possible, for example: if a UT code has use case experience data as " -1" and "1", the UT code should still exist but there is no other use case experience data "none", then the use case experience data in the test case experience data set in the UT code is incomplete, it can be considered that The UT code cannot pass the validity test. Whether the test cases cover common boundary conditions can also be judged through similar situations, and finally whether the UT code can pass the validity test.
  • the way to traverse the source code can be through the configured source code path, first read the source code directory, and then traverse all the codes line by line according to the source code directory or make the UT code effective by locating the UT code in the source code. Sex test.
  • Implementing the code validity test method of this embodiment can test the validity of the UT code, which can specifically involve testing whether valid assertions are written in the UT code, and whether the test cases in the UT code cover common input combinations or boundary conditions, etc. , Then in the code development process, the developer can obtain the validity test result, and perform corresponding code correction actions based on the validity test result, so as to ensure the quality and development efficiency of the software code, and can introduce the code validity test as a software test The important consideration factors in the, prompt developers to pay attention to the effectiveness of the code and develop good development habits.
  • the validity test rule also includes UT code features, which can be UT function keywords, or expressions containing UT function keywords, or classic UT running code segments, etc.
  • UT code features can be "unittest”, "import unittest”, etc.
  • the code validity testing method of this embodiment mainly includes the process shown in Fig. 1:
  • Step S101 locate the UT code in the source code according to the characteristics of the UT code.
  • one or some UT codes can be quickly located in the source code according to the UT code features.
  • Step S102 Determine whether there is content similar to or the same as the validity test feature in the located UT code.
  • the validity test result indicates that the UT code has a valid assertion; when there is content similar to but different from the validity test feature in the UT code, or there is no content similar to but different from the validity test feature in the UT code , When there is no content that is the same as the validity test feature, the validity test result indicates that the UT code does not have a valid assertion.
  • the character comparison can be used.
  • the validity test result can indicate whether the located UT code passes the validity test, and can also indicate the specific reason why the located UT code passes the validity test, for example, whether a valid assertion is written.
  • this embodiment further provides the following content:
  • the validity test rule also includes a code experience framework for indicating the logical composition of the source code, and the code experience framework includes the position indication information of the experience UT code.
  • the logical composition of the source code can include: the original basic code for realizing system functions, and UT code. In the actual software development process, usually developers will write software code according to certain code writing logic, so that the source code obtained by writing has a certain logic composition law.
  • the source code shown in Figure 2 contains the implementation system The basic code 201 of the function and the UT code 202.
  • the basic code 201 includes the first part code 2011 and the second part code 2012.
  • the first part code 2011 and the second part code 2012 are the smallest testable units and both include basic code features (For example: corresponding function code keywords), the UT code 202 is placed after the basic code 201 and used to execute UT on the first part of code 2011 and the second part of code 2012. If there is a code experience frame that contains a three-stage structure, the first two paragraphs contain the corresponding basic code features, and the last paragraph contains the experience UT code position indication information to indicate that UT code should appear in the last paragraph, then the code frame of the source code to be tested When matched with the code experience framework, the source code to be tested can quickly locate the position where the UT code should exist as indicated by the experience UT code position indication information, so that the UT code at this position can be tested for validity.
  • basic code features For example: corresponding function code keywords
  • the position indicated by the empirical UT code position indication information may be the starting position, ending position, intermediate position, or the position covered by some codes in the UT code that may exist.
  • the empirical UT code location indication information correspondingly indicates that there is no UT code at the position in the source code, a close search can be performed, and it is also possible to achieve rapid positioning of the UT code.
  • the code experience framework can be directly obtained through several source code code framework samples, or through deep learning methods to train several source code code framework samples.
  • the amount of code covered by each section of the code experience framework can be flexibly changed, so that the code experience framework can be applied to source codes with different amounts of code.
  • the experience UT code location indication information indicates the location of the UT code in the code experience framework.
  • the code experience framework is equivalent to indicating the structural composition logic of the basic code and the UT code.
  • the code experience framework itself is also a kind of location information. Collection, using location information, and then can determine whether the code frame of the source code matches the code experience frame or even the degree of matching.
  • the UT code contained in the source code is checked for content that matches the validity test feature, which specifically includes the process shown in Figure 3:
  • step S301 it is judged whether the code framework of the source code matches the code experience framework, and if so, step 302 is executed, otherwise, the source code can be traversed to locate the corresponding UT code to perform the validity test of the UT code in the source code.
  • the code framework of the source code can be automatically generated in advance according to the characteristics of the basic code when the code is written.
  • Step S302 Determine whether there is a validity test feature in the UT code corresponding to the position indicated by the empirical UT code position indication information in the source code. If so, the validity test result indicates that the position indicated by the empirical UT code position indication information corresponds to A valid assertion is written in the UT code, otherwise the validity test result indicates that the UT code corresponding to the position indicated by the empirical UT code position indication information does not have a valid assertion.
  • Implementing the code validity testing method of this embodiment can not only realize the rapid positioning of the UT code in the source code, but also build an orderly logical composition structure of the source code, which is convenient for positioning, searching, and correcting during the code development process.
  • this embodiment further provides the following content:
  • the code validity testing method of this embodiment further includes:
  • Step S401 When there is no validity test feature in the UT code corresponding to the position indicated by the empirical UT code position indication information in the source code, the validity test result indicates the UT code corresponding to the position indicated by the empirical UT code position indication information No valid assertion is written, and the position indicated by the empirical UT code position indication information is prompted.
  • This embodiment provides a code validity test method, which mainly includes the process shown in FIG. 5:
  • Step S501 Obtain the incremental content of the source code of the current version with the UT code on the source code of the previous version and the previous validity test result of the source code of the previous version.
  • Step S502 According to the validity test rule containing the validity test feature, it is detected whether there is content matching the validity test feature in the UT code included in the incremental content, and the incremental validity test result is obtained.
  • Step S503 Combine the previous validity test result with the incremental validity test result to obtain the current validity test result of the current version of the source code.
  • the UT code positioning of the incremental content can be performed according to the method of traversing the incremental content or the method shown in the second and third embodiments.
  • the previous validity test result and the incremental validity test result can be based on the relevant content in the foregoing embodiment.
  • the previous validity test result corresponding to the source code of the previous version is combined with the incremental validity test result corresponding to the incremental content to obtain the current version of the source code.
  • Effective testability test results for example: the current effectiveness test result is the effectiveness test passed, and the incremental effectiveness test result is the effectiveness test failed, the current effectiveness test result is the effectiveness test failed, and can indicate Because there is a validity problem in the incremental content, it can further locate the location and/or cause of the validity problem; the current validity test result is the validity test passed, and the incremental validity test result is the validity test passed , The current validity test result is the validity test passed.
  • Embodiment 6 is a diagrammatic representation of Embodiment 6
  • this embodiment further adds the following content:
  • the validity test rule also includes a first code experience frame and a second code experience frame. There is a frame difference between the first code experience frame and the second code experience frame.
  • the content contains the position indication information of the experience UT code.
  • the code experience framework and the content of the framework difference are similar to the "code experience framework" part described in the third embodiment.
  • step S502 specifically includes the process shown in FIG. 6:
  • Step S601 Determine whether the framework of the current version of the source code matches the first code experience framework and whether the framework of the previous version source code matches the second code experience framework. If so, perform step S602, otherwise, traverse the incremental content to Locate the corresponding UT code to test the validity of the UT code in the incremental content.
  • Step S602 Determine whether there is a validity test feature in the UT code corresponding to the position indicated by the empirical UT code position indication information. If so, the current validity test result in step S503 indicates that the UT code of the previous version of the source code passes validity During testing, the current validity test result indicates that the current version of the source code passed the validity test, otherwise, regardless of whether the previous validity test result indicates whether the UT code of the previous version source code passed the validity test, the current validity test result indicates the current The version source code failed the validity test.
  • steps S601 and S602 in the embodiment can be similar to the related content in the third embodiment, and will not be repeated here.
  • the framework of UT code is JUnit framework, JUnitX framework, TestNG framework or NUnit framework, etc.
  • the corresponding validity test features may change accordingly, for example: in JUnit framework, the assertion keyword is "assertEquals"; in NUnit Under the framework, the assertion keyword is "assert.AreNotEqual” and so on.
  • the content can also be located, and the validity test result can also include the location information of the content.
  • the validity test of the UT code indicating the location of the location cannot be passed, that is, the location can be prompted to guide the developer to quickly locate the location and to perform specific problem confirmation and/or code correction processing.
  • the validity test result can also include: a description of the situation where the content is similar to the validity test feature, and/or, the content is based on Suggestions for modification of validity test features. Or, automatically modify the content according to the validity test feature, and prompt the developer of the modification.
  • FIG. 7 shows the structure of the computing device provided in the seventh embodiment of the present application. For ease of description, only the parts related to the embodiment of the present application are shown.
  • the computing device of the embodiment of the present application includes a processor 701 and a memory 702, and the processor 701 implements the steps in the foregoing method embodiments when executing the computer instructions 703 stored in the memory 702, such as steps S101 to S102 shown in FIG. 1, or Figure 3- Figure 6 shows the steps.
  • the computing device in the embodiment of the present application may be a personal computer or a network composed of computers.
  • the processor 701 in the computing device executes the computer instruction 703
  • the steps implemented when implementing the foregoing methods can refer to the description of the foregoing method embodiments, which will not be repeated here.
  • Embodiment 8 is a diagrammatic representation of Embodiment 8
  • one or more readable storage media storing computer readable instructions are provided.
  • the computer readable instructions are executed by one or more processors, the one or more processors
  • the steps in the foregoing method embodiments are implemented during execution, for example, steps S101 to S102 shown in FIG. 1 or the steps shown in FIGS. 3 to 6.
  • the readable storage medium provided in this embodiment includes a non-volatile readable storage medium and a volatile readable storage medium.
  • the execution shown in FIG. 7 is realized by hardware components, and the equipment, units, modules, devices and other components of the operations described in FIGS. 1 to 6 are here.
  • hardware components include controllers, sensors, generators, drivers, memories, comparators, arithmetic logic units, adders, subtractors, multipliers, dividers, integrators, processors, and those known to those of ordinary skill in the art Any other electronic components configured to perform the operations described in this application.
  • the hardware components are implemented by one or more processors or computers.
  • processing elements such as arrays of logic gates, controllers and arithmetic logic units, digital signal processors, microcomputers, programmable logic controllers, field programmable gate arrays, programmable logic arrays, microprocessors Or any other device or combination of devices known to those of ordinary skill in the art that can respond to and execute instructions in a defined manner to obtain a desired result) to implement a processor or a computer.
  • processing elements such as arrays of logic gates, controllers and arithmetic logic units, digital signal processors, microcomputers, programmable logic controllers, field programmable gate arrays, programmable logic arrays, microprocessors Or any other device or combination of devices known to those of ordinary skill in the art that can respond to and execute instructions in a defined manner to obtain a desired result
  • the processor or computer includes or is connected to one or more memories that store instructions or software executed by the processor or computer.
  • a hardware component implemented by a processor or a computer executes instructions or software (such as an operating system OS and one or more software applications running on the OS) to perform the operations described herein with respect to FIGS. 1 to 6. Hardware components also access, manipulate, process, create, and store data in response to the execution of instructions or software.
  • processor or “computer” may be used in the description of the examples described herein, but in other examples, multiple processors or computers are used, or the processor or computer includes multiple processing elements or multiple Type of processing element or both.
  • the hardware component includes multiple processors, and in another example, the hardware component includes a processor and a controller.
  • the hardware components have any one or more different processing configurations, examples of which include single processor, independent processor, parallel processor, single instruction single data SISD multiprocessing, single instruction multiple data SIMD multiprocessing, multiple instruction single data MISD multiple processing Processing and multi-instruction and multi-data MIMD multi-processing.
  • the execution is performed by computing hardware (for example, by one or more processors or computers) that is implemented as executing instructions or software as described above to perform the operations performed by the methods described in this application. As shown in FIGS. 1 to 6 Out the method of performing the operations described in this application. For example, a single operation or two or more operations may be performed by a single processor, or two or more processors, or a processor and a controller. One or more operations may be executed by one or more processors, or a processor and a controller, and one or more other operations may be executed by one or more other processors, or another processor and another controller. operating. One or more processors, or processors and controllers, may perform a single operation or two or more operations.
  • Instructions or software used to control a processor or a computer to implement hardware components and perform the methods described above can be written as computer instructions, code segments, instructions, or any combination thereof, to individually or collectively indicate or configure the processor or
  • the computer operates as a machine or a dedicated computer for performing operations performed by hardware components and methods as described above.
  • instructions or software include machine code directly executed by a processor or computer, such as machine code generated by a compiler.
  • the instructions or software include higher-level code that is executed by a processor or computer using an interpreter.
  • a programmer of ordinary skill in the art can easily write instructions or software based on the block diagrams and flowcharts shown in the drawings and the corresponding descriptions in the specification that disclose the algorithms used to perform the operations performed by the hardware components and the methods described above .
  • the instructions or software used to control the processor or computer to implement the hardware components and execute the methods described above, as well as any associated data, data files and data structures, can be recorded, stored or fixed in one or more non-transitory computers. Read the storage medium, or be recorded, stored or fixed on one or more non-transitory computer-readable storage mediums.
  • non-transitory computer-readable storage media include: read only memory ROM, random access memory RAM, flash memory, CD-ROM, CD-R, CD+R, CD-RW, CD+RW, DVD-ROM, DVD -R, DVD+R, DVD-RW, DVD+RW, DVD-RAM, BD-ROM, BD-R, BD-R LTH, BD-RE, magnetic tape, floppy disk, magneto-optical data storage device, optical data storage device , Hard disks, solid state disks, and any device known to those of ordinary skill in the art, which can store instructions or software and any associated data, data files and data structures in a non-transitory manner, and integrate instructions or software And any associated data, data files and data structures are provided to the processor or computer so that the processor or computer can execute instructions.
  • the instructions or software and any associated data, data files, and data structures are distributed on a networked computer system such that the instructions and software and any associated data, data files, and data structures pass through the processor or computer Stored, accessed, and executed in a distributed manner.

Abstract

本申请适用计算机技术领域,提供了一种代码有效性测试方法、计算设备及存储介质,该方法包括:根据包含有有效性测试特征的有效性测试规则,检测源代码所包含的单元测试UT代码中是否存在与所述有效性测试特征匹配的内容,得到有效性测试结果。这样,能实现对UT代码有效性进行测试,那么在代码开发过程中,开发者可以获知有效性测试结果,依据该有效性测试结果进行相应的代码修正动作,从而保证软件代码的质量及开发效率,并且可引入代码有效性测试作为软件测试中的重要考量因素,促使开发者对代码有效性进行关注,养成良好的开发习惯。

Description

代码有效性测试方法、计算设备及存储介质
本申请以2019年5月22日提交的申请号为201910430120.8,名称为“代码有效性测试方法、计算设备及存储介质”的中国发明申请为基础,并要求其优先权。
技术领域
本申请属于计算机技术领域,尤其涉及一种代码有效性测试方法、计算设备及存储介质。
背景技术
在目前的软件应用中,在开发出软件后,通常需要对软件代码进行测试,软件测试主要用于对软件正确性进行分析和对软件漏洞进行检测。单元测试(Unit Testing,UT)是指对软件中的最小可测试单元进行检测和验证,最小可测试单元可以是软件中的一个模块、一个函数或一个类等。
在进行软件测试时,通常需要确定软件的执行完整情况,进而根据该执行完整情况来对测试工作进行评估,进而便于对软件等进行调整,在此基础上对软件代码进行完善。代码覆盖率是软件测试中的一种考量因素,用以描述软件代码中代码被测试的比例或程度。代码覆盖率常常被用作衡量软件测试能力的指标,甚至于用作考核软件测试任务完成情况。现有主要可利用Jacoco等代码覆盖率统计工具,针对需要进行测试的代码进行测试并收集代码覆盖率,并基于代码覆盖率,对测试工作的完成情况进行评估。
Jacoco等统计工具虽然能测试代码覆盖率,但无法测试代码有效性,例如:无法得知是否在UT代码中写入有效断言,从而导致在代码开发过程中,无法保证软件代码的质量,无法为开发人员提供有效性评价的参考信息,开发效率得不到保障,并且可能会引导开发人员追求高代码覆盖率,而忽视代码有效性,不利于养成良好的开发习惯。
发明内容
本申请的目的在于提供一种代码有效性测试方法、计算设备及存储介质,旨在解决现有技术所存在的、的问题。
一方面,本申请提供了一种代码有效性测试方法,包括:
根据包含有有效性测试特征的有效性测试规则,检测源代码所包含的单元测试UT代码中是否存在与所述有效性测试特征匹配的内容,得到有效性测试结果。
进一步的,所述有效性测试特征为:断言关键字或包含断言关键字的表达式,所述有效性测试规则还包含UT代码特征,根据包含有有效性测试特征的有效性测试规则,检测源代码所包含的单元测试UT代码中是否存在与所述有效性测试特征匹配的内容,具体包括:
根据所述UT代码特征,在所述源代码中定位所述UT代码;
判断定位到的所述UT代码中是否存在与所述有效性测试特征相近似或相同的内容,
若定位到的所述UT代码中存在与所述有效性测试特征相同的内容,则所述有效性测试结果相应指示所述UT代码写有有效断言,
若定位到的所述UT代码中存在与所述有效性测试特征相近似但不同的内容,或者所述UT代码中既不存在与所述有效性测试特征相近似但不同的内容、又不存在与所述有效性测试特征相同的内容时,则所述有效性测试结果相应指示所述UT代码未写有有效断言。
进一步的,所述UT代码特征为UT功能关键字或包含UT功能关键字的表达式。
进一步的,所述有效性测试规则中还包含用于指示所述源代码逻辑组成的代码经验框架,所述代码经验框架中包含经验UT代码位置指示信息,
根据包含有有效性测试特征的有效性测试规则,检测源代码所包含的单元测试UT代码中是否存在与所述有效性测试特征匹配的内容,具体还包括:
判断所述源代码的代码框架是否与所述代码经验框架匹配;
若所述源代码的代码框架与所述代码经验框架匹配,则判断所述源代码中在所述经验UT代码位置指示信息所指示的位置对应的所述UT代码中是否存在所述有效性测试特征,
若所述源代码中在所述经验UT代码位置指示信息所指示的位置对应的所述UT 代码中存在所述有效性测试特征,则所述有效性测试结果指示所述经验UT代码位置指示信息所指示的位置对应的所述UT代码写有有效断言。
进一步的,当所述源代码中在所述经验UT代码位置指示信息所指示的位置对应的所述UT代码中不存在所述有效性测试特征时,将所述经验UT代码位置指示信息所指示的位置进行提示,以提示开发者进行问题确认和/或代码修正处理。
进一步的,所述方法还包括:
当所述UT代码中存在与所述有效性测试特征相近似但不同的内容时,对所述内容进行定位,所述有效性测试结果中包含所述内容的定位信息,或者,
当所述UT代码中存在与所述有效性测试特征相近似但不同的内容时,所述有效性测试结果中包含:所述内容与所述有效性测试特征相近似的情形说明,和/或,对所述内容依据所述有效性测试特征进行修改的建议,或者,
当所述UT代码中存在与所述有效性测试特征相近似但不同的内容时,自动对所述内容依据所述有效性测试特征进行修改,并向开发者提示所述修改。
另一方面,本申请还提供了一种代码有效性测试方法,包括:
获得存在有单元测试UT代码的当前版本源代码在前一版本源代码上的增量内容以及所述前一版本源代码的前一有效性测试结果;
根据包含有有效性测试特征的有效性测试规则,检测所述增量内容所包含的UT代码中是否存在与所述有效性测试特征匹配的内容,得到增量有效性测试结果;
将所述前一有效性测试结果与所述增量有效性测试结果相组合,得到所述当前版本源代码的当前有效性测试结果。
进一步的,所述有效性测试规则中还包含第一代码经验框架及第二代码经验框架,所述第一代码经验框架与所述第二代码经验框架之间存在框架差内容,所述框架差内容中包含经验UT代码位置指示信息,
根据包含有有效性测试特征的有效性测试规则,检测所述增量内容所包含的UT代码中是否存在与所述有效性测试特征匹配的内容,具体包括:
判断所述当前版本源代码的框架是否与所述第一代码经验框架匹配且所述前一版本源代码的框架是否与所述第二代码经验框架匹配;
若所述当前版本源代码的框架与所述第一代码经验框架匹配且所述前一版本源代码的框架与所述第二代码经验框架匹配,则判断所述经验UT代码位置指示信息所指示的位置对应的所述UT代码中是否存在所述有效性测试特征,
若所述经验UT代码位置指示信息所指示的位置对应的所述UT代码中存在所述有效性测试特征,则当所述前一有效性测试结果指示所述前一版本源代码的所述UT代码通过有效性测试时,所述当前有效性测试结果指示所述当前版本源代码通过有效性测试。
另一方面,本申请提供一种计算设备,包括存储器及处理器,所述处理器执行所述存储器中存储的计算机指令时实现如下步骤:
根据包含有有效性测试特征的有效性测试规则,检测源代码所包含的单元测试UT代码中是否存在与所述有效性测试特征匹配的内容,得到有效性测试结果。
另一方面,本申请提供一种计算设备,包括存储器及处理器,所述处理器执行所述存储器中存储的计算机指令时实现如下步骤:
获得存在有单元测试UT代码的当前版本源代码在前一版本源代码上的增量内容以及所述前一版本源代码的前一有效性测试结果;
根据包含有有效性测试特征的有效性测试规则,检测所述增量内容所包含的UT代码中是否存在与所述有效性测试特征匹配的内容,得到增量有效性测试结果;
将所述前一有效性测试结果与所述增量有效性测试结果相组合,得到所述当前版本源代码的当前有效性测试结果。
另一方面,本申请提供一个或多个存储有计算机可读指令的可读存储介质,所述计算机可读存储介质存储有计算机可读指令,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行如下步骤:
根据包含有有效性测试特征的有效性测试规则,检测源代码所包含的单元测试UT代码中是否存在与所述有效性测试特征匹配的内容,得到有效性测试结果。
另一方面,本申请提供一个或多个存储有计算机可读指令的可读存储介质,所述计算机可读存储介质存储有计算机可读指令,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行如下步骤:
获得存在有单元测试UT代码的当前版本源代码在前一版本源代码上的增量内容以及所述前一版本源代码的前一有效性测试结果;
根据包含有有效性测试特征的有效性测试规则,检测所述增量内容所包含的UT代码中是否存在与所述有效性测试特征匹配的内容,得到增量有效性测试结果;
将所述前一有效性测试结果与所述增量有效性测试结果相组合,得到所述当前版本源代码的当前有效性测试结果。
本申请的一个或多个实施例的细节在下面的附图及描述中提出。本申请的其他特征和优点将从说明书、附图以及权利要求书变得明显。
附图说明
图1是本申请实施例二提供的代码有效性测试方法的实现流程图;
图2是本申请实施例三中源代码逻辑组成示意图;
图3是本申请实施例三提供的代码有效性测试方法的部分流程图;
图4是本申请实施例四提供的代码有效性测试方法的部分流程图;
图5是本申请实施例五提供的代码有效性测试方法的实现流程图;
图6是本申请实施例六提供的代码有效性测试方法的部分流程图;
图7是本申请实施例七提供的计算设备的结构示意图。
具体实施方式
为了使本申请的目的、技术方案及优点更加清楚明白,以下结合附图及实施例,对本申请进行进一步详细说明。应当理解,此处所描述的具体实施例仅仅用以解释本申请,并不用于限定本申请。
以下结合具体实施例对本申请的具体实现进行详细描述:
软件测试是保证软件质量的关键。通常情况下,软件测试所花费的时间大致占到整个软件工程生命周期的40%以上。通过对软件中的最小可测试单元(例如:一个类、一个函数或一个模块)进行测试,即单元测试UT,以验证软件正确性或者是否满足客户的需求。本申请实施例所提出的代码有效性测试方法,主要 是判断待测试的源代码中所包含的UT代码是否包含有效性测试特征,尤其是在当前UT代码必用断言功能的情形下,对UT代码是否包含有效断言进行检测,从而达到对代码有效性进行测试的目的。
实施例一:
本实施例提供一种代码有效性测试方法,主要包括:
根据包含有效性测试特征的有效性测试规则,遍历存在有UT代码的源代码,以判断UT代码中是否存在与有效性测试特征匹配的内容,得到有效性测试结果。
本实施例中,可事先建立一有效性测试规则,利用该有效性测试规则可对待测试源代码的有效性进行测试。
源代码是开发者用开发工具所支持的语言写出来的代码文件,由相应的字符、符号或信号码元等构成一系列计算机语言指令。源代码一般为实现一个完整的系统功能,而组成源代码的类、模块或函数等最小可测试单元则实现组成系统功能的基础功能。为了检验最小可测试单元的正确性,即最小可测试单元基础功能是否能被准确表达,通常会在源代码中加载UT代码以实现该检验目的。UT代码通常必然包含断言功能,也通常会包含测试用例。是否包含有效断言,测试用例是否覆盖常用的输入组合或边界条件等,通常成为代码有效性的测试标准。其中,尤其以是否包含有效断言作为代码有效性的重要测试标准。
对于针对断言的有效性测试,有效性测试特征可以是断言关键字或包含断言关键字的表达式等,若UT代码中不存在断言关键字或不存在包含断言关键字的表达式,则可认为该UT代码未写有有效断言而无法通过有效性测试。UT代码中不存在断言关键字或包含断言关键字的表达式的情形具体可为:UT代码中存在与断言关键字或包含断言关键字的表达式既不相近又不相同的内容,即UT代码中完全不存在与断言关键字相近或相同的内容;或者,UT代码中存在与断言关键字或包含断言关键字的表达式相近但不相同的内容,例如:断言关键字为“assert”,而UT代码中存在与之相近但不相同的内容“asert”;包含断言关键字的表达式为“assertTrue()”,而UT代码中存在与之相近但不相同的内容“assertTrue(”。
对于针对测试用例的有效性测试,有效性测试特征还可以是测试用例经验数据 集,该测试用例经验数据集包含:属性相对的不同的用例经验数据,例如:在一种测试场景下,测试用例经验数据集包含:第一用例经验数据为“1”,第二用例经验数据为“0”,以“1”及“0”作为UT代码不同的输入来对UT代码进行有效性测试;或者,在另一种测试场景下,测试用例经验数据集包含:第一用例经验数据为“1”,第二用例经验数据为“-1”,第三用例经验数据为“0”,第四用例经验数据为“none”,以“1”、“-1”、“0”及“none”作为UT代码不同的输入来对UT代码进行有效性测试。上述测试用例经验数据集中的用例经验数据数量、类型等可根据实际需要进行设定,但是均需满足:对于一UT代码而言,用例经验数据集中的所有用例经验数据能尽量满足测试用例覆盖常用的输入组合要求。利用预置或实时生成的测试用例经验数据集,即可判断UT代码中的所有用例经验数据是否能尽量满足测试用例覆盖常用的输入组合要求,例如:如果一UT代码中存在用例经验数据为“-1”及“1”,该UT代码中本应该还存在但并未存在另一用例经验数据“none”,则UT代码中的测试用例经验数据集中的用例经验数据不完整,则可认为该UT代码无法通过有效性测试。对于测试用例是否覆盖常用的边界条件等也可通过类似情形进行判断,而最终判断UT代码是否能通过有效性测试。
遍历源代码的方式,可通过所配置的源代码路径,首先读取源代码目录,然后根据源代码目录逐行遍历其中所有代码或者通过定位源代码中的UT代码有针对性地进行UT代码有效性测试。
实施本实施例的代码有效性测试方法,能实现对UT代码有效性进行测试,具体可涉及UT代码中是否写有有效断言、UT代码中测试用例是否覆盖常用的输入组合或边界条件等的测试,那么在代码开发过程中,开发者可以获知有效性测试结果,依据该有效性测试结果进行相应的代码修正动作,从而保证软件代码的质量及开发效率,并且可引入代码有效性测试作为软件测试中的重要考量因素,促使开发者对代码有效性进行关注,养成良好的开发习惯。
实施例二:
本实施例所提供的代码有效性测试方法中,有效性测试规则还包含UT代码特征,UT代码特征可以为UT功能关键字,或包含UT功能关键字的表达式,或经典UT运行代码段等,例如:UT代码特征可以是“unittest”、“import unittest”等。
本实施例的代码有效性测试方法主要包括如图1所示的流程:
步骤S101,根据UT代码特征,在源代码中定位UT代码。
本实施例中,当源代码中存在相应的UT代码特征,则可依据UT代码特征,在源代码中快速定位到某个或某些UT代码。
步骤S102,判断定位到的UT代码中是否存在与有效性测试特征相近似或相同的内容,当UT代码中存在与有效性测试特征(断言关键字、包含断言关键字的表达式等)相同的内容时,有效性测试结果指示UT代码写有有效断言;当UT代码中存在与有效性测试特征相近似但不同的内容,或者UT代码中既不存在与有效性测试特征相近似但不同的内容、也不存在与有效性测试特征相同的内容时,有效性测试结果指示UT代码未写有有效断言。在具体判断时,可采用字符比较的方式进行。
有效性测试结果可以指示所定位的UT代码是否通过有效性测试,也可以指示所定位的UT代码是否通过有效性测试的具体原因,例如:是否写有有效断言等。
实施本实施例的代码有效性测试方法,能实现对源代码中UT代码的快速定位,从而快速进行UT代码有效性的测试,提高有效性测试的效率。
实施例三:
本实施例在上述各实施例基础上,进一步提供了如下内容:
本实施例所提供的代码有效性测试方法中,有效性测试规则中还包含用于指示源代码逻辑组成的代码经验框架,代码经验框架中包含经验UT代码位置指示信息。源代码的逻辑组成可包含:原有为实现系统功能的基础代码,以及UT代码。在实际的软件开发过程中,通常开发者会按照一定的代码编写逻辑编写软件代码,使得编写所得到的源代码具有一定的逻辑组成规律,如图2所示的源代码中,包含为实现系统功能的基础代码201,以及UT代码202,其中基础代码201又包括第一部分代码2011及第二部分代码2012,第一部分代码2011及第二部分代码2012均为最小可测试单元且均包含基础代码特征(例如:相应的功能代码关键字),UT代码202置于基础代码201之后、用于对第一部分代码2011及第二部分代码2012执行UT。如存在一代码经验框架包含三段式结构、前两段包含相应 的基础代码特征且最后一段包含经验UT代码位置指示信息以指示在最后一段应出现UT代码,则当待测试源代码的代码框架与该代码经验框架匹配时,可在待测试源代码中快速定位到经验UT代码位置指示信息所指示的、应该存在UT代码的位置,从而对该位置处的UT代码进行有效性测试。经验UT代码位置指示信息所指示的位置可以是可能存在的UT代码的起始位置、终止位置、中间位置或UT代码中部分代码所覆盖的位置等。当经验UT代码位置指示信息对应指示在源代码中的位置处不存在UT代码时,可进行临近查找,同样也可能实现UT代码的快速定位。代码经验框架可通过若干源代码代码框架样本直接得到,或通过深度学习方法对若干源代码代码框架样本训练得到。另外,代码经验框架中各段所涵盖的代码量可弹性变化,使得代码经验框架可适用于不同代码量的源代码。
可以理解的是,经验UT代码位置指示信息指示代码经验框架中应该存在UT代码的位置,代码经验框架相当于可以指示基础代码与UT代码的结构组成逻辑,代码经验框架本身也是一种位置信息的集合,利用位置信息,进而可以判断源代码的代码框架与代码经验框架是否匹配甚至匹配程度的判断。
那么,根据包含有有效性测试特征的有效性测试规则,检测源代码所包含的UT代码中是否存在与有效性测试特征匹配的内容,具体还包括如图3所示的流程:
步骤S301,判断源代码的代码框架是否与代码经验框架匹配,若是,则执行步骤302,否则可遍历源代码以定位到相应的UT代码,以进行源代码中UT代码有效性测试。
本实施例中,源代码的代码框架可以预先在代码编写时,依据基础代码特征自动生成。
步骤S302,判断源代码中在经验UT代码位置指示信息所指示的位置对应的UT代码中是否存在有效性测试特征,若是,则有效性测试结果指示经验UT代码位置指示信息所指示的位置对应的UT代码写有有效断言,否则有效性测试结果指示经验UT代码位置指示信息所指示的位置对应的UT代码未写有有效断言。
实施本实施例的代码有效性测试方法,不仅能实现对源代码中UT代码的快速定位,而且能构建源代码有序的逻辑组成结构,便于代码开发过程中的定位查 找、修正等处理。
实施例四:
本实施例在实施例三基础上,进一步提供了如下内容:
如图4所示,本实施例的代码有效性测试方法还包括:
步骤S401,当源代码中在经验UT代码位置指示信息所指示的位置对应的UT代码中不存在有效性测试特征时,有效性测试结果指示经验UT代码位置指示信息所指示的位置对应的UT代码未写有有效断言,且将经验UT代码位置指示信息所指示的位置进行提示。
实施本实施例的代码有效性测试方法,当应存在有效性测试特征的位置未出现有效性测试特征时,表明该位置的UT代码有效性测试不能通过,即可以经验UT代码位置指示信息所指示的该位置进行提示,以提示开发者快速定位该位置并可针对性进行问题确认和/或代码修正处理。
实施例五:
本实施例提供一种代码有效性测试方法,主要包括如图5所示的流程:
步骤S501,获得存在有UT代码的当前版本源代码在前一版本源代码上的增量内容以及前一版本源代码的前一有效性测试结果。
步骤S502,根据包含有有效性测试特征的有效性测试规则,检测增量内容所包含的UT代码中是否存在与有效性测试特征匹配的内容,得到增量有效性测试结果。
步骤S503,将前一有效性测试结果与增量有效性测试结果相组合,得到当前版本源代码的当前有效性测试结果。
本实施例中,增量内容的UT代码定位可依据遍历增量内容方式或如实施例二、三所示的方式进行。其中,前一有效性测试结果与增量有效性测试结果可依据上述实施例中相关内容所述。
按照预设的有效性测试结果的组合策略,将前一版本源代码对应的前一有效性测试结果,与增量内容对应的增量有效性测试结果相组合,可得到当前版本源代码的当前有效测试性测试结果,例如:当前一有效性测试结果为有效性测试通过,而增量有效性测试结果为有效性测试不通过,则当前有效性测试结果为 有效性测试不通过,并且可指示为增量内容中存在有效性问题,进一步还可定位出现该有效性问题的位置和/或原因等;当前一有效性测试结果为有效性测试通过,增量有效性测试结果为有效性测试通过,则当前有效性测试结果为有效性测试通过。
实施本实施例的代码有效性测试方法,不仅能实现上述实施例相应能够实现的效果,而且对于增量更新的当前版本源代码可简化有效性测试,进一步提高整体运行效率。
实施例六:
本实施例在实施例五基础上,进一步增加了如下内容:
本实施例的代码有效性测试方法中,有效性测试规则中还包含第一代码经验框架及第二代码经验框架,第一代码经验框架与第二代码经验框架之间存在框架差内容,框架差内容中包含经验UT代码位置指示信息。代码经验框架及框架差内容类似于实施例三中所述的“代码经验框架”部分。
相应的,步骤S502具体包括如图6所示的流程:
步骤S601,判断所当前版本源代码的框架是否与第一代码经验框架匹配且前一版本源代码的框架是否与第二代码经验框架匹配,若是,则执行步骤S602,否则可遍历增量内容以定位到相应的UT代码,以进行增量内容中UT代码有效性测试。
步骤S602,判断经验UT代码位置指示信息所指示的位置对应的UT代码中是否存在有效性测试特征,若是,则步骤S503中当前一有效性测试结果指示前一版本源代码的UT代码通过有效性测试时,当前有效性测试结果指示当前版本源代码通过有效性测试,否则,不论前一有效性测试结果指示前一版本源代码的UT代码是否通过有效性测试时,当前有效性测试结果指示当前版本源代码未通过有效性测试。
实施例中步骤S601、S602的内容可类似于实施例三中相关内容,此处不再赘述。
其他应用例中可选的方案:
1、UT代码的框架为JUnit框架、JUnitX框架、TestNG框架或NUnit框架等,相 应的有效性测试特征可能会发生相应的变化,例如:在JUnit框架下,断言关键字为“assertEquals”;在NUnit框架下,断言关键字为“assert.AreNotEqual”等。
2、根据有效性测试结果,生成用于引导开发者进行代码修复的测试报告。
3、当UT代码中存在与有效性测试特征相近似但不同的内容时,还可以对该内容进行定位,有效性测试结果中还可以包含该内容的定位信息。这样,表明该定位位置的UT代码有效性测试不能通过,即可以对该位置进行提示,以指导开发者快速定位该位置并可针对性进行问题确认和/或代码修正处理。
4、当UT代码中存在与有效性测试特征相近似但不同的内容时,有效性测试结果中还可以包含:该内容与有效性测试特征相近似的情形说明,和/或,对该内容依据有效性测试特征进行修改的建议。亦或者,自动对该内容依据有效性测试特征进行修改,并向开发者提示该修改。
实施例七:
图7示出了本申请实施例七提供的计算设备的结构,为了便于说明,仅示出了与本申请实施例相关的部分。
本申请实施例的计算设备包括处理器701及存储器702,处理器701执行存储器702中存储的计算机指令703时实现上述各个方法实施例中的步骤,例如图1所示的步骤S101至S102,或者图3-图6所示的步骤。
本申请实施例的计算设备可以为个人计算机或者计算机组成的网络。该计算设备中处理器701执行计算机指令703时,实现上述各方法时实现的步骤可参考前述方法实施例的描述,在此不再赘述。
实施例八:
在本申请实施例中,提供了一个或多个存储有计算机可读指令的可读存储介质,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行时实现上述各方法实施例中的步骤,例如,图1所示的步骤S101至S102,或者图3-图6所示的步骤。本实施例所提供的可读存储介质包括非易失性可读存储介质和易失性可读存储介质。
通过硬件组件来实现图7中示出的执行,这里针对图1至图6描述的操作的设备、单元、模块、装置和其他组件。硬件组件的示例包括控制器、传感器、生成 器、驱动器、存储器、比较器、算术逻辑单元、加法器、减法器、乘法器、除法器、集成器、处理器以及本领域普通技术人员所知的被配置为执行本申请中描述的操作的任意其他电子组件。在一个示例中,通过一个或多个处理器或计算机来实现硬件组件。通过一个或多个处理元件(诸如,逻辑门的阵列、控制器和算术逻辑单元、数字信号处理器、微型计算机、可编程逻辑控制器、现场可编程门阵列、可编程逻辑阵列、微处理器或本领域普通技术人员所知的能够以限定的方式响应并执行指令以获得期望结果的任意其他装置或装置的组合)来实现处理器或计算机。
在一个示例中,处理器或计算机包括或连接到存储由处理器或计算机执行的指令或软件的一个或多个存储器。通过处理器或计算机实现的硬件组件执行指令或软件(诸如,操作系统OS和在OS上运行的一个或多个软件应用),以执行这里针对图1至图6描述的操作。硬件组件还响应于指令或软件的执行而访问、操控、处理、创建和存储数据。为了简明,单数术语“处理器”或“计算机”可用于这里描述的示例的描述,但在其他示例中,多个处理器或计算机被使用,或者处理器或计算机包括多个处理元件或多种类型的处理元件或二者。在一个示例中,硬件组件包括多个处理器,在另一示例中,硬件组件包括处理器和控制器。硬件组件具有任意一个或多个不同的处理配置,其示例包括单个处理器、独立处理器、并行处理器、单指令单数据SISD多处理、单指令多数据SIMD多处理、多指令单数据MISD多处理和多指令多数据MIMD多处理。
通过被实现为如上所述的执行指令或软件以执行本申请中描述的由方法执行的操作的计算硬件(例如,通过一个或多个处理器或计算机)来执行在图1至图6中示出的执行本申请中描述的操作的方法。例如,可通过单个处理器、或者两个或更多个处理器、或者处理器和控制器来执行单个操作或者两个或更多个操作。可通过一个或多个处理器、或者处理器和控制器来执行一个或多个操作,可通过一个或多个其他处理器、或者另一处理器和另一控制器来执行一个或多个其他操作。一个或多个处理器、或者处理器和控制器可执行单个操作或者两个或更多个操作。用于控制处理器或计算机实现硬件组件并且执行如上面描述的方法的指令或软件可被写为计算机指令、代码段、指令或它们的任何组合, 以单独地或共同地指示或配置处理器或计算机作为用于执行由硬件组件执行的操作和如上所述的方法的机器或专用计算机进行操作。在一个示例中,指令或软件包括直接由处理器或计算机执行的机器代码,诸如,由编译器产生的机器代码。在另一示例中,指令或软件包括由处理器或计算机使用解释器执行的更高级代码。本领域普通编程人员可基于公开了用于执行由硬件组件执行的操作和如上所述的方法的算法的附图中示出的框图和流程图以及说明书中的相应描述,容易地编写指令或软件。
用于控制处理器或计算机实现硬件组件并且执行如上所述的方法的指令或软件以及任何相关联的数据、数据文件以及数据结构可被记录、存储或固定在一个或多个非暂时性计算机可读存储介质中,或被记录、存储或固定在一个或多个非暂时性计算机可读存储介质上。非暂时性计算机可读存储介质的示例包括:只读存储器ROM、随机存取存储器RAM、闪存、CD-ROM、CD-R、CD+R、CD-RW、CD+RW、DVD-ROM、DVD-R、DVD+R、DVD-RW、DVD+RW、DVD-RAM、BD-ROM、BD-R、BD-R LTH、BD-RE、磁带、软盘、磁光数据存储装置、光学数据存储装置、硬盘、固态盘和本领域普通技术人员所知的任意装置,所述任意装置能够以非暂时性的方式存储指令或软件以及任何相关联的数据、数据文件和数据结构,并将指令或软件以及任何相关联的数据、数据文件以及数据结构提供给处理器或计算机,以便处理器或计算机能执行指令。在一个示例中,指令或软件以及任何相关联的数据、数据文件以及数据结构被分布在联网的计算机系统上,使得指令和软件以及任何相关联的数据、数据文件以及数据结构通过处理器或计算机以分布式的方式被存储、访问和执行。
虽然本公开包括特定示例,但是本领域普通技术人员在获得本主题申请的公开的全面理解之后将清楚的是:在不脱离权利要求和它们的等同物的精神和范围的情况下,可对这些示例进行形式和细节上的各种改变。在此描述的示例应仅在描述意义上考虑,而非为了限制的目的。在每个示例中的特征或方面的描述将被视为可应用于其他示例中的相似特征或方面。如果以不同的顺序执行描述的技术,和/或如果描述的系统、架构、装置或电路中的组件以不同方式被组合和/或被其他组件或其等同物替代或补充,则可实现合适的结果。因此,本公开 的范围并非由具体实施方式限定,而是由权利要求和它们的等同物所限定,并且在权利要求和它们的等同物的范围内的所有变化将被解释为包括在本公开中。
发明概述
技术问题
问题的解决方案
发明的有益效果

Claims (20)

  1. 一种代码有效性测试方法,其特征在于,包括:
    根据包含有有效性测试特征的有效性测试规则,检测源代码所包含的单元测试UT代码中是否存在与所述有效性测试特征匹配的内容,得到有效性测试结果。
  2. 如权利要求1所述的方法,其特征在于,所述有效性测试特征为:断言关键字或包含断言关键字的表达式,所述有效性测试规则还包含UT代码特征,根据包含有有效性测试特征的有效性测试规则,检测源代码所包含的单元测试UT代码中是否存在与所述有效性测试特征匹配的内容,具体包括:
    根据所述UT代码特征,在所述源代码中定位所述UT代码;
    判断定位到的所述UT代码中是否存在与所述有效性测试特征相近似或相同的内容,
    若定位到的所述UT代码中存在与所述有效性测试特征相同的内容,则所述有效性测试结果相应指示所述UT代码写有有效断言,
    若定位到的所述UT代码中存在与所述有效性测试特征相近似但不同的内容,或者所述UT代码中既不存在与所述有效性测试特征相近似但不同的内容、又不存在与所述有效性测试特征相同的内容时,则所述有效性测试结果相应指示所述UT代码未写有有效断言。
  3. 如权利要求2所述的方法,其特征在于,所述UT代码特征为UT功能关键字或包含UT功能关键字的表达式。
  4. 如权利要求1或2所述的方法,其特征在于,所述有效性测试规则中还包含用于指示所述源代码逻辑组成的代码经验框架,所述代码经验框架中包含经验UT代码位置指示信息,
    根据包含有有效性测试特征的有效性测试规则,检测源代码所包含的单元测试UT代码中是否存在与所述有效性测试特征匹配的内容,具体还包括:
    判断所述源代码的代码框架是否与所述代码经验框架匹配;
    若所述源代码的代码框架与所述代码经验框架匹配,则判断所述源代码中在所述经验UT代码位置指示信息所指示的位置对应的所述UT代码中是否存在所述有效性测试特征;
    若所述源代码中在所述经验UT代码位置指示信息所指示的位置对应的所述UT代码中存在所述有效性测试特征,则所述有效性测试结果指示所述经验UT代码位置指示信息所指示的位置对应的所述UT代码写有有效断言。
  5. 如权利要求4所述的方法,其特征在于,当所述源代码中在所述经验UT代码位置指示信息所指示的位置对应的所述UT代码中不存在所述有效性测试特征时,则将所述经验UT代码位置指示信息所指示的位置进行提示,以提示开发者进行问题确认和/或代码修正处理。
  6. 如权利要求2所述的方法,其特征在于,所述方法还包括:
    当所述UT代码中存在与所述有效性测试特征相近似但不同的内容时,对所述内容进行定位,所述有效性测试结果中包含所述内容的定位信息,或者,
    当所述UT代码中存在与所述有效性测试特征相近似但不同的内容时,所述有效性测试结果中包含:所述内容与所述有效性测试特征相近似的情形说明,和/或,对所述内容依据所述有效性测试特征进行修改的建议,或者,
    当所述UT代码中存在与所述有效性测试特征相近似但不同的内容时,自动对所述内容依据所述有效性测试特征进行修改,并向开发者提示所述修改。
  7. 一种代码有效性测试方法,其特征在于,包括:
    获得存在有单元测试UT代码的当前版本源代码在前一版本源代码上的增量内容以及所述前一版本源代码的前一有效性测试结果;
    根据包含有有效性测试特征的有效性测试规则,检测所述增量内 容所包含的UT代码中是否存在与所述有效性测试特征匹配的内容,得到增量有效性测试结果;
    将所述前一有效性测试结果与所述增量有效性测试结果相组合,得到所述当前版本源代码的当前有效性测试结果。
  8. 如权利要求7所述的方法,其特征在于,所述有效性测试规则中还包含第一代码经验框架及第二代码经验框架,所述第一代码经验框架与所述第二代码经验框架之间存在框架差内容,所述框架差内容中包含经验UT代码位置指示信息,
    根据包含有有效性测试特征的有效性测试规则,检测所述增量内容所包含的UT代码中是否存在与所述有效性测试特征匹配的内容,具体包括:
    判断所述当前版本源代码的框架是否与所述第一代码经验框架匹配且所述前一版本源代码的框架是否与所述第二代码经验框架匹配;
    若所述当前版本源代码的框架与所述第一代码经验框架匹配且所述前一版本源代码的框架与所述第二代码经验框架匹配,则判断所述经验UT代码位置指示信息所指示的位置对应的所述UT代码中是否存在所述有效性测试特征,
    若所述经验UT代码位置指示信息所指示的位置对应的所述UT代码中存在所述有效性测试特征,则当所述前一有效性测试结果指示所述前一版本源代码的所述UT代码通过有效性测试时,所述当前有效性测试结果指示所述当前版本源代码通过有效性测试。
  9. 一种计算设备,包括存储器及处理器,其特征在于,所述处理器执行所述存储器中存储的计算机指令时实现如下步骤:
    根据包含有有效性测试特征的有效性测试规则,检测源代码所包含的单元测试UT代码中是否存在与所述有效性测试特征匹配的内容,得到有效性测试结果。
  10. 如权利要求9所述的计算设备,其特征在于,所述有效性测试特征 为:断言关键字或包含断言关键字的表达式,所述有效性测试规则还包含UT代码特征,根据包含有有效性测试特征的有效性测试规则,检测源代码所包含的单元测试UT代码中是否存在与所述有效性测试特征匹配的内容,具体包括:
    根据所述UT代码特征,在所述源代码中定位所述UT代码;
    判断定位到的所述UT代码中是否存在与所述有效性测试特征相近似或相同的内容,
    若定位到的所述UT代码中存在与所述有效性测试特征相同的内容,则所述有效性测试结果相应指示所述UT代码写有有效断言,
    若定位到的所述UT代码中存在与所述有效性测试特征相近似但不同的内容,或者所述UT代码中既不存在与所述有效性测试特征相近似但不同的内容、又不存在与所述有效性测试特征相同的内容时,则所述有效性测试结果相应指示所述UT代码未写有有效断言。
  11. 如权利要求9或10所述的计算设备,其特征在于,所述有效性测试规则中还包含用于指示所述源代码逻辑组成的代码经验框架,所述代码经验框架中包含经验UT代码位置指示信息,
    根据包含有有效性测试特征的有效性测试规则,检测源代码所包含的单元测试UT代码中是否存在与所述有效性测试特征匹配的内容,具体还包括:
    判断所述源代码的代码框架是否与所述代码经验框架匹配;
    若所述源代码的代码框架与所述代码经验框架匹配,则判断所述源代码中在所述经验UT代码位置指示信息所指示的位置对应的所述UT代码中是否存在所述有效性测试特征;
    若所述源代码中在所述经验UT代码位置指示信息所指示的位置对应的所述UT代码中存在所述有效性测试特征,则所述有效性测试结果指示所述经验UT代码位置指示信息所指示的位置对应的所述UT代码写有有效断言。
  12. 如权利要求10所述的计算设备,其特征在于,所述处理器执行所述存储器中存储的计算机指令时还实现如下步骤:
    当所述UT代码中存在与所述有效性测试特征相近似但不同的内容时,对所述内容进行定位,所述有效性测试结果中包含所述内容的定位信息,或者,
    当所述UT代码中存在与所述有效性测试特征相近似但不同的内容时,所述有效性测试结果中包含:所述内容与所述有效性测试特征相近似的情形说明,和/或,对所述内容依据所述有效性测试特征进行修改的建议,或者,
    当所述UT代码中存在与所述有效性测试特征相近似但不同的内容时,自动对所述内容依据所述有效性测试特征进行修改,并向开发者提示所述修改。
  13. 一种计算设备,包括存储器及处理器,其特征在于,所述处理器执行所述存储器中存储的计算机指令时实现如下步骤:
    获得存在有单元测试UT代码的当前版本源代码在前一版本源代码上的增量内容以及所述前一版本源代码的前一有效性测试结果;
    根据包含有有效性测试特征的有效性测试规则,检测所述增量内容所包含的UT代码中是否存在与所述有效性测试特征匹配的内容,得到增量有效性测试结果;
    将所述前一有效性测试结果与所述增量有效性测试结果相组合,得到所述当前版本源代码的当前有效性测试结果。
  14. 如权利要求13所述的计算设备,其特征在于,所述有效性测试规则中还包含第一代码经验框架及第二代码经验框架,所述第一代码经验框架与所述第二代码经验框架之间存在框架差内容,所述框架差内容中包含经验UT代码位置指示信息,
    根据包含有有效性测试特征的有效性测试规则,检测所述增量内容所包含的UT代码中是否存在与所述有效性测试特征匹配的内容,具体包括:
    判断所述当前版本源代码的框架是否与所述第一代码经验框架匹配且所述前一版本源代码的框架是否与所述第二代码经验框架匹配;
    若所述当前版本源代码的框架与所述第一代码经验框架匹配且所述前一版本源代码的框架与所述第二代码经验框架匹配,则判断所述经验UT代码位置指示信息所指示的位置对应的所述UT代码中是否存在所述有效性测试特征,
    若所述经验UT代码位置指示信息所指示的位置对应的所述UT代码中存在所述有效性测试特征,则当所述前一有效性测试结果指示所述前一版本源代码的所述UT代码通过有效性测试时,所述当前有效性测试结果指示所述当前版本源代码通过有效性测试。
  15. 一个或多个存储有计算机可读指令的可读存储介质,所述计算机可读存储介质存储有计算机可读指令,其特征在于,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行如下步骤:
    根据包含有有效性测试特征的有效性测试规则,检测源代码所包含的单元测试UT代码中是否存在与所述有效性测试特征匹配的内容,得到有效性测试结果。
  16. 如权利要求15所述的可读存储介质,其特征在于,所述有效性测试特征为:断言关键字或包含断言关键字的表达式,所述有效性测试规则还包含UT代码特征,根据包含有有效性测试特征的有效性测试规则,检测源代码所包含的单元测试UT代码中是否存在与所述有效性测试特征匹配的内容,具体包括:
    根据所述UT代码特征,在所述源代码中定位所述UT代码;
    判断定位到的所述UT代码中是否存在与所述有效性测试特征相近似或相同的内容,
    若定位到的所述UT代码中存在与所述有效性测试特征相同的内容,则所述有效性测试结果相应指示所述UT代码写有有效断言, 若定位到的所述UT代码中存在与所述有效性测试特征相近似但不同的内容,或者所述UT代码中既不存在与所述有效性测试特征相近似但不同的内容、又不存在与所述有效性测试特征相同的内容时,则所述有效性测试结果相应指示所述UT代码未写有有效断言。
  17. 如权利要求15或16所述的可读存储介质,其特征在于,所述有效性测试规则中还包含用于指示所述源代码逻辑组成的代码经验框架,所述代码经验框架中包含经验UT代码位置指示信息,
    根据包含有有效性测试特征的有效性测试规则,检测源代码所包含的单元测试UT代码中是否存在与所述有效性测试特征匹配的内容,具体还包括:
    判断所述源代码的代码框架是否与所述代码经验框架匹配;
    若所述源代码的代码框架与所述代码经验框架匹配,则判断所述源代码中在所述经验UT代码位置指示信息所指示的位置对应的所述UT代码中是否存在所述有效性测试特征;
    若所述源代码中在所述经验UT代码位置指示信息所指示的位置对应的所述UT代码中存在所述有效性测试特征,则所述有效性测试结果指示所述经验UT代码位置指示信息所指示的位置对应的所述UT代码写有有效断言。
  18. 如权利要求16所述的可读存储介质,其特征在于,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器还执行如下步骤:
    当所述UT代码中存在与所述有效性测试特征相近似但不同的内容时,对所述内容进行定位,所述有效性测试结果中包含所述内容的定位信息,或者,
    当所述UT代码中存在与所述有效性测试特征相近似但不同的内容时,所述有效性测试结果中包含:所述内容与所述有效性测试特征相近似的情形说明,和/或,对所述内容依据所述有效性测试特 征进行修改的建议,或者,
    当所述UT代码中存在与所述有效性测试特征相近似但不同的内容时,自动对所述内容依据所述有效性测试特征进行修改,并向开发者提示所述修改。
  19. 一个或多个存储有计算机可读指令的可读存储介质,所述计算机可读存储介质存储有计算机可读指令,其特征在于,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行如下步骤:
    获得存在有单元测试UT代码的当前版本源代码在前一版本源代码上的增量内容以及所述前一版本源代码的前一有效性测试结果;
    根据包含有有效性测试特征的有效性测试规则,检测所述增量内容所包含的UT代码中是否存在与所述有效性测试特征匹配的内容,得到增量有效性测试结果;
    将所述前一有效性测试结果与所述增量有效性测试结果相组合,得到所述当前版本源代码的当前有效性测试结果。
  20. 如权利要求19所述的可读存储介质,其特征在于,所述有效性测试规则中还包含第一代码经验框架及第二代码经验框架,所述第一代码经验框架与所述第二代码经验框架之间存在框架差内容,所述框架差内容中包含经验UT代码位置指示信息,
    根据包含有有效性测试特征的有效性测试规则,检测所述增量内容所包含的UT代码中是否存在与所述有效性测试特征匹配的内容,具体包括:
    判断所述当前版本源代码的框架是否与所述第一代码经验框架匹配且所述前一版本源代码的框架是否与所述第二代码经验框架匹配;
    若所述当前版本源代码的框架与所述第一代码经验框架匹配且所述前一版本源代码的框架与所述第二代码经验框架匹配,则判断所述经验UT代码位置指示信息所指示的位置对应的所述UT代码中 是否存在所述有效性测试特征,
    若所述经验UT代码位置指示信息所指示的位置对应的所述UT代码中存在所述有效性测试特征,则当所述前一有效性测试结果指示所述前一版本源代码的所述UT代码通过有效性测试时,所述当前有效性测试结果指示所述当前版本源代码通过有效性测试。
PCT/CN2019/103760 2019-05-22 2019-08-30 代码有效性测试方法、计算设备及存储介质 WO2020232906A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910430120.8 2019-05-22
CN201910430120.8A CN110309054B (zh) 2019-05-22 2019-05-22 代码有效性测试方法、计算设备及存储介质

Publications (1)

Publication Number Publication Date
WO2020232906A1 true WO2020232906A1 (zh) 2020-11-26

Family

ID=68074814

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/103760 WO2020232906A1 (zh) 2019-05-22 2019-08-30 代码有效性测试方法、计算设备及存储介质

Country Status (2)

Country Link
CN (1) CN110309054B (zh)
WO (1) WO2020232906A1 (zh)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102147764A (zh) * 2010-02-08 2011-08-10 微软公司 测试代码质量评估
US20150370685A1 (en) * 2014-06-24 2015-12-24 Juergen Heymann Defect localization in software integration tests
CN105512021A (zh) * 2014-09-25 2016-04-20 阿里巴巴集团控股有限公司 用于软件测试的Diff分析方法及装置
CN108197036A (zh) * 2018-02-06 2018-06-22 百度在线网络技术(北京)有限公司 用于确定增量代码的覆盖率信息的方法和装置

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103164335B (zh) * 2011-12-19 2016-04-20 阿里巴巴集团控股有限公司 检查单元测试质量的方法和系统
CN109643272B (zh) * 2016-06-29 2023-03-28 新思科技有限公司 用于自动http测试的测试系统及方法
CN106326122B (zh) * 2016-08-23 2018-08-31 北京精密机电控制设备研究所 一种软件单元测试用例管理系统

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102147764A (zh) * 2010-02-08 2011-08-10 微软公司 测试代码质量评估
US20150370685A1 (en) * 2014-06-24 2015-12-24 Juergen Heymann Defect localization in software integration tests
CN105512021A (zh) * 2014-09-25 2016-04-20 阿里巴巴集团控股有限公司 用于软件测试的Diff分析方法及装置
CN108197036A (zh) * 2018-02-06 2018-06-22 百度在线网络技术(北京)有限公司 用于确定增量代码的覆盖率信息的方法和装置

Also Published As

Publication number Publication date
CN110309054A (zh) 2019-10-08
CN110309054B (zh) 2021-08-31

Similar Documents

Publication Publication Date Title
US9898387B2 (en) Development tools for logging and analyzing software bugs
US9158514B2 (en) Method and apparatus for providing change-related information
TWI571737B (zh) 軟體測試系統、方法及其非暫態電腦可讀取紀錄媒體
US8370799B2 (en) Provision of code base modification using automatic learning of code changes
US20150370690A1 (en) Development tools for refactoring computer code
US10169214B2 (en) Testing of combined code changesets in a software product
JP2019114158A (ja) カバレッジテスト支援装置およびカバレッジテスト支援方法
US9032339B2 (en) Ranking verification results for root cause analysis
JP6090327B2 (ja) ボトルネック検出装置、方法及びプログラム
Feitosa et al. Investigating the effect of design patterns on energy consumption
JP6342129B2 (ja) 混合モードプログラムのソースコードエラー位置検出装置及び方法
US20110145799A1 (en) Path-sensitive dataflow analysis including path refinement
CN102902906A (zh) 微处理器指令集验证方法
CN112925524A (zh) 一种检测驱动程序中不安全直接存储器访问的方法及装置
US9842044B2 (en) Commit sensitive tests
US20120173498A1 (en) Verifying Correctness of a Database System
US10380313B1 (en) Implementation and evaluation of designs for heterogeneous computing platforms with hardware acceleration
US20050262399A1 (en) Aggregating and prioritizing failure signatures by a parsing program
US8850407B2 (en) Test script generation
CN110928786B (zh) 针对财务程序的测试方法和装置
JP2016149123A (ja) 未知のバイナリモジュールのための有効な入力を決定する方法及び非一時的なコンピュータ可読媒体
WO2020232906A1 (zh) 代码有效性测试方法、计算设备及存储介质
US20180173735A1 (en) System and method for dynamically estimating data classification job progress and execution time
US20210318946A1 (en) Generation of code coverage information during testing of a code sequence
US20040123072A1 (en) Method and system for modeling non-interlocked diversely bypassed exposed pipeline processors for static scheduling

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: 19930027

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 19930027

Country of ref document: EP

Kind code of ref document: A1