CN113220560A - Code testing method and device, electronic equipment and storage medium - Google Patents

Code testing method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN113220560A
CN113220560A CN202010072030.9A CN202010072030A CN113220560A CN 113220560 A CN113220560 A CN 113220560A CN 202010072030 A CN202010072030 A CN 202010072030A CN 113220560 A CN113220560 A CN 113220560A
Authority
CN
China
Prior art keywords
flow
code
test
file
tested
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.)
Pending
Application number
CN202010072030.9A
Other languages
Chinese (zh)
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.)
Baidu Online Network Technology Beijing Co Ltd
Beijing Baidu Netcom Science and Technology Co Ltd
Original Assignee
Beijing Baidu Netcom Science and 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 Baidu Netcom Science and Technology Co Ltd filed Critical Beijing Baidu Netcom Science and Technology Co Ltd
Priority to CN202010072030.9A priority Critical patent/CN113220560A/en
Publication of CN113220560A publication Critical patent/CN113220560A/en
Pending legal-status Critical Current

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

Abstract

The application discloses a code testing method and device, electronic equipment and a storage medium, and relates to a software testing technology. The specific implementation scheme is as follows: acquiring coverage rate test data of a previous test aiming at a tested code in the current test aiming at the tested code; analyzing a code and flow relation file of the previous test according to the coverage test data of the previous test; matching the code and flow relation file of the previous test with a pre-stored code and flow relation file to obtain the dynamic flow of the previous test; and when the tested code is not changed, determining the target flow of the test according to the dynamic flow of the previous test and the minimum set of flows stored in advance, and testing the tested code by using the target flow of the test. The code coverage rate can be effectively improved, so that the code testing quality can be improved, and the input of labor cost and equipment cost is not required.

Description

Code testing method and device, electronic equipment and storage medium
Technical Field
The present application relates to the field of computer application technologies, and further relates to a software testing technology, and in particular, to a code testing method and apparatus, an electronic device, and a storage medium.
Background
Code Coverage (Code Coverage) is a measure in software testing, and describes the proportion and degree of source Code testing in a program, and the obtained proportion is called Code Coverage rate, and is an important index for measuring testing capability and testing integrity. In the existing code testing method, logs of a part of time period are selected randomly from 1-2 machines as testing flow, and because the testing flow is selected randomly, the testing flow may not be enough to evaluate the tested code, so that the problem of insufficient code coverage exists, and a larger online quality risk exists in continuous quick iteration. Therefore, the coverage of the code is improved, the coverage scene of the test can be further expanded, the code test quality is improved, the code loophole is carelessly leaked in advance, and the potential safety hazard on the line is intercepted.
Disclosure of Invention
In view of this, embodiments of the present disclosure provide a code testing method, apparatus, electronic device and storage medium, which can effectively improve code coverage, thereby improving code testing quality without investing labor cost and equipment cost.
In a first aspect, an embodiment of the present application provides a code testing method, where the method includes: acquiring coverage rate test data of a previous test aiming at a tested code in the current test aiming at the tested code;
analyzing a code and flow relation file of the previous test according to the coverage test data of the previous test;
matching the code and flow relation file of the previous test with a pre-stored code and flow relation file to obtain the dynamic flow of the previous test;
and when the tested code is not changed, determining the target flow of the test according to the dynamic flow of the previous test and a minimum set of prestored flows, and testing the tested code by using the target flow of the test.
The above embodiment has the following advantages or beneficial effects: in the embodiment, two basic data, namely the minimum flow set and the code and flow relation file, are predetermined for the case that the code to be tested does not change, and the dynamic flow of the previous test can be obtained by matching the code and flow relation file of the previous test with the pre-stored code and flow relation file in the current test, so that the target flow of the current test can be determined according to the dynamic flow of the previous test and the minimum flow set stored in advance in the current test, and then the code to be tested is tested by using the target flow of the current test, thereby achieving the purpose of improving the code coverage rate. In the existing code testing method, logs of partial time periods are selected from 1-2 machines at random as testing flow, and because the testing flow is selected at random, the testing flow may not be enough to evaluate the tested code, and the problem of insufficient code coverage exists. The method and the device adopt a technical means of predetermining the minimum set of the flow and the code-flow relation file, merge and duplicate the dynamic flow of the previous test and the minimum set of the flow stored in advance in the test to determine the target flow of the test, overcome the technical problem of insufficient code coverage rate in the prior art, and further achieve the technical effects of improving the code coverage rate and improving the code test quality.
In the above embodiment, the method further comprises:
when the code to be tested is changed, acquiring newly added flow corresponding to each changed function in the code to be tested in the prestored code and flow relation file; and determining the target flow of the current test according to the newly added flow corresponding to each changed function, the dynamic flow of the previous test and the minimum set of prestored flows, and testing the tested code by using the target flow of the current test.
The above embodiment has the following advantages or beneficial effects: in the embodiment, for the condition that the code to be tested changes, the target flow of the current test is determined according to the newly added flow corresponding to each changed function, the dynamic flow of the previous test and the minimum set of flows stored in advance, so that the code to be tested can be tested by using the target flow of the current test.
In the above embodiment, before the obtaining, in the current test for the code under test, coverage test data of a previous test for the code under test, the method further includes:
screening out a second amount of flow from the first amount of flow in the original flow word list according to each flow table entry in the original flow word list and an original module log of the tested code in each function module; wherein each flow table entry comprises: identification SID and parameter information of each flow;
dividing the second quantity of flow into N parts of flow, and respectively inputting the N parts of flow into N testing environments; acquiring code coverage Cov files corresponding to all flows through acquisition tasks in all test environments; merging Cov files corresponding to all flows into a full-flow Cov file; wherein N is a natural number greater than 1;
and calculating the pre-saved minimum flow set and the pre-saved code and flow relation file according to the full-flow Cov file.
The above embodiment has the following advantages or beneficial effects: through the embodiment, the two basic data of the minimum flow set and the code and flow relation file can be determined in advance before the test, and the code to be tested can be tested by using the two basic data in the test.
In the above embodiment, the calculating the minimum set of flows saved in advance according to the full-flow Cov file includes:
analyzing the coverage characteristic of each flow in the full-flow Cov file according to the SID of each flow in the full-flow Cov file;
writing each flow into a first type of flow file corresponding to the flow according to the coverage characteristic of each flow;
and carrying out duplicate removal on the flow in each first type flow file through the thread corresponding to each first type flow file, and combining duplicate removal results of each thread to obtain the minimum pre-stored flow set.
The above embodiment has the following advantages or beneficial effects: the embodiment may determine the minimum flow set in advance before the test, and the minimum flow set may be used to test the code to be tested in the test.
In the above embodiment, the calculating the pre-stored code and traffic relation file according to the full-traffic Cov file includes:
calculating the main key of the prestored code and flow relation file according to the code file name and the function name of the tested code in each functional module;
according to the pre-stored code and the main key of the flow relation file, calculating the coverage characteristic of each flow based on the full-flow Cov file under each main key;
mapping each flow into a second type flow file corresponding to each flow according to each primary key;
merging the traffic corresponding to the same primary key in each second-class traffic file, and merging the traffic in each second-class traffic file to obtain the pre-stored code and traffic relation file.
The above embodiment has the following advantages or beneficial effects: the above embodiment may determine the code and traffic relation file in advance before the test, and the code and traffic relation file may be used to test the code to be tested in the test.
In the above embodiment, the testing the code under test using the target traffic of the current test includes:
determining each switch combination state of the current test according to the logic switch corresponding to the code which is not changed in the tested code and the logic switch corresponding to the code which is changed in the tested code;
and testing the tested code by using the target flow of the current test under each switch combination state.
The above embodiment has the following advantages or beneficial effects: the above embodiment may determine the combination state of each switch, and in the test, the target flow rate of the test may be used to test the code to be tested in each switch combination state.
In the above embodiment, the testing the code under test using the target traffic of the current test includes:
constructing at least one word list data according to the predetermined test flow and a pre-stored original word list, and adding the at least one word list data to the original word list to obtain a target word list; updating the initial test environment of the current test by using the target word list;
or constructing at least one commodity material data according to a predetermined test flow and a pre-stored original database, and adding the at least one commodity material data to the original database to obtain a target database; updating the initial test environment of the test by using the target database;
and testing the tested code under the updated test environment by using the target flow of the test.
The above embodiment has the following advantages or beneficial effects: in the embodiment, the target vocabulary may be used to update the initial test environment of the test, or the target database may be used to update the initial test environment of the test, so that the target traffic of the test may be used to test the code under test in the updated test environment.
In a second aspect, the present application also provides a code testing apparatus, the apparatus including: the device comprises an acquisition module, an analysis module, a matching module and a test module; wherein the content of the first and second substances,
the acquisition module is used for acquiring coverage rate test data of a previous test aiming at a tested code in the current test aiming at the tested code;
the analysis module is used for analyzing the code and flow relation file of the previous test according to the coverage test data of the previous test;
the matching module is used for matching the code and flow relation file of the previous test with a pre-stored code and flow relation file to obtain the dynamic flow of the previous test;
and the test module is used for determining the target flow of the test according to the dynamic flow of the previous test and the minimum set of pre-stored flows when the tested code is not changed, and testing the tested code by using the target flow of the test.
In the above embodiment, the test module is further configured to, when the code to be tested changes, obtain, in the prestored code-flow relationship file, a newly added flow corresponding to each changed function in the code to be tested; and determining the target flow of the current test according to the newly added flow corresponding to each changed function, the dynamic flow of the previous test and the minimum set of prestored flows, and testing the tested code by using the target flow of the current test.
In the above embodiment, the apparatus further includes: the device comprises a screening module and a calculation module; wherein the content of the first and second substances,
the screening module is used for screening a second amount of flow from the first amount of flow in the original flow word list according to each flow table entry in the original flow word list and an original module log of the tested code in each function module; wherein each flow table entry comprises: identification SID and parameter information of each flow; dividing the second quantity of flow into N parts of flow, and respectively inputting the N parts of flow into N testing environments; acquiring code coverage Cov files corresponding to all flows through acquisition tasks in all test environments; merging Cov files corresponding to all flows into a full-flow Cov file; wherein N is a natural number greater than 1;
and the calculation module is used for calculating the pre-saved minimum set of flow and the pre-saved code and flow relation file according to the full-flow Cov file.
In the above embodiment, the calculation module is specifically configured to analyze, according to the SID of each traffic in the full-traffic Cov file, a coverage characteristic of each traffic in the full-traffic Cov file; writing each flow into a first type of flow file corresponding to the flow according to the coverage characteristic of each flow; and carrying out duplicate removal on the flow in each first type flow file through the thread corresponding to each first type flow file, and combining duplicate removal results of each thread to obtain the minimum pre-stored flow set.
In the above embodiment, the calculation module is specifically configured to calculate a primary key of the pre-stored code and flow relation file according to a code file name and a function name of the detected code in each function module; according to the pre-stored code and the main key of the flow relation file, calculating the coverage characteristic of each flow based on the full-flow Cov file under each main key; mapping each flow into a second type flow file corresponding to each flow according to each primary key; merging the traffic corresponding to the same primary key in each second-class traffic file, and merging the traffic in each second-class traffic file to obtain the pre-stored code and traffic relation file.
In the above embodiment, the test module is specifically configured to determine each switch combination state of the current test according to the logic switch corresponding to the code that has not changed in the tested code and the logic switch corresponding to the code that has changed in the tested code; and testing the tested code by using the target flow of the current test under each switch combination state.
In the above embodiment, the test module is specifically configured to construct at least one vocabulary data according to a predetermined test flow and a pre-stored original vocabulary, and add the at least one vocabulary data to the original vocabulary to obtain a target vocabulary; updating the initial test environment of the current test by using the target word list; or constructing at least one commodity material data according to a predetermined test flow and a pre-stored original database, and adding the at least one commodity material data to the original database to obtain a target database; updating the initial test environment of the test by using the target database; and testing the tested code under the updated test environment by using the target flow of the test.
In a third aspect, an embodiment of the present application provides an electronic device, including:
one or more processors;
a memory for storing one or more programs,
when the one or more programs are executed by the one or more processors, the one or more processors are caused to implement the code testing method of any embodiment of the present application.
In a fourth aspect, the present application provides a storage medium, on which a computer program is stored, where the computer program is executed by a processor to implement the code testing method according to any embodiment of the present application.
One embodiment in the above application has the following advantages or benefits: according to the code testing method, the code testing device, the electronic equipment and the storage medium, coverage testing data of a previous test for a tested code are obtained in the current test for the tested code; then, analyzing a code and flow relation file of the previous test according to coverage test data of the previous test; matching the code and flow relation file of the previous test with a pre-stored code and flow relation file to obtain the dynamic flow of the previous test; and when the tested code is not changed, determining the target flow of the test according to the dynamic flow of the previous test and the minimum set of flows stored in advance, and testing the tested code by using the target flow of the test. That is to say, the present application may determine the minimum flow set and the two basic data of the code and flow relation file in advance, and in this test, the dynamic flow of the previous test may be obtained by matching the code and flow relation file of the previous test with the pre-stored code and flow relation file, so that in this test, the target flow of this test may be determined according to the dynamic flow of the previous test and the minimum flow set stored in advance, and then the target flow of this test is used to test the code to be tested, thereby achieving the purpose of improving the code coverage. In the existing code testing method, logs of partial time periods are selected from 1-2 machines at random as testing flow, and because the testing flow is selected at random, the testing flow may not be enough to evaluate the tested code, and the problem of insufficient code coverage exists. The method adopts the technical means of predetermining the minimum set of the flow and the code-flow relation file, and combines and deduplicates the dynamic flow of the previous test and the minimum set of the flow stored in advance in the current test to determine the target flow of the current test, so that the technical problem of insufficient code coverage in the prior art is solved, and the technical effects of improving the code coverage and improving the code test quality are achieved; moreover, the technical scheme of the embodiment of the application is simple and convenient to implement, convenient to popularize and wide in application range.
Other effects of the above-described alternative will be described below with reference to specific embodiments.
Drawings
The drawings are included to provide a better understanding of the present solution and are not intended to limit the present application. Wherein:
FIG. 1 is a flowchart illustrating a code testing method according to an embodiment of the present application;
FIG. 2 is a flowchart illustrating a code testing method according to a second embodiment of the present application;
FIG. 3 is a first schematic structural diagram of a code testing apparatus according to a third embodiment of the present application;
FIG. 4 is a second schematic structural diagram of a code testing apparatus according to a third embodiment of the present application;
FIG. 5 is a block diagram of an electronic device for implementing a code testing method according to an embodiment of the present application.
Detailed Description
The following description of the exemplary embodiments of the present application, taken in conjunction with the accompanying drawings, includes various details of the embodiments of the application for the understanding of the same, which are to be considered exemplary only. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the present application. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
Example one
Fig. 1 is a flowchart of a code testing method provided in an embodiment of the present application, where the method may be performed by a code testing apparatus or an electronic device, where the apparatus or the electronic device may be implemented by software and/or hardware, and the apparatus or the electronic device may be integrated in any intelligent device with a network communication function. As shown in fig. 1, the code testing method may include the steps of:
s101, coverage rate test data of the previous test aiming at the tested code is obtained in the current test aiming at the tested code.
In a specific embodiment of the present application, a cov (code) file refers to a code overlay file; the method is used for describing the proportion and the degree of the tested source code in the program, the obtained proportion is called code coverage rate, and the proportion is an important index for measuring the testing capability and the testing integrity. The SID refers to an Identity (Identity document) of each traffic, and is used to represent a unique code of each traffic. Jenkins is an open source software project, is a continuous integration tool developed based on Java, is used for monitoring continuous and repeated work, and aims to provide an open and easy-to-use software platform to enable continuous integration of software. xstp refers to the environment of the measurand. sshpass refers to an interactive SSH login tool, where SSH login cannot specify a password in the command line, sshpass allows specification of a clear password with parameters, and then logs directly to a remote server, which supports password reading from command lines, files, and environment variables. MD5, commonly referred to as MD5 Message Digest Algorithm (MD5 Message-Digest Algorithm), is a widely used cryptographic hash function that generates a 128-bit (16-byte) hash value (hash value) to ensure the integrity of the Message transmission.
In a specific embodiment of the present application, the electronic device may obtain, in the current test for the code to be tested, coverage test data of a previous test for the code to be tested; wherein, the coverage test data of the previous test can be the Cov file of the previous test. In a specific implementation scheme, the electronic device may perform a test on the code to be tested once a day, and in this step, the electronic device may obtain coverage test data of a previous day test for the code to be tested in a current day test for the code to be tested; wherein, the test coverage rate data of the previous day can be a Cov file of the previous day test.
And S102, analyzing a code and flow relation file of the previous test according to the coverage test data of the previous test.
In a specific embodiment of the present application, the electronic device may analyze a code and flow relation file of a previous test according to coverage test data of the previous test. In particular, the coverage test data may include one or more of source file level screening information, function level screening information, and code line level screening information. Further, the source file level filtering information includes overlay source file information; the function level screening information comprises overlay source file function information; the code line level filtering information includes coverage code line number information and/or branch condition information of coverage code lines. In this step, the electronic device may obtain the code and flow relation file of the previous test by analyzing the coverage test data of the previous test. Preferably, the electronic device may further obtain a code that is not covered by the code to be tested in the previous test by analyzing the coverage test data of the previous test.
S103, matching the code and flow relation file of the previous test with a pre-stored code and flow relation file to obtain the dynamic flow of the previous test.
In a specific embodiment of the present application, the electronic device may match the code and flow relationship file of the previous test with a pre-stored code and flow relationship file to obtain the dynamic flow of the previous test. Specifically, the data structure of the code and traffic relationship file may be represented as: code file name/function name/traffic collection. Assume that the pre-saved code and traffic relationship file includes: code file 1/function name 1/flow 1; code file 1/function name 2/flow 2; code file 1/function name 3/flow 3; assume that the code and traffic relationship file of the previous test includes: code file 1/function name 1/flow 1 and flow 2; code file 1/function name 2/flow 2; code file 1/function name 3/flow 3; by matching the code and flow relation file of the previous test with the pre-stored code and flow relation file, it can be known that one flow 2 is added to the code file 1/function name 1, and the dynamic flow obtained in the previous test in this step is the flow 2.
And S104, when the tested code is not changed, determining the target flow of the test according to the dynamic flow of the previous test and the minimum set of flows stored in advance, and testing the tested code by using the target flow of the test.
In a specific embodiment of the present application, when the code to be tested is not changed, the electronic device may determine the target flow rate of the current test according to the dynamic flow rate of the previous test and the minimum set of flow rates pre-stored, and then test the code to be tested using the target flow rate of the current test. Specifically, the electronic device may combine and deduplicate the dynamic flow of the previous test and the flow of the minimum set of flows that is pre-stored, and determine the flow after combining and deduplicating as the target flow of the current test; and then testing the tested code by using the target flow of the test.
Preferably, in the specific embodiment of the present application, when the detected code changes, the electronic device may obtain, in the pre-stored code and flow relationship file, a new flow corresponding to each changed function in the detected code; and determining the target flow of the test according to the newly added flow corresponding to each changed function, the dynamic flow of the previous test and the minimum set of prestored flows, and testing the tested code by using the target flow of the test. Specifically, the electronic device may combine and deduplicate the newly added traffic corresponding to each changed function with the dynamic traffic of the previous test and the traffic of the minimum set of prestored traffic, and determine the combined and deduplicated traffic as the target traffic of the current test; and then testing the tested code by using the target flow of the test.
The code testing method provided by the embodiment of the application comprises the steps of firstly, acquiring coverage rate testing data of a previous test aiming at a tested code in the current test aiming at the tested code; then, analyzing a code and flow relation file of the previous test according to coverage test data of the previous test; matching the code and flow relation file of the previous test with a pre-stored code and flow relation file to obtain the dynamic flow of the previous test; and when the tested code is not changed, determining the target flow of the test according to the dynamic flow of the previous test and the minimum set of flows stored in advance, and testing the tested code by using the target flow of the test. That is to say, the present application may determine the minimum flow set and the two basic data of the code and flow relation file in advance, and in this test, the dynamic flow of the previous test may be obtained by matching the code and flow relation file of the previous test with the pre-stored code and flow relation file, so that in this test, the target flow of this test may be determined according to the dynamic flow of the previous test and the minimum flow set stored in advance, and then the target flow of this test is used to test the code to be tested, thereby achieving the purpose of improving the code coverage. In the existing code testing method, logs of partial time periods are selected from 1-2 machines at random as testing flow, and because the testing flow is selected at random, the testing flow may not be enough to evaluate the tested code, and the problem of insufficient code coverage exists. The method adopts the technical means of predetermining the minimum set of the flow and the code-flow relation file, and combines and deduplicates the dynamic flow of the previous test and the minimum set of the flow stored in advance in the current test to determine the target flow of the current test, so that the technical problem of insufficient code coverage in the prior art is solved, and the technical effects of improving the code coverage and improving the code test quality are achieved; moreover, the technical scheme of the embodiment of the application is simple and convenient to implement, convenient to popularize and wide in application range.
Example two
Fig. 2 is a schematic flowchart of a code testing method according to a second embodiment of the present application. As shown in fig. 2, the code testing method may include the steps of:
s201, screening out a second amount of flow from the first amount of flow in an original flow word list according to each flow table entry in the original flow word list and an original module log of a tested code in each function module; wherein each flow table entry comprises: SID and parameter information for each traffic.
In a specific embodiment of the present application, the electronic device may screen out a second amount of traffic from the first amount of traffic in the original traffic vocabulary according to each traffic table entry in the original traffic vocabulary and an original module log of the detected code in each function module; wherein each flow table entry comprises: SID and parameter information for each traffic. Specifically, the traffic vocabulary is an information table of traffic parameters (for example, request parameters) represented by SID; the original module log is parameters such as a path and a track of each flow represented by a text format; wherein one SID corresponds to one traffic; one flow corresponds to one raw module log. The code to be tested is supposed to relate to three modules, namely a module A, a module B and a module C; the flow vocabulary comprises three flows which are respectively: SID1, SID2, SID 3. In this step, the process of screening out the second amount of flow from the first amount of flow in the original flow vocabulary may be referred to as coarse screening; wherein, the coarse screen can be divided into: and flow expansion and flow reverse compensation. In the process of traffic expansion, the electronic device may match SID1 with each original module log in module a, module B, and module C, respectively, to obtain an original module log matched with SID1, which is recorded as: original module log 1; then, the SID2 is matched with each original module log in the module a, the module B, and the module C, so as to obtain an original module log matched with the SID2, which is recorded as: original module log 2; then, the SID3 is matched with each original module log in the module a, the module B, and the module C, so as to obtain an original module log matched with the SID3, which is recorded as: original module log 3; then calculating the log characteristics of the original module log 1, the original module log 2 and the original module log 3 respectively, and merging the calculated log characteristics; because the log characteristics and the flow in the original flow vocabulary have a one-to-one correspondence relationship, the original module logs with the same log characteristics are removed, namely the flow with the same log characteristics is removed from the original flow vocabulary, the flows with different log characteristics are screened out, and the flows are used as expansion flows. For example, the process of flow scalping may be implemented to screen 20 thousand flows out of 300 thousand flows as an expanded flow. In the process of flow inverse compensation, the electronic device may first use a first amount of flow (for example, 300 ten thousand) to test a code to be tested, and obtain a test result corresponding to the first amount of flow; then, testing the tested code by using the expansion flow (for example, 20 ten thousand) to obtain a test result corresponding to the expansion flow; since there is a test result that is not present in the test results corresponding to the extended flow rate among the test results corresponding to the first number of flow rates, it is possible to acquire test results that are present in the test results corresponding to the first number of flow rates and are not present in the test results corresponding to the extended flow rate, and add the flow rates (which may be 10 ten thousand, for example) corresponding to these test results as complementary flow rates to the extended flow rate, resulting in a second number of flow rates of 30 ten thousand.
For example, the specific process of the electronic device in matching the SID1 with each original module log in module a, module B, and module C may be: firstly, matching SID1 with each original module log in module A to obtain an original module log A1 matched with SID1 in module A; then, matching the SID1 with each original module log in the module B to obtain an original module log B1 matched with the SID1 in the module B; then, matching the SID1 with each original module log in the module C to obtain an original module log C1 matched with the SID1 in the module C; original module log A1, original module log B1, and original module log C2 are merged to obtain original module log 1.
S202, dividing the second quantity of flow into N parts of flow, and inputting the N parts of flow into N testing environments respectively; collecting Cov files corresponding to all flows through collection tasks in all test environments; merging Cov files corresponding to all flows into a full-flow Cov file; wherein N is a natural number greater than 1.
In a specific embodiment of the present application, the electronic device may divide the second amount of traffic into N traffic shares, and input the N traffic shares into N test environments respectively; collecting Cov files corresponding to all flows through collection tasks in all test environments; merging Cov files corresponding to all flows into a full-flow Cov file; wherein N is a natural number greater than 1. Specifically, the electronic device may input a first flow into a first test environment, and acquire, through an acquisition task in the first test environment, a Cov file corresponding to each flow in the first flow; inputting the second flow into a second test environment, and acquiring Cov files corresponding to each flow in the second flow through an acquisition task in the second test environment; …, respectively; and inputting the Nth flow into the Nth test environment, and acquiring Cov files corresponding to all flows in the Nth flow through an acquisition task in the Nth test environment. These Cov files are then merged into one full-traffic Cov file. For example, the second amount of traffic is 30 ten thousand, in this step, the electronic device may divide the 30 ten thousand traffic into 10 shares, each of which is 3 ten thousand, and assuming that the test environment is 10, allocate the first 3 ten thousand traffic to the test environment 1, the second 3 ten thousand traffic to the test environment 2, …, and the tenth 3 ten thousand traffic to the test environment 10. Specifically, in each test environment, the electronic device may input each flow into Jenkins, input the output of each Jenkins into an xstp environment, start an acquisition task through sshpass, request one of the modules (assumed to be module a), call the other modules (assumed to be module B and module C) through the requested module, and then obtain a Cov file corresponding to each flow in each flow.
And S203, calculating a pre-saved minimum flow set and a pre-saved code and flow relation file according to the full-flow Cov file.
In a specific embodiment of the present application, the electronic device may calculate the following two basic data according to the full-traffic Cov file, where the two basic data are: and storing the two basic data as a pre-stored flow minimum set and a pre-stored code and flow relation file. In a specific implementation, the electronic device may calculate the minimum set of flows and the code and flow relationship file once a week.
In a specific embodiment of the present application, in the process of calculating the minimum set of flows according to the full-flow Cov file, the electronic device may analyze the coverage characteristic of each flow in the full-flow Cov file according to the SID of each flow in the full-flow Cov file; then writing each flow into a first type of flow file corresponding to each flow according to the coverage characteristic of each flow; and then, carrying out duplicate removal on the flow in each first type flow file through the thread corresponding to each first type flow file, and combining duplicate removal results of each thread to obtain a minimum flow set stored in advance. Specifically, the electronic device may use a binary string to represent the case where each line of code is covered by each traffic. For example, using 0 indicates that a certain line of code is covered by a certain flow; the use of 1 indicates that a certain line of code is not covered by a certain flow. In order to improve the analysis speed, the coverage characteristics of each flow can be calculated through multiple threads, and the coverage characteristics are subjected to Hash mapping according to the MD5 values of the coverage characteristics and then are concurrently written into a plurality of first-class flow files; and then, data in each first-class flow file is subjected to deduplication by using multiple threads, and finally the calculation results of each thread are combined to obtain a minimum flow set.
In a specific embodiment of the application, in the process of calculating the code and flow relation file according to the full-flow Cov file, the electronic device may first calculate a primary key of a pre-stored code and flow relation file according to a code file name and a function name of a detected code in each functional module; then, according to the pre-stored code and the main key of the flow relation file, calculating the coverage characteristic of each flow based on the full-flow Cov file under each main key; the specific calculation method is the same as the minimum set; then mapping each flow to a second type flow file corresponding to each flow according to each primary key; merging the traffic corresponding to the same primary key in each second-class traffic file, and merging the traffic in each second-class traffic file to obtain a prestored code and traffic relation file. When the specific scheme is implemented, a certain amount of truncation can be performed according to the principle of coverage characteristic even distribution. For example, there are 100 flows and five overlay features for primary key 1, and if 60 are truncated, 60/5-12 overlay features are selected for each overlay feature.
For example, the minimum set of flows: assume three flows, respectively: flow 1(SID1), flow 2(SID2) and flow 3(SID 3); two lines of codes are respectively: code 1, code 2; assume that traffic 1 covers code 1 and code 3; flow 2 override code 2; flow 3 covers code 1 and code 3; since the flow 1 and the flow 3 are both the coverage code 1 and the coverage code 3, the flow 3 can be deleted, and only the flow 1 and the flow 2 are reserved, so that the set composed of the flow 1 and the flow 2 is the minimum set of flows. Code and overlay traffic relationship data: the code file name/function name/SID is used as a data structure to indicate which functions in a certain code are covered by which flow. For example: the code file name 1/function name 1/flow 1 and flow 2 indicate that the function 1 in the code file 1 is covered by the flow 1 and the flow 2.
In a specific embodiment of the present application, for a code that is not covered in a previous test, the electronic device may screen an incremental flow from the obtained code and flow relation file; the screening process exists in the following order: 1. traffic that can be overlaid to the modification function; 2. traffic to the modified file can be overridden. Firstly, acquiring the flow capable of covering the modification function; and if the flow which can cover the modification function cannot be obtained, obtaining the flow which can cover the modification file.
And S204, acquiring coverage rate test data of the previous test aiming at the tested code in the current test aiming at the tested code.
In a specific embodiment of the present application, the electronic device may obtain, in the current test for the code to be tested, coverage test data of a previous test for the code to be tested; wherein, the coverage test data of the previous test can be the Cov file of the previous test. In a specific implementation scheme, the electronic device may perform a test on the code to be tested once a day, and in this step, the electronic device may obtain coverage test data of a previous day test for the code to be tested in a current day test for the code to be tested; wherein, the test coverage rate data of the previous day can be a Cov file of the previous day test.
And S205, analyzing the code and flow relation file of the previous test according to the coverage test data of the previous test.
In a specific embodiment of the application, the electronic device may obtain the code and flow relation file of the previous test by analyzing the coverage test data of the previous test. Preferably, the electronic device may further obtain a code that is not covered by the code to be tested in the previous test by analyzing the coverage test data of the previous test.
And S206, matching the code and flow relation file of the previous test with a pre-stored code and flow relation file to obtain the dynamic flow of the previous test.
In a specific embodiment of the present application, the electronic device may match the code and flow relationship file of the previous test with a pre-stored code and flow relationship file to obtain the dynamic flow of the previous test. Specifically, the data structure of the code and traffic relationship file may be represented as: code file name/function name/traffic collection. In this step, the electronic device may compare each line in the code and flow relation file of the previous test with each line in the pre-stored code and flow relation file to obtain a newly added code function file; determining a new code in the new code function file; and dynamically selecting the related flow aiming at the newly added code in the code and flow relation file, namely acquiring the dynamic flow of the previous test.
Preferably, in the embodiment of the present application, the electronic device may further perform flow adjustment in the process of acquiring the dynamic flow of the previous test. In particular, for complex modules, the coverage proportion of some services is too low because of insufficient traffic. Therefore, in the technical scheme provided by the application, firstly, offline test flow can be extracted by analyzing the characteristic field of the log; secondly, calculating the ratio of the specific service flow of the on-line environment; finally, the occupation ratio of the offline test traffic is adjusted through the occupation ratio of the online environment specific traffic and the traffic which can cover the specific traffic offline.
And S207, when the tested code is not changed, determining the target flow of the test according to the dynamic flow of the previous test and the minimum set of flows stored in advance, and testing the tested code by using the target flow of the test.
In a specific embodiment of the present application, when the code to be tested is not changed, the electronic device may determine the target flow rate of the current test according to the dynamic flow rate of the previous test and the minimum set of flow rates pre-stored, and then test the code to be tested using the target flow rate of the current test. Specifically, the electronic device may combine and deduplicate the dynamic flow of the previous test and the flow of the minimum set of flows that is pre-stored, and determine the flow after combining and deduplicating as the target flow of the current test; and then testing the tested code by using the target flow of the test.
Preferably, in the specific embodiment of the present application, when the detected code changes, the electronic device may obtain, in the pre-stored code and flow relationship file, a new flow corresponding to each changed function in the detected code; and determining the target flow of the test according to the newly added flow corresponding to each changed function, the dynamic flow of the previous test and the minimum set of prestored flows, and testing the tested code by using the target flow of the test. Specifically, the electronic device may combine and deduplicate the newly added traffic corresponding to each changed function with the dynamic traffic of the previous test and the traffic of the minimum set of prestored traffic, and determine the combined and deduplicated traffic as the target traffic of the current test; and then testing the tested code by using the target flow of the test.
Preferably, in a specific embodiment of the present application, during a process of testing a code to be tested by using a target flow of the current test, the electronic device may further determine a combination state of each switch of the current test according to a logic switch corresponding to a code that is not changed in the code to be tested and a logic switch corresponding to a code that is changed in the code to be tested; and then testing the tested code under each switch combination state by using the target flow of the test. For example, assume that the logic switch corresponding to the unchanged code in the tested code is: a switch 1; assume that the logic switch corresponding to the changed code in the tested code is: switch 2 and switch 3; in this step, the electronic device can determine eight switch combination states, which are respectively: the switch 1 is opened, the switch 2 is closed, and the switch 3 is closed; the switch 1 is closed, the switch 2 is opened, and the switch 3 is closed; the switch 1 is closed, the switch 2 is closed, and the switch 3 is opened; the switch 1 is turned on, the switch 2 is turned on, and the switch 3 is turned off; the switch 1 is closed, the switch 2 is opened, and the switch 3 is opened; the switch 1 is opened, the switch 2 is closed, and the switch 3 is opened; the switch 1 is turned on, the switch 2 is turned on, and the switch 3 is turned on; switch 1 is closed, switch 2 is closed, and switch 3 is closed.
Preferably, in a specific embodiment of the present application, in a process of testing a code to be tested by using a target flow of the current test, the electronic device may first construct at least one vocabulary data according to a predetermined test flow and a pre-stored original vocabulary, and add the at least one vocabulary data to the original vocabulary to obtain the target vocabulary; updating the initial test environment of the test by using the target vocabulary; or, according to the predetermined test flow and a pre-stored original database, constructing at least one commodity material data, and adding the at least one commodity material data to the original database to obtain a target database; updating the initial test environment of the test by using the target database; and testing the tested code under the updated test environment by using the target flow of the test. Specifically, in the process of constructing word list data, firstly, core field data which can be covered in a test process is obtained in a code instrumentation mode, such as advertisement ID and account ID; thirdly, analyzing the uncovered vocabulary files by analyzing the code coverage; and finally, inserting part of word list data by matching the word list file with the core field data. In addition, in the process of constructing the commodity material data, firstly, collecting the ID information of commodities which can be covered, and secondly, obtaining the commodity material data; thirdly, analyzing the commodity coverage condition based on the combing rule, and modifying a small amount of commodity data for the rule of insufficient coverage. For example, the effective time of the commodity needs to cover the online commodity, the expired commodity and the like.
For example, constructing the vocabulary data may be a scheme of adding an ID in a configuration file; building the commodity material data may be a scheme of adding or modifying commodity attributes in a database. In the scheme of constructing the vocabulary, three flows are assumed, which are respectively: traffic 1, traffic 2, and traffic 3, each of which can cover 3 IDs (where IDs represent core field data such as advertisement IDs or user IDs), then three can cover 9 IDs, say IDs 11-ID19, and assuming that there is only one ID1 in the original vocabulary, then in the scheme of constructing the vocabulary, several of the IDs 11-ID19 can be added to the original vocabulary.
The code testing method provided by the embodiment of the application comprises the steps of firstly, acquiring coverage rate testing data of a previous test aiming at a tested code in the current test aiming at the tested code; then, analyzing a code and flow relation file of the previous test according to coverage test data of the previous test; matching the code and flow relation file of the previous test with a pre-stored code and flow relation file to obtain the dynamic flow of the previous test; and when the tested code is not changed, determining the target flow of the test according to the dynamic flow of the previous test and the minimum set of flows stored in advance, and testing the tested code by using the target flow of the test. That is to say, the present application may determine the minimum flow set and the two basic data of the code and flow relation file in advance, and in this test, the dynamic flow of the previous test may be obtained by matching the code and flow relation file of the previous test with the pre-stored code and flow relation file, so that in this test, the target flow of this test may be determined according to the dynamic flow of the previous test and the minimum flow set stored in advance, and then the target flow of this test is used to test the code to be tested, thereby achieving the purpose of improving the code coverage. In the existing code testing method, logs of partial time periods are selected from 1-2 machines at random as testing flow, and because the testing flow is selected at random, the testing flow may not be enough to evaluate the tested code, and the problem of insufficient code coverage exists. The method adopts the technical means of predetermining the minimum set of the flow and the code-flow relation file, and combines and deduplicates the dynamic flow of the previous test and the minimum set of the flow stored in advance in the current test to determine the target flow of the current test, so that the technical problem of insufficient code coverage in the prior art is solved, and the technical effects of improving the code coverage and improving the code test quality are achieved; moreover, the technical scheme of the embodiment of the application is simple and convenient to implement, convenient to popularize and wide in application range.
EXAMPLE III
Fig. 3 is a schematic view of a first structure of a code testing apparatus according to a third embodiment of the present application. As shown in fig. 3, the apparatus 300 includes: the device comprises an acquisition module 301, an analysis module 302, a matching module 303 and a test module 304; wherein the content of the first and second substances,
the obtaining module 301 is configured to obtain coverage test data of a previous test for a code to be tested in a current test for the code to be tested;
the analysis module 302 is configured to analyze a code and flow relation file of the previous test according to the coverage test data of the previous test;
the matching module 303 is configured to match the code and flow relationship file of the previous test with a pre-stored code and flow relationship file to obtain a dynamic flow of the previous test;
the test module 304 is configured to determine the target flow of the current test according to the minimum set of the dynamic flow of the previous test and the flow stored in advance when the code to be tested is not changed, and test the code to be tested by using the target flow of the current test.
Further, the testing module 304 is further configured to, when the code to be tested changes, obtain, in the prestored code-flow relationship file, a newly added flow corresponding to each changed function in the code to be tested; and determining the target flow of the current test according to the newly added flow corresponding to each changed function, the dynamic flow of the previous test and the minimum set of prestored flows, and testing the tested code by using the target flow of the current test.
Fig. 4 is a second schematic structural diagram of a code testing apparatus according to a third embodiment of the present application. As shown in fig. 4, the apparatus 300 further includes: a screening module 305 and a calculation module 306; wherein the content of the first and second substances,
the screening module 305 is configured to screen out a second amount of traffic from the first amount of traffic in the original traffic vocabulary according to each traffic table entry in the original traffic vocabulary and the original module log of the detected code in each functional module; wherein each flow table entry comprises: identification SID and parameter information of each flow; dividing the second quantity of flow into N parts of flow, and respectively inputting the N parts of flow into N testing environments; collecting Cov files corresponding to all flows through collection tasks in all test environments; merging Cov files corresponding to all flows into a full-flow Cov file; wherein N is a natural number greater than 1;
the calculating module 306 is configured to calculate the pre-saved minimum set of flows and the pre-saved code and flow relation file according to the full-flow Cov file.
Further, the calculating module 306 is specifically configured to analyze a coverage characteristic of each flow in the full-flow Cov file according to the SID of each flow in the full-flow Cov file; writing each flow into a first type of flow file corresponding to the flow according to the coverage characteristic of each flow; and carrying out duplicate removal on the flow in each first type flow file through the thread corresponding to each first type flow file, and combining duplicate removal results of each thread to obtain the minimum pre-stored flow set.
Further, the calculating module 306 is specifically configured to calculate a primary key of the pre-stored code and flow relation file according to the code file name and the function name of the detected code in each functional module; according to the pre-stored code and the main key of the flow relation file, calculating the coverage characteristic of each flow based on the full-flow Cov file under each main key; mapping each flow into a second type flow file corresponding to each flow according to each primary key; merging the traffic corresponding to the same primary key in each second-class traffic file, and merging the traffic in each second-class traffic file to obtain the pre-stored code and traffic relation file.
Further, the test module 306 is specifically configured to determine each switch combination state of the current test according to the logic switch corresponding to the code that is not changed in the tested code and the logic switch corresponding to the code that is changed in the tested code; and testing the tested code by using the target flow of the current test under each switch combination state.
Further, the testing module 306 is specifically configured to construct at least one vocabulary data according to a predetermined testing flow and a pre-stored original vocabulary, and add the at least one vocabulary data to the original vocabulary to obtain a target vocabulary; updating the initial test environment of the current test by using the target word list; or constructing at least one commodity material data according to a predetermined test flow and a pre-stored original database, and adding the at least one commodity material data to the original database to obtain a target database; updating the initial test environment of the test by using the target database; and testing the tested code under the updated test environment by using the target flow of the test.
The code testing device can execute the method provided by any embodiment of the application, and has the corresponding functional modules and beneficial effects of the execution method. For technical details that are not described in detail in this embodiment, reference may be made to a code testing method provided in any embodiment of the present application.
Example four
According to an embodiment of the present application, an electronic device and a readable storage medium are also provided.
Fig. 5 is a block diagram of an electronic device according to an embodiment of the present application. Electronic devices are intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device may also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are meant to be examples only, and are not meant to limit implementations of the present application that are described and/or claimed herein.
As shown in fig. 5, the electronic apparatus includes: one or more processors 501, memory 502, and interfaces for connecting the various components, including high-speed interfaces and low-speed interfaces. The various components are interconnected using different buses and may be mounted on a common motherboard or in other manners as desired. The processor may process instructions for execution within the electronic device, including instructions stored in or on the memory to display graphical information of a GUI on an external input/output apparatus (such as a display device coupled to the interface). In other embodiments, multiple processors and/or multiple buses may be used, along with multiple memories and multiple memories, as desired. Also, multiple electronic devices may be connected, with each device providing portions of the necessary operations (e.g., as a server array, a group of blade servers, or a multi-processor system). In fig. 5, one processor 501 is taken as an example.
Memory 502 is a non-transitory computer readable storage medium as provided herein. Wherein the memory stores instructions executable by at least one processor to cause the at least one processor to perform the code testing method provided herein. The non-transitory computer-readable storage medium of the present application stores computer instructions for causing a computer to perform the code testing method provided herein.
Memory 502, which is a non-transitory computer-readable storage medium, may be used to store non-transitory software programs, non-transitory computer-executable programs, and modules, such as program instructions/modules (e.g., acquisition module 301, parsing module 302, matching module 303, and testing module 304 shown in fig. 3) corresponding to the code testing method in the embodiments of the present application. The processor 501 executes various functional applications of the server and data processing, i.e., implementing the code testing method in the above method embodiments, by running non-transitory software programs, instructions, and modules stored in the memory 502.
The memory 502 may include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function; the storage data area may store data created according to the use of the electronic device of the code test method, and the like. Further, the memory 502 may include high speed random access memory, and may also include non-transitory memory, such as at least one magnetic disk storage device, flash memory device, or other non-transitory solid state storage device. In some embodiments, memory 502 optionally includes memory located remotely from processor 501, which may be connected to the code testing method electronics over a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The electronic device of the code testing method may further include: an input device 503 and an output device 504. The processor 501, the memory 502, the input device 503 and the output device 504 may be connected by a bus or other means, and fig. 5 illustrates the connection by a bus as an example.
The input device 503 may receive input numeric or character information and generate key signal inputs related to user settings and function control of the electronic apparatus of the code test method, such as an input device of a touch screen, a keypad, a mouse, a track pad, a touch pad, a pointing stick, one or more mouse buttons, a track ball, a joystick, etc. The output devices 504 may include a display device, auxiliary lighting devices (e.g., LEDs), and haptic feedback devices (e.g., vibrating motors), among others. The display device may include, but is not limited to, a Liquid Crystal Display (LCD), a Light Emitting Diode (LED) display, and a plasma display. In some implementations, the display device can be a touch screen.
Various implementations of the systems and techniques described here can be realized in digital electronic circuitry, integrated circuitry, application specific ASICs (application specific integrated circuits), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include: implemented in one or more computer programs that are executable and/or interpretable on a programmable system including at least one programmable processor, which may be special or general purpose, receiving data and instructions from, and transmitting data and instructions to, a storage system, at least one input device, and at least one output device.
These computer programs (also known as programs, software applications, or code) include machine instructions for a programmable processor, and may be implemented using high-level procedural and/or object-oriented programming languages, and/or assembly/machine languages. As used herein, the terms "machine-readable medium" and "computer-readable medium" refer to any computer program product, apparatus, and/or device (e.g., magnetic discs, optical disks, memory, Programmable Logic Devices (PLDs)) used to provide machine instructions and/or data to a programmable processor, including a machine-readable medium that receives machine instructions as a machine-readable signal. The term "machine-readable signal" refers to any signal used to provide machine instructions and/or data to a programmable processor.
To provide for interaction with a user, the systems and techniques described here can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to a user; and a keyboard and a pointing device (e.g., a mouse or a trackball) by which a user can provide input to the computer. Other kinds of devices may also be used to provide for interaction with a user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form, including acoustic, speech, or tactile input.
The systems and techniques described here can be implemented in a computing system that includes a back-end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front-end component (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back-end, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local Area Networks (LANs), Wide Area Networks (WANs), the internet, and blockchain networks.
The computer system may include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other.
According to the technical scheme of the embodiment of the application, firstly, coverage rate test data of a previous test for a tested code is obtained in the current test for the tested code; then, analyzing a code and flow relation file of the previous test according to coverage test data of the previous test; matching the code and flow relation file of the previous test with a pre-stored code and flow relation file to obtain the dynamic flow of the previous test; and when the tested code is not changed, determining the target flow of the test according to the dynamic flow of the previous test and the minimum set of flows stored in advance, and testing the tested code by using the target flow of the test. That is to say, the present application may determine the minimum flow set and the two basic data of the code and flow relation file in advance, and in this test, the dynamic flow of the previous test may be obtained by matching the code and flow relation file of the previous test with the pre-stored code and flow relation file, so that in this test, the target flow of this test may be determined according to the dynamic flow of the previous test and the minimum flow set stored in advance, and then the target flow of this test is used to test the code to be tested, thereby achieving the purpose of improving the code coverage. In the existing code testing method, logs of partial time periods are selected from 1-2 machines at random as testing flow, and because the testing flow is selected at random, the testing flow may not be enough to evaluate the tested code, and the problem of insufficient code coverage exists. The method adopts the technical means of predetermining the minimum set of the flow and the code-flow relation file, and combines and deduplicates the dynamic flow of the previous test and the minimum set of the flow stored in advance in the current test to determine the target flow of the current test, so that the technical problem of insufficient code coverage in the prior art is solved, and the technical effects of improving the code coverage and improving the code test quality are achieved; moreover, the technical scheme of the embodiment of the application is simple and convenient to implement, convenient to popularize and wide in application range.
It should be understood that various forms of the flows shown above may be used, with steps reordered, added, or deleted. For example, the steps described in the present application may be executed in parallel, sequentially, or in different orders, and the present invention is not limited thereto as long as the desired results of the technical solutions disclosed in the present application can be achieved.
The above-described embodiments should not be construed as limiting the scope of the present application. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may be made in accordance with design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present application shall be included in the protection scope of the present application.

Claims (16)

1. A method for code testing, the method comprising:
acquiring coverage rate test data of a previous test aiming at a tested code in the current test aiming at the tested code;
analyzing a code and flow relation file of the previous test according to the coverage test data of the previous test;
matching the code and flow relation file of the previous test with a pre-stored code and flow relation file to obtain the dynamic flow of the previous test;
and when the tested code is not changed, determining the target flow of the test according to the dynamic flow of the previous test and a minimum set of prestored flows, and testing the tested code by using the target flow of the test.
2. The method of claim 1, further comprising:
when the code to be tested is changed, acquiring newly added flow corresponding to each changed function in the code to be tested in the prestored code and flow relation file; and determining the target flow of the current test according to the newly added flow corresponding to each changed function, the dynamic flow of the previous test and the minimum set of prestored flows, and testing the tested code by using the target flow of the current test.
3. The method of claim 1, prior to said obtaining coverage test data for a previous test of the code under test in a present test of the code under test, the method further comprising:
screening out a second amount of flow from the first amount of flow in the original flow word list according to each flow table entry in the original flow word list and an original module log of the tested code in each function module; wherein each flow table entry comprises: identification SID and parameter information of each flow;
dividing the second quantity of flow into N parts of flow, and respectively inputting the N parts of flow into N testing environments; acquiring code coverage Cov files corresponding to all flows through acquisition tasks in all test environments; merging Cov files corresponding to all flows into a full-flow Cov file; wherein N is a natural number greater than 1;
and calculating the pre-saved minimum flow set and the pre-saved code and flow relation file according to the full-flow Cov file.
4. The method of claim 3, wherein said computing the minimum set of pre-saved flows from the full-flow Cov file comprises:
analyzing the coverage characteristic of each flow in the full-flow Cov file according to the SID of each flow in the full-flow Cov file;
writing each flow into a first type of flow file corresponding to the flow according to the coverage characteristic of each flow;
and carrying out duplicate removal on the flow in each first type flow file through the thread corresponding to each first type flow file, and combining duplicate removal results of each thread to obtain the minimum pre-stored flow set.
5. The method of claim 3, wherein said computing the pre-saved code-to-traffic relationship file from the full-traffic Cov file comprises:
calculating the main key of the prestored code and flow relation file according to the code file name and the function name of the tested code in each functional module;
according to the pre-stored code and the main key of the flow relation file, calculating the coverage characteristic of each flow based on the full-flow Cov file under each main key;
mapping each flow into a second type flow file corresponding to each flow according to each primary key;
merging the traffic corresponding to the same primary key in each second-class traffic file, and merging the traffic in each second-class traffic file to obtain the pre-stored code and traffic relation file.
6. The method of claim 2, wherein the testing the code under test using the target traffic of the current test comprises:
determining each switch combination state of the current test according to the logic switch corresponding to the code which is not changed in the tested code and the logic switch corresponding to the code which is changed in the tested code;
and testing the tested code by using the target flow of the current test under each switch combination state.
7. The method of claim 1, wherein the testing the code under test using the target traffic of the current test comprises:
constructing at least one word list data according to the predetermined test flow and a pre-stored original word list, and adding the at least one word list data to the original word list to obtain a target word list; updating the initial test environment of the current test by using the target word list;
or constructing at least one commodity material data according to a predetermined test flow and a pre-stored original database, and adding the at least one commodity material data to the original database to obtain a target database; updating the initial test environment of the test by using the target database;
and testing the tested code under the updated test environment by using the target flow of the test.
8. A code testing apparatus, characterized in that the apparatus comprises: the device comprises an acquisition module, an analysis module, a matching module and a test module; wherein the content of the first and second substances,
the acquisition module is used for acquiring coverage rate test data of a previous test aiming at a tested code in the current test aiming at the tested code;
the analysis module is used for analyzing the code and flow relation file of the previous test according to the coverage test data of the previous test;
the matching module is used for matching the code and flow relation file of the previous test with a pre-stored code and flow relation file to obtain the dynamic flow of the previous test;
and the test module is used for determining the target flow of the test according to the dynamic flow of the previous test and the minimum set of pre-stored flows when the tested code is not changed, and testing the tested code by using the target flow of the test.
9. The apparatus according to claim 8, wherein the testing module is further configured to, when the code to be tested changes, obtain, in the pre-stored code-flow relationship file, a new flow corresponding to each function that has changed in the code to be tested; and determining the target flow of the current test according to the newly added flow corresponding to each changed function, the dynamic flow of the previous test and the minimum set of prestored flows, and testing the tested code by using the target flow of the current test.
10. The apparatus of claim 8, further comprising: the device comprises a screening module and a calculation module; wherein the content of the first and second substances,
the screening module is used for screening a second amount of flow from the first amount of flow in the original flow word list according to each flow table entry in the original flow word list and an original module log of the tested code in each function module; wherein each flow table entry comprises: identification SID and parameter information of each flow; dividing the second quantity of flow into N parts of flow, and respectively inputting the N parts of flow into N testing environments; acquiring code coverage Cov files corresponding to all flows through acquisition tasks in all test environments; merging Cov files corresponding to all flows into a full-flow Cov file; wherein N is a natural number greater than 1;
and the calculation module is used for calculating the pre-saved minimum set of flow and the pre-saved code and flow relation file according to the full-flow Cov file.
11. The apparatus of claim 10, wherein:
the calculation module is specifically configured to analyze a coverage characteristic of each flow in the full-flow Cov file according to the SID of each flow in the full-flow Cov file; writing each flow into a first type of flow file corresponding to the flow according to the coverage characteristic of each flow; and carrying out duplicate removal on the flow in each first type flow file through the thread corresponding to each first type flow file, and combining duplicate removal results of each thread to obtain the minimum pre-stored flow set.
12. The apparatus of claim 10, wherein:
the calculation module is specifically used for calculating the primary key of the pre-stored code and flow relation file according to the code file name and the function name of the detected code in each functional module; according to the pre-stored code and the main key of the flow relation file, calculating the coverage characteristic of each flow based on the full-flow Cov file under each main key; mapping each flow into a second type flow file corresponding to each flow according to each primary key; merging the traffic corresponding to the same primary key in each second-class traffic file, and merging the traffic in each second-class traffic file to obtain the pre-stored code and traffic relation file.
13. The apparatus of claim 9, wherein:
the test module is specifically configured to determine each switch combination state of the test according to a logic switch corresponding to an unchanged code in the tested code and a logic switch corresponding to a changed code in the tested code; and testing the tested code by using the target flow of the current test under each switch combination state.
14. The apparatus of claim 8, wherein:
the testing module is specifically used for constructing at least one word list data according to a predetermined testing flow and a pre-stored original word list, and adding the at least one word list data to the original word list to obtain a target word list; updating the initial test environment of the current test by using the target word list; or constructing at least one commodity material data according to a predetermined test flow and a pre-stored original database, and adding the at least one commodity material data to the original database to obtain a target database; updating the initial test environment of the test by using the target database; and testing the tested code under the updated test environment by using the target flow of the test.
15. An electronic device, comprising:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein the content of the first and second substances,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-7.
16. A non-transitory computer readable storage medium having stored thereon computer instructions for causing the computer to perform the method of any one of claims 1-7.
CN202010072030.9A 2020-01-21 2020-01-21 Code testing method and device, electronic equipment and storage medium Pending CN113220560A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010072030.9A CN113220560A (en) 2020-01-21 2020-01-21 Code testing method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010072030.9A CN113220560A (en) 2020-01-21 2020-01-21 Code testing method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN113220560A true CN113220560A (en) 2021-08-06

Family

ID=77085272

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010072030.9A Pending CN113220560A (en) 2020-01-21 2020-01-21 Code testing method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN113220560A (en)

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20150161028A1 (en) * 2013-12-09 2015-06-11 International Business Machines Corporation System and method for determining test coverage
CN105279084A (en) * 2014-06-24 2016-01-27 Sap欧洲公司 Defect localization in software integration tests
US20170132119A1 (en) * 2015-09-25 2017-05-11 EMC IP Holding Company LLC Method and device for retrieving test case based on code coverage
CN109240911A (en) * 2018-08-13 2019-01-18 腾讯科技(北京)有限公司 Accurate test method, device and computer equipment
CN109614341A (en) * 2018-12-29 2019-04-12 微梦创科网络科技(中国)有限公司 A kind of test method and system of code coverage
US10324066B1 (en) * 2015-12-31 2019-06-18 VeriPhase, Inc. System and method for the improved analysis of ultrasonic weld data

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20150161028A1 (en) * 2013-12-09 2015-06-11 International Business Machines Corporation System and method for determining test coverage
CN105279084A (en) * 2014-06-24 2016-01-27 Sap欧洲公司 Defect localization in software integration tests
US20170132119A1 (en) * 2015-09-25 2017-05-11 EMC IP Holding Company LLC Method and device for retrieving test case based on code coverage
US10324066B1 (en) * 2015-12-31 2019-06-18 VeriPhase, Inc. System and method for the improved analysis of ultrasonic weld data
CN109240911A (en) * 2018-08-13 2019-01-18 腾讯科技(北京)有限公司 Accurate test method, device and computer equipment
CN109614341A (en) * 2018-12-29 2019-04-12 微梦创科网络科技(中国)有限公司 A kind of test method and system of code coverage

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
韩;吴波;辛丹;: "一种动静结合的高代码覆盖率模糊测试方法", 信息安全研究, no. 08, 5 August 2016 (2016-08-05) *

Similar Documents

Publication Publication Date Title
CN111080243A (en) Service processing method, device, system, electronic equipment and storage medium
CN111639027B (en) Test method and device and electronic equipment
CN109117141B (en) Method, device, electronic equipment and computer readable storage medium for simplifying programming
US10581791B2 (en) Communication message consolidation with content difference formatting
CN111666206A (en) Method, device, equipment and storage medium for acquiring influence range of change code
CN113076104A (en) Page generation method, device, equipment and storage medium
CN111506803A (en) Content recommendation method and device, electronic equipment and storage medium
CN111913808A (en) Task allocation method, device, equipment and storage medium
CN111913998A (en) Data processing method, device, equipment and storage medium
US11086899B2 (en) On demand synchronization of information
CN109561212B (en) Merging method, device, equipment and storage medium for published information
CN111241396B (en) Information pushing method and device, electronic equipment and storage medium
CN111581518A (en) Information pushing method and device
CN113220560A (en) Code testing method and device, electronic equipment and storage medium
CN110909390A (en) Task auditing method and device, electronic equipment and storage medium
CN112822302B (en) Data normalization method and device, electronic equipment and storage medium
CN114995875A (en) Page component configuration method and device, electronic equipment and storage medium
CN114661274A (en) Method and device for generating intelligent contract
US20120016890A1 (en) Assigning visual characteristics to records
CN113138760A (en) Page generation method and device, electronic equipment and medium
CN113467941A (en) Method and device for sharing information
CN111694686A (en) Abnormal service processing method and device, electronic equipment and storage medium
CN111708582A (en) Online configuration method and device and electronic equipment
CN111831317A (en) Method and device for acquiring dependency relationship between services, electronic equipment and storage medium
CN112738567B (en) Platform content processing method and device, electronic equipment and storage medium

Legal Events

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