[go: up one dir, main page]

CN114116505B - Code testing method and device - Google Patents

Code testing method and device Download PDF

Info

Publication number
CN114116505B
CN114116505B CN202111457312.1A CN202111457312A CN114116505B CN 114116505 B CN114116505 B CN 114116505B CN 202111457312 A CN202111457312 A CN 202111457312A CN 114116505 B CN114116505 B CN 114116505B
Authority
CN
China
Prior art keywords
code
unit test
modification
test case
unit
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202111457312.1A
Other languages
Chinese (zh)
Other versions
CN114116505A (en
Inventor
赵硕
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Dajia Internet Information Technology Co Ltd
Original Assignee
Beijing Dajia Internet Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Dajia Internet Information Technology Co Ltd filed Critical Beijing Dajia Internet Information Technology Co Ltd
Priority to CN202111457312.1A priority Critical patent/CN114116505B/en
Publication of CN114116505A publication Critical patent/CN114116505A/en
Application granted granted Critical
Publication of CN114116505B publication Critical patent/CN114116505B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Prevention of errors by analysis, debugging or testing of software
    • G06F11/3668Testing of software
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Prevention of errors by analysis, debugging or testing of software
    • G06F11/3668Testing of software
    • G06F11/3672Test management
    • G06F11/3688Test 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

本公开提供了一种代码测试方法及装置。所述代码测试方法包括:获取代码测试信息,并将所述代码测试信息划分为若干单元测试用例;确定所述若干单元测试用例所用于测试的代码是否有修改;若所述若干单元测试用例中的至少一个单元测试用例所用于测试的代码有修改,则使用所述至少一个单元测试用例进行独立用例测试;若所述至少一个单元测试用例的独立用例测试通过,则确定不进行代码测试。

The present disclosure provides a code testing method and device. The code testing method includes: obtaining code testing information, and dividing the code testing information into a number of unit test cases; determining whether the code used for testing the several unit test cases has been modified; if the code used for testing at least one unit test case among the several unit test cases has been modified, using the at least one unit test case to perform an independent case test; if the independent case test of the at least one unit test case passes, determining not to perform code testing.

Description

Code testing method and device
Technical Field
The present disclosure relates generally to the field of electronics, and more particularly, to a code testing method and apparatus.
Background
After each code change (for example, a developer modifies the code), the modified code needs to be tested by using a full unit test Case, if all unit test cases pass through, the modified code is not problematic, and if the unit test cases fail to execute, the modified code is problematic. By testing the modified code in the code testing mode, whether the modified code has problems can be determined, but because all the codes need to be completely tested in each test, even if the codes are slightly modified and adjusted, more time is required to be spent for testing.
Disclosure of Invention
An exemplary embodiment of the present disclosure is to provide a code testing method and apparatus to solve at least the above-mentioned problems in the related art. The technical scheme of the present disclosure is as follows:
According to a first aspect of the disclosed embodiments, a code testing method is provided, which includes obtaining code testing information, dividing the code testing information into a plurality of unit testing cases, determining whether codes used for testing by the unit testing cases are modified, if the codes used for testing by at least one unit testing case in the unit testing cases are modified, using the at least one unit testing case to conduct independent case testing, and if the independent case testing of the at least one unit testing case is passed, determining that the code testing is not conducted.
Optionally, the step of determining whether the code used for testing by the plurality of unit test cases is modified includes determining a class file associated with each unit test case in the plurality of unit test cases in a class file of the code after modification, determining a class file corresponding to the code part modified at this time, determining a unit test case associated with the class file corresponding to the code part modified at this time according to the class file associated with each unit test case, and taking the determined unit test case as the at least one unit test case modified by the code used for testing.
Optionally, determining the class file associated with each unit test case in the class file of the code after the modification includes determining a method call chain of the code after the modification, wherein the method call chain is used for representing a call relationship among a plurality of methods abstracted by the code after the modification, and determining the class file associated with each unit test case according to the method required to be called by each unit test case and the method call chain of the code after the modification.
Optionally, the step of determining the method call chain of the modified code comprises determining the method call chain of the modified code according to the abstract syntax tree of the modified code.
Optionally, determining the class file associated with each unit test case according to the method required to be called by each unit test case and the method call chain of the code after the modification comprises determining, for each unit test case, the method call chain to which the method required to be called by the unit test case belongs from the method call chain of the code after the modification, and determining the class file corresponding to the method call chain as the class file associated with the unit test case, wherein the class file corresponding to the method call chain is the class file in which the class included by the method call chain is located.
Optionally, determining the class file associated with each unit test case in the class file of the code after the modification includes traversing the class file of the code after the modification by a byte code analysis mode for each unit test case, and determining the class file of the method of which the content relates to the unit test case needs to be called as the class file associated with the unit test case.
Optionally, the step of determining the unit test cases associated with the class file corresponding to the code portion modified at this time according to the class file associated with each unit test case includes determining the unit test cases having the corresponding relationship with the class file corresponding to the code portion modified at this time as the unit test cases associated with the class file corresponding to the code portion modified at this time according to the corresponding relationship between each unit test case and the class file associated with each unit test case.
Optionally, the code testing method further comprises determining that the modification of the code used for testing by the at least one unit test case is problematic if the independent case test of the at least one unit test case fails.
According to a second aspect of the embodiments of the present disclosure, a code testing device is provided, which includes a unit test obtaining unit configured to obtain code test information and divide the code test information into a plurality of unit test cases, a modification determining unit configured to determine whether codes used for testing by the plurality of unit test cases are modified, an independent case testing unit configured to use at least one unit test case of the plurality of unit test cases to perform independent case testing if the codes used for testing by the at least one unit test case are modified, and a determining unit configured to determine not to perform code testing if the independent case testing of the at least one unit test case is passed.
Optionally, the modification determining unit is configured to determine a class file associated with each unit test case in the plurality of unit test cases in the class file of the code after the modification, determine a class file corresponding to the code portion of the modification, determine a unit test case associated with the class file corresponding to the code portion of the modification according to the class file associated with each unit test case, and take the determined unit test case as the at least one unit test case modified by the code used for testing.
Optionally, the modification determining unit is configured to determine a method call chain of the code after the modification, and determine a class file associated with each unit test case according to a method required to be called by each unit test case and the method call chain of the code after the modification, wherein the method call chain is used for representing a call relation among a plurality of methods abstracted by the code after the modification.
Optionally, the modification determining unit is configured to determine a method call chain of the code after the modification according to the abstract syntax tree of the code after the modification.
Optionally, the modification determining unit is configured to determine, for each unit test case, a method call chain to which a method to be called by the unit test case belongs from a method call chain of the code after the modification, and determine a class file corresponding to the method call chain to be a class file associated with the unit test case, where the class file corresponding to the method call chain is a class file in which a class included in the method call chain is located.
Optionally, the modification determining unit is configured to traverse the class file of the code modified this time by means of byte code analysis for each unit test case, and determine the class file of the method whose content relates to the unit test case to be called as the class file associated with the unit test case.
Optionally, the modification determining unit is configured to determine, as the unit test cases associated with the class file corresponding to the code portion modified at this time, the unit test cases having the correspondence with the class file corresponding to the code portion modified at this time according to the correspondence between each unit test case and the class file associated therewith.
Optionally, the determining unit is configured to determine that there is a problem with modification of the code for which the at least one unit test case is used if the independent case test of the at least one unit test case fails.
According to a third aspect of embodiments of the present disclosure, there is provided an electronic device comprising at least one processor, at least one memory storing computer executable instructions, wherein the computer executable instructions, when executed by the at least one processor, cause the at least one processor to perform a code testing method as described above.
According to a fourth aspect of embodiments of the present disclosure, there is provided a computer-readable storage medium, which when executed by at least one processor, causes the at least one processor to perform the code testing method as described above.
According to a fifth aspect of embodiments of the present disclosure, there is provided a computer program product comprising computer instructions which, when executed by at least one processor, implement a code testing method as described above.
According to the code testing method and device of the exemplary embodiment of the disclosure, the independent Case test is performed by using at least one unit test Case with the modified code used for the test, namely, only the unit test Case associated with the code part modified at this time is executed, and the code modified at this time is tested, so that whether the modified code has a problem or not can be effectively determined, the execution quantity of unit test Case cases can be effectively reduced, and the efficiency of the code test is improved.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the disclosure and together with the description, serve to explain the principles of the disclosure and do not constitute an undue limitation on the disclosure.
FIG. 1 illustrates a flow chart of a code testing method according to an exemplary embodiment of the present disclosure;
FIG. 2 illustrates a flowchart of a method of determining whether code for which a number of unit test cases are used for testing is modified, according to an example embodiment of the present disclosure;
FIG. 3 illustrates a block diagram of a code testing apparatus according to an exemplary embodiment of the present disclosure;
Fig. 4 shows a block diagram of an electronic device according to an exemplary embodiment of the present disclosure.
Detailed Description
In order to enable those skilled in the art to better understand the technical solutions of the present disclosure, the technical solutions of the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings.
It should be noted that the terms "first," "second," and the like in the description and claims of the present disclosure and in the foregoing figures are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate such that the embodiments of the disclosure described herein may be capable of operation in sequences other than those illustrated or described herein. The implementations described in the following exemplary examples are not representative of all implementations consistent with the present disclosure. Rather, they are merely examples of apparatus and methods consistent with some aspects of the present disclosure as detailed in the accompanying claims.
It should be noted that, in this disclosure, "at least one of the items" refers to a case where three types of juxtaposition including "any one of the items", "a combination of any of the items", "an entirety of the items" are included. For example, "comprising at least one of A and B" includes the case of juxtaposition of three of (1) comprising A, (2) comprising B, and (3) comprising A and B. For example, "at least one of the first and second steps is executed", that is, three cases are shown in parallel, namely (1) execute the first step, (2) execute the second step, and (3) execute the first and second steps.
Fig. 1 illustrates a flowchart of a code testing method according to an exemplary embodiment of the present disclosure.
Referring to fig. 1, in step S101, code test information is acquired and divided into a plurality of unit test cases.
As an example, the code test information is information for testing the object code, for example, information for verifying whether the object code has a problem or not and whether a desired function can be implemented.
Case, unit test Case, a method (function) to achieve simple function, tests whether a certain code block is functioning properly with a set of specific inputs, and returns the correct output.
In step S102, it is determined whether the code used for testing by the unit test cases has been modified.
As an example, the code testing method according to an exemplary embodiment of the present disclosure may further include determining the code portion of the current modification.
The code part modified at this time is a part different from the original code in the code modified at this time. The original code is the basis of the current modification, and the current modification is performed based on the original code. The modified code can be the modified engineering source code.
As an example, the code portion of the present modification may be determined in an appropriate manner, which is not limited by the present disclosure. For example, MR Diff may be generated using a git tool, specifically, the git tool may compare the difference between the current modified code and the original code, and then give a Diff file including code change information, where the Diff file is in text format, and in which lines of codes are modified according to a specific format, and the current modified code portion may be analyzed by parsing the file.
MR (Merge Request), a development mode of a code management tool, if a developer needs to merge into a target code branch after modifying a code, the developer needs to provide an MR for others to review, and the developer can only merge after the review is finished. The code in the target code branch is the original unmodified code, the code modified for the original unmodified code is in the MR, and the original code becomes the modified code in the MR after the MR is combined with the target code branch. As an example, a code testing method according to an exemplary embodiment of the present disclosure may be performed before the MR is reviewed by others.
As an example, when at least one unit test case for testing the code portion modified at this time (for example, testing a function related to the code portion modified at this time) exists in the plurality of unit test cases, that is, when the code used for testing by the at least one unit test case is modified, it may be determined that the code used for testing by the plurality of unit test cases is modified.
As an example, a unit test case associated with a class file corresponding to the code portion of the current modification (i.e., the class file of the current modification) may be determined from the plurality of unit test cases, and the determined unit test case may be used as the at least one unit test case for which the code for the test has modification.
With respect to class files, a class is a concept in code that is written in a file, and thus, one file may contain one or more classes, i.e., a file containing a class.
The class file corresponding to the code part modified at this time is the class file modified at this time determined according to the code part modified at this time, namely the class file related to the code part modified at this time. The modified class file, that is, the file corresponding to the modified class, for example, one class file may be changed by only a few lines, and the modified class file may be referred to as a file corresponding to the modified class.
For example, the current modified class file may be analyzed based on the current MR Diff.
An exemplary embodiment of step S102 will be described below in conjunction with fig. 2.
If it is determined in step S102 that the code used for testing by at least one of the plurality of unit test cases is modified, step S103 is executed, and an independent case test is performed using the at least one unit test case. To determine whether the current modified code has problems.
In step S104, if the independent case test of the at least one unit test case passes, it is determined that the code test is not performed.
As an example, if the independent case test of the at least one unit test case passes, it is determined that the code modified this time has no problem, so it is determined that the full-scale code test is not required.
The unit test is a test method for codes in software engineering, and can be understood as running the set of cases, the case execution is free of problems, the case execution is failed, and the object of the case execution is Apk files compiled by all modified source codes.
In fact, the present disclosure considers that the code is tested after the initial completion or after each subsequent modification, and is applied after the test is passed, so that the portion of the original code that is not modified is tested before the test, and the portion of the original code that is not modified is passed, and the repeated test is not required. The method and the device can only use the corresponding unit test cases for the code part modified at this time to carry out independent case test, namely, only test the functions related to the code part modified at this time, so that whether the code modified at this time has problems or not can be effectively determined, omission does not occur, and the test time is saved.
By way of example, the code testing method according to the exemplary embodiment of the present disclosure may further include determining that the current modification of the code portion for which the at least one unit test case is used is problematic if the independent case test of the at least one unit test case fails.
FIG. 2 illustrates a flowchart of a method of determining whether code used by the unit test cases for testing is modified according to an exemplary embodiment of the present disclosure.
Referring to fig. 2, in step S201, a class file associated with each of the unit test cases in the plurality of unit test cases in the class file of the code modified at this time is determined.
In one embodiment, step S201 may include determining a method call chain of the code after the current modification, and then determining a class file associated with each unit test case according to a method required to be called by each unit test case and the method call chain of the code after the current modification. The method call chain is used for representing call relations among a plurality of methods into which the code after the modification is abstracted.
As an example, a method call chain of the code after the modification can be determined according to an abstract syntax tree of the code after the modification. That is, a method call chain of the code can be analyzed according to an abstract syntax tree of the code, which is equivalent to abstracting the code into one method, and the code relation is that one method calls another method, so that a call chain is connected in series.
For each unit test case, a method call chain to which a method to be called by the unit test case belongs is determined from a method call chain of the code modified at this time, and a class file corresponding to the method call chain is determined as a class file associated with the unit test case.
The class file corresponding to the method call chain is the class file in which the class included in the method call chain is located.
In other words, the class file affected by the Case can be found according to the method call relation of the Case and the method call chain of the code, which call chain the method called in the Case belongs to can be understood as traversing the loop to judge, and which class the call chain has, so that the class file specifically affected is found.
In another embodiment, step S201 may include traversing the class file of the code modified this time by way of byte code analysis for each unit test case, and determining the class file of the method whose content relates to the unit test case to be called as the class file associated with the unit test case.
The bytecode analysis may scan the structured code file for the data needed therein, which in this embodiment amounts to traversing all class files to see which class file content includes identification information (e.g., name) of a certain method contained in the case.
In step S202, a class file corresponding to the code portion modified this time is determined.
In step S203, according to the class file associated with each unit test case, determining the unit test case associated with the class file corresponding to the code part modified at this time, and taking the determined unit test case as the at least one unit test case modified by the code used for testing.
As an example, a unit test case having a correspondence relationship with a class file corresponding to the code portion of the present modification may be determined as a unit test case associated with a class file corresponding to the code portion of the present modification according to a correspondence relationship (e.g., a mapping relationship) between each unit test case and the class file associated therewith.
For example, according to the method called in the method call chain and the case, which class file is affected by the case is judged, the mapping relation between the case and the class file is obtained, and then according to the class file corresponding to the code part modified at this time, the associated case is obtained through the mapping relation.
According to the exemplary embodiment of the disclosure, the correlation between the unit test Case and the class file can be automatically analyzed, and the unit test Case most relevant to the modification is calculated according to the MR Diff, so that the correlation between the unit test Case and the MR Diff is improved, the execution quantity of the cases is reduced, and the automatic test efficiency is improved.
Fig. 3 illustrates a block diagram of a code testing apparatus according to an exemplary embodiment of the present disclosure.
As shown in fig. 3, the code testing apparatus 10 according to the exemplary embodiment of the present disclosure includes a unit test acquisition unit 101, a modification determination unit 102, an independent use case test unit 103, and a determination unit 104.
Specifically, the unit test acquisition unit 101 is configured to acquire code test information and divide the code test information into a number of unit test cases.
The modification determination unit 102 is configured to determine whether the code for which the unit test cases are used for testing is modified.
The independent case test unit 103 is configured to perform independent case test by using at least one unit test case of the plurality of unit test cases if the code used for the test by the at least one unit test case is modified.
The determining unit 104 is configured to determine not to perform the code test if the independent case test of the at least one unit test case passes.
As an example, the modification determination unit 102 may be configured to determine a class file associated with each of the plurality of unit test cases in the class file of the code after the current modification, determine a class file corresponding to the code portion of the current modification, determine a unit test case associated with the class file corresponding to the code portion of the current modification according to the class file associated with each unit test case, and take the determined unit test case as the at least one unit test case for which the code used for the test has modification.
As an example, the modification determining unit 102 may be configured to determine a method call chain of the code after the modification, and determine a class file associated with each unit test case according to a method required to be called by each unit test case and the method call chain of the code after the modification, where the method call chain is used to represent a call relationship between a plurality of methods to which the code after the modification is abstracted.
As an example, the modification determining unit 102 may be configured to determine a method call chain of the current modified code according to an abstract syntax tree of the current modified code.
As an example, the modification determining unit 102 may be configured to determine, for each unit test case, a method call chain to which a method to be called by the unit test case belongs from a method call chain of the code modified this time, and determine a class file corresponding to the method call chain to be a class file associated with the unit test case, where the class file corresponding to the method call chain is a class file in which a class included in the method call chain is located.
As an example, the modification determination unit 102 may be configured to traverse the class file of the code modified this time by way of bytecode analysis for each unit test case, and determine the class file whose content relates to the method that the unit test case needs to call as the class file associated with the unit test case.
As an example, the modification determining unit 102 may be configured to determine, as the unit test cases associated with the class file corresponding to the code portion of the present modification, the unit test cases having a correspondence relationship with the class file corresponding to the code portion of the present modification according to the correspondence relationship between each unit test case and the class file associated therewith.
As an example, the determining unit 104 may be configured to determine that there is a problem with modification of the code for which the at least one unit test case is used if the independent case test of the at least one unit test case fails.
With respect to the code testing device 10 in the above-described embodiment, the specific manner in which the respective units perform the operations has been described in detail in the embodiment regarding the method, and will not be described in detail here.
Furthermore, it should be understood that the various units in the code testing apparatus 10 according to the exemplary embodiments of the present disclosure may be implemented as hardware components and/or software components. The individual units may be implemented, for example, using a Field Programmable Gate Array (FPGA) or an Application Specific Integrated Circuit (ASIC), depending on the processing performed by the individual units as defined.
Fig. 4 shows a block diagram of an electronic device according to an exemplary embodiment of the present disclosure. Referring to fig. 4, the electronic device 20 includes at least one memory 201 and at least one processor 202, the at least one memory 201 having stored therein a set of computer-executable instructions that, when executed by the at least one processor 202, perform the code testing method as described in the above-described exemplary embodiments.
By way of example, the electronic device 20 may be a PC computer, tablet device, personal digital assistant, smart phone, or other device capable of executing the above-described set of instructions. Here, the electronic device 20 is not necessarily a single electronic device, but may be any apparatus or a collection of circuits capable of executing the above-described instructions (or instruction sets) individually or in combination. The electronic device 20 may also be part of an integrated control system or system manager, or may be configured as a portable electronic device that interfaces with either locally or remotely (e.g., via wireless transmission).
In electronic device 20, processor 202 may include a Central Processing Unit (CPU), a Graphics Processor (GPU), a programmable logic device, a special purpose processor system, a microcontroller, or a microprocessor. By way of example, and not limitation, processor 202 may also include an analog processor, a digital processor, a microprocessor, a multi-core processor, a processor array, a network processor, and the like.
The processor 202 may execute instructions or code stored in the memory 201, wherein the memory 201 may also store data. The instructions and data may also be transmitted and received over a network via a network interface device, which may employ any known transmission protocol.
The memory 201 may be integrated with the processor 202, for example, RAM or flash memory disposed within an integrated circuit microprocessor or the like. In addition, the memory 201 may include a stand-alone device, such as an external disk drive, a storage array, or other storage device usable by any database system. The memory 301 and the processor 202 may be operatively coupled or may communicate with each other, such as through an I/O port, network connection, etc., such that the processor 202 is able to read files stored in the memory.
In addition, the electronic device 20 may also include a video display (such as a liquid crystal display) and a user interaction interface (such as a keyboard, mouse, touch input device, etc.). All components of the electronic device 20 may be connected to each other via a bus and/or a network.
According to an exemplary embodiment of the present disclosure, there may also be provided a computer-readable storage medium storing instructions, wherein the instructions, when executed by at least one processor, cause the at least one processor to perform the code testing method as described in the above exemplary embodiments. Examples of computer readable storage media herein include read-only memory (ROM), random-access programmable read-only memory (PROM), electrically erasable programmable read-only memory (EEPROM), random-access memory (RAM), dynamic random-access memory (DRAM), static random-access memory (SRAM), flash memory, nonvolatile 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, blu-ray or optical disk memory, hard Disk Drive (HDD), solid State Disk (SSD), card memory (such as a multimedia card, secure Digital (SD) card or ultra-fast digital (XD) card), magnetic tape, floppy disk, magneto-optical data storage device, hard disk, solid state disk, and any other device configured to non-temporarily store a computer program and any associated data, data files and data structures and to cause the computer program and any associated data, data file and data structures to be provided to a processor or processor to execute the computer program. The computer programs in the computer readable storage media described above can be run in an environment deployed in a computer device, such as a client, host, proxy device, server, etc., and further, in one example, the computer programs and any associated data, data files, and data structures are distributed across networked computer systems such that the computer programs and any associated data, data files, and data structures are stored, accessed, and executed in a distributed fashion by one or more processors or computers.
According to an exemplary embodiment of the present disclosure, a computer program product may also be provided, instructions in which are executable by at least one processor to perform the code testing method as described in the above exemplary embodiment.
Other embodiments of the disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the disclosure disclosed herein. This application is intended to cover any adaptations, uses, or adaptations of the disclosure following, in general, the principles of the disclosure and including such departures from the present disclosure as come within known or customary practice within the art to which the disclosure pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the disclosure being indicated by the following claims.
It is to be understood that the present disclosure is not limited to the precise arrangements and instrumentalities shown in the drawings, and that various modifications and changes may be effected without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims (15)

1. A code testing method, comprising:
Code test information is obtained and divided into a plurality of unit test cases;
Determining whether codes used for testing by the unit test cases are modified or not;
If the code used for testing by at least one unit test case in the unit test cases is modified, using the at least one unit test case to perform independent case testing;
If the independent case test of the at least one unit test case passes, determining that the code test is not performed;
The step of determining whether the code used for testing by the unit test cases is modified comprises the following steps:
Determining class files associated with each unit test case in the unit test cases in the class files of the code after the modification;
Determining a class file corresponding to the modified code part;
According to the class file associated with each unit test case, determining the unit test case associated with the class file corresponding to the code part modified at this time, and taking the determined unit test case as the at least one unit test case with the modified code used for testing;
The step of determining the class file associated with each unit test case in the class file of the code after the modification comprises the following steps:
determining a method call chain of the code after the modification, wherein the method call chain is used for representing call relations among a plurality of methods which are abstracted by the code after the modification;
And determining class files associated with each unit test case according to the method required to be called by each unit test case and the method call chain of the code after the modification.
2. The code testing method according to claim 1, wherein the step of determining a method call chain of the code after the current modification includes:
And determining a method call chain of the code after the modification according to the abstract syntax tree of the code after the modification.
3. The code testing method according to claim 1, wherein the step of determining the class file associated with each unit test case according to the method required to be invoked by each unit test case and the method call chain of the code after the current modification includes:
Determining a method call chain to which a method to be called by the unit test case belongs from a method call chain of the code modified at this time aiming at each unit test case;
the class files corresponding to the method call chains are class files in which the classes included in the method call chains are located.
4. The code testing method according to claim 1, wherein the step of determining a class file associated with each unit test case in the class file of the code after the current modification further comprises:
traversing the class file of the code after the modification by a byte code analysis mode aiming at each unit test case, and determining the class file of a method of which the content relates to the unit test case and needs to be called as the class file associated with the unit test case.
5. The code testing method according to claim 1, wherein the step of determining the unit test cases associated with the class file corresponding to the code portion modified at this time based on the class file associated with each unit test case comprises:
And determining the unit test cases with the corresponding relation with the class files corresponding to the code parts modified at this time as the unit test cases associated with the class files corresponding to the code parts modified at this time according to the corresponding relation between each unit test case and the class files associated with each unit test case.
6. The code testing method of claim 1, wherein the code testing method further comprises:
If the independent case test of the at least one unit test case fails, determining that the modification of the code used for the test by the at least one unit test case is problematic.
7. A code testing apparatus, comprising:
the unit test acquisition unit is configured to acquire code test information and divide the code test information into a plurality of unit test cases;
a modification determining unit configured to determine whether the code used for the test by the unit test cases is modified;
The independent case test unit is configured to use at least one unit test case in the plurality of unit test cases to perform independent case test if the code used for the test is modified;
A determining unit configured to determine not to perform the code test if the independent case test of the at least one unit test case passes;
The modification determining unit is configured to determine a class file associated with each unit test case in the plurality of unit test cases in the class file of the code after the modification, determine a class file corresponding to the code part of the modification, determine the unit test case associated with the class file corresponding to the code part of the modification according to the class file associated with each unit test case, and take the determined unit test case as the at least one unit test case with the modification of the code used for the test;
The method comprises a modification determining unit, a modification determining unit and a processing unit, wherein the modification determining unit is configured to determine a method call chain of a code after the modification, and determine class files associated with each unit test case according to a method required to be called by each unit test case and the method call chain of the code after the modification, and the method call chain is used for representing call relations among a plurality of methods abstracted by the code after the modification.
8. The code testing apparatus according to claim 7, wherein the modification determining unit is configured to determine the method call chain of the code after the current modification based on an abstract syntax tree of the code after the current modification.
9. The code testing device according to claim 7, wherein the modification determining unit is configured to determine, for each unit test case, a method call chain to which a method to be called by the unit test case belongs from method call chains of the code modified this time;
the class files corresponding to the method call chains are class files in which the classes included in the method call chains are located.
10. The code testing device of claim 7, wherein the modification determining unit is further configured to traverse the class file of the code after the modification by means of byte code analysis for each unit test case, and determine the class file of the method whose content relates to the unit test case needs to be called as the class file associated with the unit test case.
11. The code testing device of claim 7, wherein the modification determining unit is configured to determine, as the unit test cases associated with the class file corresponding to the code portion of the present modification, the unit test cases having the correspondence with the class file corresponding to the code portion of the present modification according to the correspondence between each unit test case and the class file associated therewith.
12. The code testing apparatus according to claim 7, wherein the determining unit is configured to determine that there is a problem with modification of the code for which the at least one unit test case is used if the independent case test of the at least one unit test case fails.
13. An electronic device, comprising:
at least one processor;
at least one memory storing computer-executable instructions,
Wherein the computer executable instructions, when executed by the at least one processor, cause the at least one processor to perform the code testing method of any of claims 1 to 6.
14. A computer-readable storage medium, wherein instructions in the computer-readable storage medium, when executed by at least one processor, cause the at least one processor to perform the code testing method of any of claims 1 to 6.
15. A computer program product comprising computer instructions which, when executed by at least one processor, implement the code testing method of any one of claims 1 to 6.
CN202111457312.1A 2021-12-02 2021-12-02 Code testing method and device Active CN114116505B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111457312.1A CN114116505B (en) 2021-12-02 2021-12-02 Code testing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111457312.1A CN114116505B (en) 2021-12-02 2021-12-02 Code testing method and device

Publications (2)

Publication Number Publication Date
CN114116505A CN114116505A (en) 2022-03-01
CN114116505B true CN114116505B (en) 2025-02-28

Family

ID=80369558

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111457312.1A Active CN114116505B (en) 2021-12-02 2021-12-02 Code testing method and device

Country Status (1)

Country Link
CN (1) CN114116505B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115269443A (en) * 2022-09-29 2022-11-01 中邮消费金融有限公司 Software defect automatic positioning test method and system
CN115905031B (en) * 2023-03-14 2023-06-23 云筑信息科技(成都)有限公司 Test case recommendation method based on accurate quality assurance system

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112445692A (en) * 2019-08-27 2021-03-05 腾讯科技(深圳)有限公司 Case testing method and terminal
CN113127357A (en) * 2021-04-21 2021-07-16 北京百度网讯科技有限公司 Unit testing method, device, equipment, storage medium and program product

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10394697B2 (en) * 2017-05-15 2019-08-27 International Business Machines Corporation Focus area integration test heuristics
CN111045944B (en) * 2019-12-11 2023-06-13 广州品唯软件有限公司 Regression testing method, device, system and computer-readable storage medium

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112445692A (en) * 2019-08-27 2021-03-05 腾讯科技(深圳)有限公司 Case testing method and terminal
CN113127357A (en) * 2021-04-21 2021-07-16 北京百度网讯科技有限公司 Unit testing method, device, equipment, storage medium and program product

Also Published As

Publication number Publication date
CN114116505A (en) 2022-03-01

Similar Documents

Publication Publication Date Title
US9201632B2 (en) Systems and methods for incremental software development
US9047402B2 (en) Automatic calculation of orthogonal defect classification (ODC) fields
US9594553B2 (en) Identifying semantic differences between source code versions
US8386851B2 (en) Functional coverage using combinatorial test design
Chen et al. Extracting and studying the Logging-Code-Issue-Introducing changes in Java-based large-scale open source software systems
US20210026756A1 (en) Deriving software application dependency trees for white-box testing
JP2015507303A (en) Code coverage rate determination method and system
US8516505B2 (en) Cross-platform compatibility framework for computer applications
US20050125776A1 (en) Determining the possibility of adverse effects arising from a code change
US20080276225A1 (en) Testing Executable Logic
CN112765017A (en) Data query performance test method and device based on MySQL database
CN114116505B (en) Code testing method and device
US20070250815A1 (en) Measuring code coverage
JP2015011372A (en) Debug support system, method, program, and recording medium
CN112419057A (en) Method, device, equipment and storage medium for generating and storing logs of intelligent contracts
CN112035367B (en) Method and system for checking workflow correctness of big data platform
CN111694729A (en) Application testing method and device, electronic equipment and computer readable medium
CN111240987A (en) Migration program detection method and device, electronic equipment and computer readable storage medium
US9009666B1 (en) Systems and methods for testing software and for storing and tracking test assets with the software
US11726901B2 (en) Continuous testing and dependency tracking for java virtual machines
US10481969B2 (en) Configurable system wide tests
CN116991751B (en) Code testing method and device, electronic equipment and storage medium
US20200167152A1 (en) Identification of a partial code to be refactored within a source code
US20220107825A1 (en) Measuring the Memory Usage of Java Programs
US7886137B1 (en) Template-based BIOS project creation

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