[go: up one dir, main page]

CN113220560B - 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
CN113220560B
CN113220560B CN202010072030.9A CN202010072030A CN113220560B CN 113220560 B CN113220560 B CN 113220560B CN 202010072030 A CN202010072030 A CN 202010072030A CN 113220560 B CN113220560 B CN 113220560B
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.)
Active
Application number
CN202010072030.9A
Other languages
Chinese (zh)
Other versions
CN113220560A (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 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/CN113220560B/en
Publication of CN113220560A publication Critical patent/CN113220560A/en
Application granted granted Critical
Publication of CN113220560B publication Critical patent/CN113220560B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR 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; CALCULATING OR 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)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

The application discloses a code testing method, a code testing 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 the previous test of the tested code in the current test of 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 the pre-stored code and flow relation file to obtain the dynamic flow of the previous test; when the tested code is not changed, determining the target flow of the current test according to the dynamic flow of the previous test and the pre-stored minimum flow set, and testing the tested code by using the target flow of the current test. The embodiment of the application can effectively improve the code coverage rate, thereby improving the code test quality without inputting labor cost and equipment cost.

Description

Code testing method and device, electronic equipment and storage medium
Technical Field
The application relates to the technical field of computer application, in particular to a software testing technology, and particularly relates to a code testing method, a device, electronic equipment and a storage medium.
Background
Code Coverage (Code Coverage) is a measure in software testing that describes the proportion and extent to which source Code is tested in a program, and the resulting proportion is called Code Coverage, which is an important indicator of measuring test capability and test integrity. In the existing code testing method, the logs of partial time periods are randomly selected in 1-2 machines as the testing flow, and the testing flow is randomly selected, so that the tested codes can be insufficiently evaluated through the testing flow, the problem of insufficient code coverage rate exists, and a large online quality risk exists in continuous rapid iteration. Therefore, the coverage of the codes can be improved, the coverage scene of the test can be further expanded, the code test quality is improved, the code loopholes are cared early, and the potential safety hazards on the line are intercepted.
Disclosure of Invention
In view of this, the embodiments of the present application provide a code testing method, apparatus, electronic device, and storage medium, which can effectively improve code coverage, so that code testing quality can be improved, and no human cost and equipment cost are required.
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 the previous test of the tested code in the current test of the tested code;
according to the coverage test data of the previous test, analyzing a code and flow relation file 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 current test according to the dynamic flow of the previous test and a pre-stored minimum flow set, and testing the tested code by using the target flow of the current test.
The above embodiment has the following advantages or beneficial effects: according to the embodiment, the two basic data, namely the minimum flow set and the code and the flow relation file, are determined in advance for the condition that the tested code is not changed, and the dynamic flow of the previous test can be obtained by matching the code and the flow relation file of the previous test with the pre-stored code and the 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 pre-stored flow minimum set in the current test, and then the tested code 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, the logs of partial time periods are generally randomly selected from 1-2 machines to serve as testing flow, and the testing flow is randomly selected, so that the tested codes can be insufficiently evaluated through the testing flow, and the problem of insufficient code coverage rate exists. Because the application adopts the technical means of predetermining the minimum flow set and the code and flow relation file, and combines and de-duplicated the dynamic flow of the previous test and the pre-stored minimum flow set in the current test, the target flow of the current test is determined, the technical problem of insufficient code coverage rate in the prior art is overcome, and the technical effects of improving the code coverage rate and the code test quality are further achieved.
In the above embodiment, the method further includes:
When the tested code is changed, acquiring new flow corresponding to each function changed in the tested code from the pre-stored code and flow relation file; and determining the target flow of the current test according to the newly-increased flow corresponding to each changed function, the dynamic flow of the previous test and the pre-stored minimum flow set, and testing the tested code by using the target flow of the current test.
The above embodiment has the following advantages or beneficial effects: according to the embodiment, aiming at the condition that the tested code is changed, the target flow of the current test is determined according to the newly-increased flow corresponding to each changed function, the dynamic flow of the previous test and the pre-stored minimum flow set, so that the tested code can be tested by using the target flow of the current test.
In the above embodiment, before the coverage test data of the previous test for the code under test is obtained in the present test for the code under test, the method further includes:
screening out a second number of flows from a first number of flows in an original flow vocabulary according to each flow table item in the original flow vocabulary and an original module log of the tested code in each functional module; wherein each flow meter 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 test environments; collecting code coverage Cov files corresponding to each flow through collecting tasks in each test environment; combining Cov files corresponding to each flow into a full-flow Cov file; wherein N is a natural number greater than 1;
and calculating the pre-stored minimum flow set and the pre-stored 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 two basic data can be used for testing the tested code in the test.
In the foregoing embodiment, the calculating the pre-saved traffic minimum set according to the full traffic Cov file includes:
according to the SID of each flow in the full-flow Cov file, analyzing the coverage characteristic of each flow in the full-flow Cov file;
Writing each flow into a corresponding first type flow file according to the coverage characteristic of each flow;
And carrying out de-duplication on the flow in each first type flow file through the thread corresponding to each first type flow file, and merging de-duplication results of each thread to obtain the pre-stored flow minimum set.
The above embodiment has the following advantages or beneficial effects: the above embodiment may determine the minimum flow set in advance before the present test, where the code to be tested may be tested using the minimum flow set.
In the foregoing embodiment, the calculating the pre-saved code and flow relation file according to the full-flow Cov file includes:
Calculating a primary key of the pre-stored code and flow relation file according to the code file name and function name of the tested code in each functional module;
According to the pre-stored codes and the main keys of the flow relation file, calculating the coverage characteristics of each flow under each main key based on the full-flow Cov file;
mapping each flow to a corresponding second class flow file according to each primary key;
and merging the flows corresponding to the same primary key in each second type flow file, and merging the flows in each second type flow file to obtain the pre-stored code and flow relation file.
The above embodiment has the following advantages or beneficial effects: the above embodiment can pre-determine the code and flow relation file before the current test, and the code and flow relation file can be used for testing the tested code in the current test.
In the above embodiment, the testing the tested code using the target traffic of the current test includes:
Determining the combination state of each switch 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 under each switch combination state by using the target flow of the test.
The above embodiment has the following advantages or beneficial effects: the above embodiment can determine the combination state of each switch, and in the present test, the tested code can be tested under each switch combination state by using the target flow of the present test.
In the above embodiment, the testing the tested code using the target traffic of the current test includes:
Constructing at least one vocabulary data according to a predetermined test flow and a pre-stored original vocabulary, and adding the at least one vocabulary data into the original vocabulary to obtain a target vocabulary; updating the initial test environment of the current test by using the target vocabulary;
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 current test by using the target database;
And testing the tested code in the updated testing environment by using the target flow of the current test.
The above embodiment has the following advantages or beneficial effects: the above embodiment can update the initial test environment of the current test by using the target vocabulary, or update the initial test environment of the current test by using the target database, so that the tested code can be tested under the updated test environment by using the target flow of the current test.
In a second aspect, the present application also provides a code testing device, the device comprising: the device comprises an acquisition module, an analysis module, a matching module and a test module; wherein,
The acquisition module is used for acquiring coverage rate test data of the previous test of the tested code in the current test of 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 current test according to the dynamic flow of the previous test and a pre-stored minimum flow set when the tested code is not changed, and testing the tested code by using the target flow of the current test.
In the above embodiment, the test module is further configured to obtain, when the tested code changes, a new flow corresponding to each function that changes in the tested code in the pre-stored code-flow relation file; and determining the target flow of the current test according to the newly-increased flow corresponding to each changed function, the dynamic flow of the previous test and the pre-stored minimum flow set, and testing the tested code by using the target flow of the current test.
In the above embodiment, the apparatus further includes: a screening module and a calculating module; wherein,
The screening module is used for screening the second quantity of flow from the first quantity of flow in the original flow vocabulary according to each flow table item in the original flow vocabulary and the original module log of the tested code in each functional module; wherein each flow meter 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 test environments; collecting code coverage Cov files corresponding to each flow through collecting tasks in each test environment; combining Cov files corresponding to each flow 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-stored minimum flow set and the pre-stored code and flow relation file according to the full-flow Cov file.
In the foregoing embodiment, the computing module is specifically configured to analyze, according to the SID of each flow in the full-flow Cov file, a coverage feature of each flow in the full-flow Cov file; writing each flow into a corresponding first type flow file according to the coverage characteristic of each flow; and carrying out de-duplication on the flow in each first type flow file through the thread corresponding to each first type flow file, and merging de-duplication results of each thread to obtain the pre-stored flow minimum set.
In the above embodiment, the calculating module is specifically configured to calculate, according to the code file name and the function name of the code under test in each function module, a primary key of the pre-stored code and flow relation file; according to the pre-stored codes and the main keys of the flow relation file, calculating the coverage characteristics of each flow under each main key based on the full-flow Cov file; mapping each flow to a corresponding second class flow file according to each primary key; and merging the flows corresponding to the same primary key in each second type flow file, and merging the flows in each second type flow file to obtain the pre-stored code and flow relation file.
In the above embodiment, the test module is specifically configured to determine, according to a logic switch corresponding to a code that is not changed in the tested code and a logic switch corresponding to a code that is changed in the tested code, each switch combination state of the current test; and testing the tested code under each switch combination state by using the target flow of the test.
In the foregoing 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 vocabulary; 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 current test by using the target database; and testing the tested code in the updated testing environment by using the target flow of the current 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,
The one or more programs, when executed by the one or more processors, cause the one or more processors to implement the code testing method described in any of the embodiments of the present application.
In a fourth aspect, an embodiment of the present application provides a storage medium having stored thereon a computer program which, when executed by a processor, implements the code testing method according to any embodiment of the present application.
One embodiment of the above application has the following advantages or benefits: the code testing method, the device, the electronic equipment and the storage medium provided by the application are characterized in that coverage rate testing data of the previous test of the tested code are obtained in the current test of the tested code; then 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 the pre-stored code and flow relation file to obtain the dynamic flow of the previous test; when the tested code is not changed, determining the target flow of the current test according to the dynamic flow of the previous test and the pre-stored minimum flow set, and testing the tested code by using the target flow of the current test. In other words, the application can determine the minimum flow set and two basic data of the code and the flow relation file in advance, and in the current test, the dynamic flow of the previous test can be obtained by matching the code and the flow relation file of the previous test with the pre-stored code and the flow relation file, so that the target flow of the current test can be determined according to the dynamic flow of the previous test and the pre-stored flow minimum set in the current test, and then the tested code 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, the logs of partial time periods are generally randomly selected from 1-2 machines to serve as testing flow, and the testing flow is randomly selected, so that the tested codes can be insufficiently evaluated through the testing flow, and the problem of insufficient code coverage rate exists. Because the application adopts the technical means of predetermining the minimum flow set and the code and flow relation file, and combines and de-weights the dynamic flow of the previous test and the pre-stored minimum flow set in the current test, the target flow of the current test is determined, the technical problem of insufficient code coverage rate in the prior art is overcome, and the technical effects of improving the code coverage rate and the code test quality are further achieved; in addition, the technical scheme of the embodiment of the application is simple and convenient to realize, convenient to popularize and wider in application range.
Other effects of the above alternative will be described below in connection with specific embodiments.
Drawings
The drawings are included to provide a better understanding of the present application and are not to be construed as limiting the application. Wherein:
FIG. 1 is a flow chart of a code testing method according to an embodiment of the application;
fig. 2 is a flow chart of a code testing method according to a second embodiment of the present application;
FIG. 3 is a schematic diagram of a first configuration of a code testing device according to a third embodiment of the present application;
FIG. 4 is a second schematic diagram of a code testing device 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 of an embodiment of the present application.
Detailed Description
Exemplary embodiments of the present application will now be described with reference to the accompanying drawings, in which various details of the embodiments of the present application are included to facilitate understanding, and are to be considered merely exemplary. 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 application. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
Example 1
Fig. 1 is a schematic flow chart of a code testing method according to an embodiment of the present application, where the method may be performed by a code testing device or an electronic device, and the device or the electronic device may be implemented by software and/or hardware, and the device or the electronic device may be integrated into any intelligent device having a network communication function. As shown in fig. 1, the code testing method may include the steps of:
s101, acquiring coverage rate test data of the previous test of the tested code in the current test of the tested code.
In a specific embodiment of the present application, cov (Code Coverage) files refer to code overlay files; to describe the proportion and extent to which source code is tested in a program, the resulting proportion is called code coverage, which is an important indicator of the measurement of test capability and test integrity. SID refers to an identification (Identity Documen) of each traffic, representing a unique code for each traffic. Jenkins is an open source software project, is a continuous integration tool based on Java development, is used for monitoring continuous repeated work, and aims to provide an open and easy-to-use software platform so that continuous integration of software is possible. xstp refers to the environment of the object under test. sshpass refers to an interactive-free SSH login tool, where SSH login cannot specify a password in the command line, sshpass allows a plaintext password to be specified with parameters, and then logs directly into the remote server, which supports the password to be read from the command line, file, environment variables. MD5, collectively referred to as the MD5 Message-Digest Algorithm (MD 5 Message-Digest Algorithm), is a widely used cryptographic hash function that produces a 128-bit (16-byte) hash value that is used to ensure that the information transfer is completely consistent.
In a specific embodiment of the present application, the electronic device may obtain coverage rate test data of a previous test for a code under test in the current test for the code under test; the coverage rate test data of the previous test may be a Cov file of the previous test. In the implementation of the specific scheme, the electronic device can test the tested code once a day, and in this step, the electronic device can acquire coverage rate test data of a previous day test of the tested code in the current day test of the tested code; the test coverage rate test data of the previous day may be a Cov file of the previous day test.
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 parse the code and flow relation file of the previous test according to the coverage test data of the previous test. In particular, the overlay test data may include one or more of source file level filtering information, function level filtering information, and code line level filtering information. Further, the source file level filtering information includes overlay source file information; the function level filtering information comprises overlay source file function information; the code line level filtering information includes information of the number of lines of the overlay code and/or branching condition information of the overlay code line. In the step, the electronic equipment analyzes the coverage test data of the previous test to obtain the code and flow relation file of the previous test. Preferably, the electronic device may further obtain a code that is not covered by the tested code in the previous test by analyzing the coverage test data of the previous test.
And S103, matching the code and flow relation file of the previous test with the 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 relation file of the previous test with the pre-stored code and flow relation file, so as to obtain the dynamic flow of the previous test. In particular, the data structure of the code-to-flow relationship file may be expressed as: code filename/function name/flow set. It is assumed that the pre-saved code-to-flow 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 flow 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 is known that a flow 2 is added in 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 current test according to the dynamic flow of the previous test and the pre-stored minimum flow set, and testing the tested code by using the target flow of the current test.
In a specific embodiment of the present application, when the tested code is unchanged, the electronic device may determine the target flow of the current test according to the dynamic flow of the previous test and the minimum set of flows stored in advance, and then use the target flow of the current test to test the tested code. Specifically, the electronic device may combine and de-duplicate the dynamic flow of the previous test and the flow in the minimum set of pre-stored flows, and determine the flow after combining and de-duplication as the target flow 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, when a measured code is changed, the electronic device may obtain, in a pre-stored code and flow relation file, a new flow corresponding to each function that is changed in the measured code; and determining the target flow of the current test according to the newly-increased flow corresponding to each changed function, the dynamic flow of the previous test and the pre-stored minimum flow set, and testing the tested code by using the target flow of the current test. Specifically, the electronic device may combine and de-duplicate the newly-increased flow corresponding to each changed function with the dynamic flow of the previous test and the flow in the minimum set of the pre-stored flows, and determine the flow after combining and de-duplication as the target flow 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 the previous test of the tested code in the current test of the tested code; then 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 the pre-stored code and flow relation file to obtain the dynamic flow of the previous test; when the tested code is not changed, determining the target flow of the current test according to the dynamic flow of the previous test and the pre-stored minimum flow set, and testing the tested code by using the target flow of the current test. In other words, the application can determine the minimum flow set and two basic data of the code and the flow relation file in advance, and in the current test, the dynamic flow of the previous test can be obtained by matching the code and the flow relation file of the previous test with the pre-stored code and the flow relation file, so that the target flow of the current test can be determined according to the dynamic flow of the previous test and the pre-stored flow minimum set in the current test, and then the tested code 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, the logs of partial time periods are generally randomly selected from 1-2 machines to serve as testing flow, and the testing flow is randomly selected, so that the tested codes can be insufficiently evaluated through the testing flow, and the problem of insufficient code coverage rate exists. Because the application adopts the technical means of predetermining the minimum flow set and the code and flow relation file, and combines and de-weights the dynamic flow of the previous test and the pre-stored minimum flow set in the current test, the target flow of the current test is determined, the technical problem of insufficient code coverage rate in the prior art is overcome, and the technical effects of improving the code coverage rate and the code test quality are further achieved; in addition, the technical scheme of the embodiment of the application is simple and convenient to realize, convenient to popularize and wider in application range.
Example two
Fig. 2 is a flow chart of a code testing method according to a second embodiment of the application. As shown in fig. 2, the code testing method may include the steps of:
S201, screening out a second number of flows from a first number of flows in an original flow vocabulary according to each flow table item in the original flow vocabulary and an original module log of a tested code in each functional module; wherein each flow meter entry comprises: SIDs and parameter information for each flow.
In a specific embodiment of the present application, the electronic device may screen out a second number of flows from a first number of flows in the original flow vocabulary according to each flow table entry in the original flow vocabulary and an original module log of the tested code in each function module; wherein each flow meter entry comprises: SIDs and parameter information for each flow. Specifically, the flow vocabulary is an information table of flow parameters (for example, may be request parameters) represented by SID; the original module log is a path, track and other parameters of each flow expressed in a text format; wherein one SID corresponds to one traffic; one flow corresponds to one original module log. Assume that the code to be tested involves three modules, namely module A, module B and module C; the flow vocabulary includes three flows, respectively: SID1, SID2, SID3. The process of screening out the second number of flows from the first number of flows in the original flow vocabulary in this step may be referred to as coarse screening; wherein, the coarse screen can be divided into: and (3) two links of flow expansion and flow countercompensation. In the flow expansion process, the electronic device may first match SID1 with each original module log in modules a, B and C, to obtain an original module log matched with SID1, and record the original module log as: original module log 1; then, SID2 is matched with each original module log in the module A, the module B and the module C respectively, so that an original module log matched with SID2 is obtained and recorded as follows: original module log 2; then, SID3 is matched with each original module log in the module A, the module B and the module C respectively, so that an original module log matched with SID3 is obtained and recorded as follows: an original module log 3; then, respectively calculating log features of an original module log 1, an original module log 2 and an original module log 3, and merging the calculated log features; because the log features and the flows in the original flow vocabulary have a one-to-one correspondence, the original module log with the same log features is de-duplicated, so that the flows with the same log features can be removed in the original flow vocabulary, and the flows with different log features are screened out and used as expansion flows. For example, the process of coarse flow screening can be implemented to screen 20 ten thousand flows out of 300 ten thousand flows as extended flows. In the flow countercompensation process, the electronic equipment can test the tested code by using a first number of flows (for example, 300 ten thousand) to obtain a test result corresponding to the first number of flows; 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 are test results that are not present in the test results corresponding to the expanded flow rate among the test results corresponding to the first number of flow rates, it is possible to obtain 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 expanded flow rate, and add the flow rates (for example, 10 ten thousand) corresponding to these test results as the countercompensation flow rates to the expanded flow rates, so as to obtain a second number of flow rates of 30 ten thousand.
For example, the specific process of the electronic device in matching SID1 with each of the original module logs in module a, module B, and module C may be: firstly, matching SID1 with each original module log in a module A, and obtaining an original module log A1 matched with SID1 in the module A; then matching SID1 with each original module log in the module B, and obtaining an original module log B1 matched with SID1 in the module B; matching SID1 with each original module log in the module C, and obtaining an original module log C1 matched with SID1 in the module C; and combining the original module log A1, the original module log B1 and the original module log C2 to obtain the original module log 1.
S202, dividing the second quantity of flow into N flows, and respectively inputting the N flows into N test environments; collecting Cov files corresponding to each flow through collecting tasks in each test environment; combining Cov files corresponding to each flow 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 number of flows into N flows, and input the N flows into N test environments respectively; collecting Cov files corresponding to each flow through collecting tasks in each test environment; combining Cov files corresponding to each flow 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 collect Cov files corresponding to each flow in the first flow through an acquisition task in the first test environment; inputting the second flow into a second test environment, and collecting Cov files corresponding to each flow in the second flow through a collection task in the second test environment; …; inputting the Nth flow into an Nth testing environment, and collecting Cov files corresponding to each flow in the Nth flow through a collection task in the Nth testing environment. These Cov files are then combined into a full flow Cov file. For example, in this step, the electronic device may divide the 30 ten thousand flows into 10 parts, each 3 ten thousand, and if the test environments are 10, the first 3 ten thousand flows are allocated to the test environment 1, the second 3 ten thousand flows are allocated to the test environments 2, …, and the tenth 3 ten thousand flows are allocated 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 xstp environments again, start an acquisition task through sshpass, request one of the modules (assuming that the module a may be used), call the other modules (assuming that the module B and the module C may be used) through the requested module, and then obtain Cov files corresponding to each flow in each flow.
S203, calculating a pre-stored flow minimum set and a pre-stored 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-flow Cov file, where the two basic data are respectively: the flow minimum set and the code and flow relation file are then saved together as a pre-saved flow minimum set and a pre-saved code and flow relation file. In particular implementations, the electronic device may calculate the minimum set of flows and the code-to-flow relationship file once per week.
In the specific embodiment of the application, in the process of calculating the flow minimum set according to the full-flow Cov file, the electronic equipment can 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 corresponding first type flow file according to the coverage characteristic of each flow; and then, carrying out de-duplication on the flow in each first type flow file through the thread corresponding to each first type flow file, and merging de-duplication results of each thread to obtain a pre-stored flow minimum set. 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 row of code is covered by a certain traffic; a 1 indicates that a certain line of code is not covered by a certain traffic. In order to improve the analysis speed, the coverage characteristics of each flow can be calculated through multithreading, and the flow is written into a plurality of first-class flow files after being hashed and mapped according to the MD5 value of the coverage characteristics; and then, carrying out de-duplication on the data in each first class flow file by using multithreading, and finally merging the calculation results of each thread to obtain a flow minimum set.
In the 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 equipment can calculate the primary key of the pre-stored code and flow relation file according to the code file name and function name of the tested 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 under each main key based on the full-flow Cov file; the specific calculation method is the same as the minimum set; then mapping each flow to a corresponding second class flow file according to each main key; and merging the flows corresponding to the same primary key in each second type of flow file, and merging the flows in each second type of flow file to obtain a pre-stored code and flow relation file. When the specific scheme is realized, a certain number of truncations can be performed according to the principle of the even distribution of the coverage characteristics. For example, for primary key 1, there are 100 flows, five overlay features, if 60 are truncated, 60/5=12 per overlay feature is chosen.
By way of example, the traffic minimums: assume three flows, respectively: traffic 1 (SID 1), traffic 2 (SID 2) and traffic 3 (SID 3); two lines of codes are respectively: code 1 and code 2; assume that traffic 1 covers code 1 and code 3; traffic 2 overlays code 2; traffic 3 covers code 1 and code 3; since both traffic 1 and traffic 3 are the overlay code 1 and code 3, traffic 3 can be deleted and only traffic 1 and traffic 2 are reserved, so the set consisting of traffic 1 and traffic 2 is the traffic minimum set. Code versus coverage traffic 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 traffic. For example: code file name 1/function name 1/flow 1 and flow 2, meaning that function 1 in code file 1 is covered by flow 1 and flow 2.
In the specific embodiment of the application, aiming at the codes which are not covered in the previous test, the electronic equipment can screen out the increment flow from the obtained code and flow relation file; the screening process occurs in the following order: 1. flow that can be covered to the modification function; 2. traffic to the modification file can be covered. Firstly, acquiring the flow which can be covered to the modification function; if the flow which can be covered by the modification function is not obtained, the flow which can be covered by the modification file is obtained.
S204, acquiring coverage rate test data of the previous test of the tested code in the current test of the tested code.
In a specific embodiment of the present application, the electronic device may obtain coverage rate test data of a previous test for a code under test in the current test for the code under test; the coverage rate test data of the previous test may be a Cov file of the previous test. In the implementation of the specific scheme, the electronic device can test the tested code once a day, and in this step, the electronic device can acquire coverage rate test data of a previous day test of the tested code in the current day test of the tested code; the test coverage rate test data of the previous day may be a Cov file of the previous day test.
S205, 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 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 tested code in the previous test by analyzing the coverage test data of the previous test.
S206, matching the code and flow relation file of the previous test with the 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 relation file of the previous test with the pre-stored code and flow relation file, so as to obtain the dynamic flow of the previous test. In particular, the data structure of the code-to-flow relationship file may be expressed as: code filename/function name/flow set. In this step, the electronic device may compare each line in the code and flow relation file tested previously 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 from 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 during the process of acquiring the dynamic flow of the previous test. In particular, for complex modules, insufficient traffic can easily result in too low a coverage ratio for some traffic. Therefore, in the technical scheme provided by the application, firstly, the offline test flow can be extracted by analyzing the characteristic field of the log; secondly, calculating the duty ratio of the specific service flow of the online environment; finally, the duty ratio of the off-line test flow is adjusted by the duty ratio of the on-line environment specific service flow and the flow which can cover the specific service off-line.
S207, when the tested code is not changed, determining the target flow of the current test according to the dynamic flow of the previous test and the pre-stored minimum flow set, and testing the tested code by using the target flow of the current test.
In a specific embodiment of the present application, when the tested code is unchanged, the electronic device may determine the target flow of the current test according to the dynamic flow of the previous test and the minimum set of flows stored in advance, and then use the target flow of the current test to test the tested code. Specifically, the electronic device may combine and de-duplicate the dynamic flow of the previous test and the flow in the minimum set of pre-stored flows, and determine the flow after combining and de-duplication as the target flow 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, when a measured code is changed, the electronic device may obtain, in a pre-stored code and flow relation file, a new flow corresponding to each function that is changed in the measured code; and determining the target flow of the current test according to the newly-increased flow corresponding to each changed function, the dynamic flow of the previous test and the pre-stored minimum flow set, and testing the tested code by using the target flow of the current test. Specifically, the electronic device may combine and de-duplicate the newly-increased flow corresponding to each changed function with the dynamic flow of the previous test and the flow in the minimum set of the pre-stored flows, and determine the flow after combining and de-duplication as the target flow 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, in a process of testing a tested code by using a target flow of the present test, the electronic device may determine a combination state of each switch of the present test according to a logic switch corresponding to a code that has not been changed in the tested code and a logic switch corresponding to a code that has been changed in the tested code; and then testing the tested code in each switch combination state by using the target flow of the test. For example, assume that the logical switch corresponding to the unchanged code in the tested code is: a switch 1; the logic switch corresponding to the changed code in the tested code is assumed to be: a switch 2 and a switch 3; in this step, the electronic device may determine eight switch combination states, which are: switch 1 is opened, switch 2 is closed, and switch 3 is closed; switch 1 is closed, switch 2 is opened, and switch 3 is closed; switch 1 is closed, switch 2 is closed, and switch 3 is opened; switch 1 is on, switch 2 is on, and switch 3 is off; switch 1 is closed, switch 2 is opened, and switch 3 is opened; switch 1 is opened, switch 2 is closed, and switch 3 is opened; switch 1 is opened, switch 2 is opened, and switch 3 is opened; 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 tested code by using a target flow of the present test, an 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 an initial test environment of the test by using the target word list; or constructing at least one commodity material data according to the predetermined test flow and the pre-stored original database, and adding the at least one commodity material data to the original database to obtain a target database; updating an initial test environment of the test by using a target database; and then testing the tested code in the updated testing environment by using the target flow of the test. In the process of constructing the vocabulary data, firstly, core field data which can be covered in one test process, such as advertisement ID and account ID, are obtained by a code instrumentation mode; thirdly, analyzing the uncovered vocabulary files by analyzing the code coverage; and finally, inserting part of vocabulary data through matching the vocabulary file with the core field data. In addition, in the process of constructing commodity material data, firstly, acquiring commodity ID information which can be covered, and secondly, acquiring commodity material data; and thirdly, analyzing commodity coverage conditions based on carding rules, and modifying a small amount of commodity data for insufficient coverage rules. Such as the need to cover online merchandise, expired merchandise, etc. for the effective time of the merchandise.
By way of example, building vocabulary data may be a scheme of adding an ID to a configuration file; building commodity material data may be a scheme of adding or modifying commodity attributes in a database. In the scheme for constructing the vocabulary, three flows are assumed, which are respectively: traffic 1, traffic 2 and traffic 3, each of which can cover 3 IDs (here ID means core field data, such as advertisement ID or user ID), then three traffic can cover 9 IDs, assuming ID11-ID19, assuming only one ID1 in the original vocabulary, then in the scheme of building the vocabulary, several IDs of ID11-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 the previous test of the tested code in the current test of the tested code; then 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 the pre-stored code and flow relation file to obtain the dynamic flow of the previous test; when the tested code is not changed, determining the target flow of the current test according to the dynamic flow of the previous test and the pre-stored minimum flow set, and testing the tested code by using the target flow of the current test. In other words, the application can determine the minimum flow set and two basic data of the code and the flow relation file in advance, and in the current test, the dynamic flow of the previous test can be obtained by matching the code and the flow relation file of the previous test with the pre-stored code and the flow relation file, so that the target flow of the current test can be determined according to the dynamic flow of the previous test and the pre-stored flow minimum set in the current test, and then the tested code 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, the logs of partial time periods are generally randomly selected from 1-2 machines to serve as testing flow, and the testing flow is randomly selected, so that the tested codes can be insufficiently evaluated through the testing flow, and the problem of insufficient code coverage rate exists. Because the application adopts the technical means of predetermining the minimum flow set and the code and flow relation file, and combines and de-weights the dynamic flow of the previous test and the pre-stored minimum flow set in the current test, the target flow of the current test is determined, the technical problem of insufficient code coverage rate in the prior art is overcome, and the technical effects of improving the code coverage rate and the code test quality are further achieved; in addition, the technical scheme of the embodiment of the application is simple and convenient to realize, convenient to popularize and wider in application range.
Example III
Fig. 3 is a schematic diagram of a first structure of a code testing device 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 acquiring module 301 is configured to acquire coverage rate test data of a previous test for a code to be tested in the current test for the code to be tested;
the parsing module 302 is configured to parse the 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 relation file of the previous test with a pre-stored code and flow relation file, so as to obtain a dynamic flow of the previous test;
And the test module 304 is configured to determine, when the tested code is unchanged, the target flow of the current test according to the dynamic flow of the previous test and a pre-stored minimum flow set, and test the tested code using the target flow of the current test.
Further, the test module 304 is further configured to obtain, when the tested code changes, a new flow corresponding to each function that changes in the tested code in the pre-stored code-flow relation file; and determining the target flow of the current test according to the newly-increased flow corresponding to each changed function, the dynamic flow of the previous test and the pre-stored minimum flow set, 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 device 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 screening module 305 is configured to screen a second number of flows from a first number of flows in the original flow vocabulary according to each flow table item in the original flow vocabulary and an original module log of the tested code in each function module; wherein each flow meter 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 test environments; collecting Cov files corresponding to each flow through collecting tasks in each test environment; combining Cov files corresponding to each flow 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 traffic minimum set and the pre-saved code-traffic relation file according to the full-traffic Cov file.
Further, the calculating module 306 is specifically configured to analyze the coverage feature 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 corresponding first type flow file according to the coverage characteristic of each flow; and carrying out de-duplication on the flow in each first type flow file through the thread corresponding to each first type flow file, and merging de-duplication results of each thread to obtain the pre-stored flow minimum set.
Further, the calculating module 306 is specifically configured to calculate, according to the code file name and the function name of the tested code in each function module, the primary key of the pre-stored code and flow relation file; according to the pre-stored codes and the main keys of the flow relation file, calculating the coverage characteristics of each flow under each main key based on the full-flow Cov file; mapping each flow to a corresponding second class flow file according to each primary key; and merging the flows corresponding to the same primary key in each second type flow file, and merging the flows in each second type flow file to obtain the pre-stored code and flow relation file.
Further, the test module 306 is specifically configured to determine, 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, each switch combination state of the current test; and testing the tested code under each switch combination state by using the target flow of the test.
Further, the test module 306 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 vocabulary; 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 current test by using the target database; and testing the tested code in the updated testing environment by using the target flow of the current 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 executing the method. Technical details not described in detail in this embodiment may be referred to the code testing method provided in any embodiment of the present application.
Example IV
According to an embodiment of the present application, the present application also provides an electronic device and a readable storage medium.
As shown in fig. 5, a block diagram of an electronic device of a code testing method 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 telephones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are meant to be exemplary only, and are not meant to limit implementations of the applications described and/or claimed herein.
As shown in fig. 5, the electronic device includes: one or more processors 501, memory 502, and interfaces for connecting 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 executing within the electronic device, including instructions stored in or on memory to display graphical information of the GUI on an external input/output device, such as a display device coupled to the interface. In other embodiments, multiple processors and/or multiple buses may be used, if desired, along with multiple memories and multiple memories. Also, multiple electronic devices may be connected, each providing a portion of the necessary operations (e.g., as a server array, a set of blade servers, or a multiprocessor system). One processor 501 is illustrated in fig. 5.
Memory 502 is a non-transitory computer readable storage medium provided by the present application. The memory stores instructions executable by the at least one processor to cause the at least one processor to perform the code testing method provided by the present application. The non-transitory computer readable storage medium of the present application stores computer instructions for causing a computer to execute the code test method provided by the present application.
The memory 502 is used as a non-transitory computer readable storage medium for storing non-transitory software programs, non-transitory computer executable programs, and modules, such as program instructions/modules (e.g., the acquisition module 301, the parsing module 302, the matching module 303, and the testing module 304 shown in fig. 3) corresponding to the code testing method in the embodiment of the present application. The processor 501 executes various functional applications of the server and data processing by running non-transitory software programs, instructions, and modules stored in the memory 502, i.e., implements the code testing method in the method embodiments described above.
Memory 502 may include a storage program area that may store an operating system, at least one application program required for functionality, and a storage data area; the storage data area may store data created according to the use of the electronic device of the code test method, and the like. In addition, 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 may optionally include memory located remotely from processor 501, which may be connected to the electronic device of the code testing method via 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 test method may further include: an input device 503 and an output device 504. The processor 501, memory 502, input devices 503 and output devices 504 may be connected by a bus or otherwise, for example in fig. 5.
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 device of the code testing method, such as a touch screen, a keypad, a mouse, a track pad, a touch pad, a pointer stick, one or more mouse buttons, a track ball, a joystick, and the like. The output devices 504 may include a display device, auxiliary lighting devices (e.g., LEDs), and haptic feedback devices (e.g., vibration 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 may be a touch screen.
Various implementations of the systems and techniques described here can be realized in digital electronic circuitry, integrated circuitry, application specific ASIC (application specific integrated circuit), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include: implemented in one or more computer programs, the one or more computer programs may be executed and/or interpreted on a programmable system including at least one programmable processor, which may be a special purpose or general-purpose programmable processor, that may receive data and instructions from, and transmit data and instructions to, a storage system, at least one input device, and at least one output device.
These computing programs (also referred to as programs, software applications, or code) include machine instructions for a programmable processor, and may be implemented in a high-level procedural and/or object-oriented programming language, and/or in assembly/machine language. 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 pointing device (e.g., a mouse or 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 may 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 input, speech input, or tactile input.
The systems and techniques described here can be implemented in a computing system that includes a background 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 background, 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 a client and a server. The client and server are typically 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, coverage rate test data of the previous test of the tested code are obtained in the current test of the tested code; then 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 the pre-stored code and flow relation file to obtain the dynamic flow of the previous test; when the tested code is not changed, determining the target flow of the current test according to the dynamic flow of the previous test and the pre-stored minimum flow set, and testing the tested code by using the target flow of the current test. In other words, the application can determine the minimum flow set and two basic data of the code and the flow relation file in advance, and in the current test, the dynamic flow of the previous test can be obtained by matching the code and the flow relation file of the previous test with the pre-stored code and the flow relation file, so that the target flow of the current test can be determined according to the dynamic flow of the previous test and the pre-stored flow minimum set in the current test, and then the tested code 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, the logs of partial time periods are generally randomly selected from 1-2 machines to serve as testing flow, and the testing flow is randomly selected, so that the tested codes can be insufficiently evaluated through the testing flow, and the problem of insufficient code coverage rate exists. Because the application adopts the technical means of predetermining the minimum flow set and the code and flow relation file, and combines and de-weights the dynamic flow of the previous test and the pre-stored minimum flow set in the current test, the target flow of the current test is determined, the technical problem of insufficient code coverage rate in the prior art is overcome, and the technical effects of improving the code coverage rate and the code test quality are further achieved; in addition, the technical scheme of the embodiment of the application is simple and convenient to realize, convenient to popularize and wider in application range.
It should be appreciated that various forms of the flows shown above may be used to reorder, add, or delete steps. For example, the steps described in the present application may be performed in parallel, sequentially, or in a different order, provided that the desired results of the disclosed embodiments are achieved, and are not limited herein.
The above embodiments do not limit the scope of the present application. It will be apparent to those skilled in the art that various modifications, combinations, sub-combinations and alternatives are possible, depending on design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present application should be included in the scope of the present application.

Claims (12)

1. A method of code testing, the method comprising:
acquiring coverage rate test data of the previous test of the tested code in the current test of the tested code;
According to the coverage test data of the previous test, analyzing a code and flow relation file of the previous test; the code and flow relation file is a file obtained by analyzing coverage test data; the coverage test data comprises one or more of source file level screening information, function level screening information and code line level screening information; the source file level filtering information comprises overlay source file information; the function level filtering information comprises overlay source file function information; the code line level screening information comprises information of the number of lines of covering codes and/or information of branching conditions of the lines of covering codes;
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;
When the tested code is not changed, determining the target flow of the current test according to the dynamic flow of the previous test and a pre-stored minimum flow set, and testing the tested code by using the target flow of the current test;
When the tested code is changed, acquiring new flow corresponding to each function changed in the tested code from the pre-stored code and flow relation file; and determining the target flow of the current test according to the newly-increased flow corresponding to each changed function, the dynamic flow of the previous test and the pre-stored minimum flow set, and testing the tested code by using the target flow of the current test.
2. The method of claim 1, prior to the acquiring coverage test data for a previous test of a code under test in a current test of the code under test, the method further comprising:
screening out a second number of flows from a first number of flows in an original flow vocabulary according to each flow table item in the original flow vocabulary and an original module log of the tested code in each functional module; wherein each flow meter 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 test environments; collecting code coverage Cov files corresponding to each flow through collecting tasks in each test environment; combining Cov files corresponding to each flow into a full-flow Cov file; wherein N is a natural number greater than 1;
Calculating the pre-stored minimum flow set and the pre-stored code and flow relation file according to the full flow Cov file;
The calculating the pre-stored flow minimum set according to the full-flow Cov file comprises the following steps:
according to the SID of each flow in the full-flow Cov file, analyzing the coverage characteristic of each flow in the full-flow Cov file;
Writing each flow into a corresponding first type flow file according to the coverage characteristic of each flow;
And carrying out de-duplication on the flow in each first type flow file through the thread corresponding to each first type flow file, and merging de-duplication results of each thread to obtain the pre-stored flow minimum set.
3. The method of claim 2, wherein said calculating said pre-saved code-to-flow relationship file from said full-flow Cov file comprises:
Calculating a primary key of the pre-stored code and flow relation file according to the code file name and function name of the tested code in each functional module;
According to the pre-stored codes and the main keys of the flow relation file, calculating the coverage characteristics of each flow under each main key based on the full-flow Cov file;
mapping each flow to a corresponding second class flow file according to each primary key;
and merging the flows corresponding to the same primary key in each second type flow file, and merging the flows in each second type flow file to obtain the pre-stored code and flow relation file.
4. The method of claim 1, wherein testing the code under test using the target traffic for the present test comprises:
Determining the combination state of each switch 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 under each switch combination state by using the target flow of the test.
5. The method of claim 1, wherein testing the code under test using the target traffic for the present test comprises:
Constructing at least one vocabulary data according to a predetermined test flow and a pre-stored original vocabulary, and adding the at least one vocabulary data into the original vocabulary to obtain a target vocabulary; updating the initial test environment of the current test by using the target vocabulary;
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 current test by using the target database;
And testing the tested code in the updated testing environment by using the target flow of the current test.
6. A code testing apparatus, the apparatus comprising: the device comprises an acquisition module, an analysis module, a matching module and a test module; wherein,
The acquisition module is used for acquiring coverage rate test data of the previous test of the tested code in the current test of 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 code and flow relation file is a file obtained by analyzing coverage test data; the coverage test data comprises one or more of source file level screening information, function level screening information and code line level screening information; the source file level filtering information comprises overlay source file information; the function level filtering information comprises overlay source file function information; the code line level screening information comprises information of the number of lines of covering codes and/or information of branching conditions of the lines of covering codes;
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;
the test module is used for determining the target flow of the current test according to the dynamic flow of the previous test and a pre-stored minimum flow set when the tested code is not changed, and testing the tested code by using the target flow of the current test;
The test module is further used for acquiring new flow corresponding to each function changed in the tested code from the pre-stored code and flow relation file when the tested code is changed; and determining the target flow of the current test according to the newly-increased flow corresponding to each changed function, the dynamic flow of the previous test and the pre-stored minimum flow set, and testing the tested code by using the target flow of the current test.
7. The apparatus of claim 6, wherein the apparatus further comprises: a screening module and a calculating module; wherein,
The screening module is used for screening the second quantity of flow from the first quantity of flow in the original flow vocabulary according to each flow table item in the original flow vocabulary and the original module log of the tested code in each functional module; wherein each flow meter 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 test environments; collecting code coverage Cov files corresponding to each flow through collecting tasks in each test environment; combining Cov files corresponding to each flow into a full-flow Cov file; wherein N is a natural number greater than 1;
the calculation module is used for calculating the pre-stored minimum flow set and the pre-stored code and flow relation file according to the full-flow Cov file;
The computing module is specifically configured to analyze a coverage feature 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 corresponding first type flow file according to the coverage characteristic of each flow; and carrying out de-duplication on the flow in each first type flow file through the thread corresponding to each first type flow file, and merging de-duplication results of each thread to obtain the pre-stored flow minimum set.
8. The apparatus according to claim 7, wherein:
The calculation module is specifically used for calculating a primary key of the pre-stored code and flow relation file according to the code file name and the function name of the tested code in each function module; according to the pre-stored codes and the main keys of the flow relation file, calculating the coverage characteristics of each flow under each main key based on the full-flow Cov file; mapping each flow to a corresponding second class flow file according to each primary key; and merging the flows corresponding to the same primary key in each second type flow file, and merging the flows in each second type flow file to obtain the pre-stored code and flow relation file.
9. The apparatus according to claim 6, wherein:
The test module is specifically configured to determine a combination state of each switch of the current test according to a logic switch corresponding to a code which is not changed in the tested code and a logic switch corresponding to a code which is changed in the tested code; and testing the tested code under each switch combination state by using the target flow of the test.
10. The apparatus according to claim 6, wherein:
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 vocabulary; 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 current test by using the target database; and testing the tested code in the updated testing environment by using the target flow of the current test.
11. An electronic device, comprising:
at least one processor; and
A memory communicatively coupled to the at least one processor; wherein,
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-5.
12. A non-transitory computer readable storage medium storing computer instructions for causing the computer to perform the method of any one of claims 1-5.
CN202010072030.9A 2020-01-21 2020-01-21 Code testing method and device, electronic equipment and storage medium Active CN113220560B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010072030.9A CN113220560B (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 CN113220560B (en) 2020-01-21 2020-01-21 Code testing method and device, electronic equipment and storage medium

Publications (2)

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

Family

ID=77085272

Family Applications (1)

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

Country Status (1)

Country Link
CN (1) CN113220560B (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105279084A (en) * 2014-06-24 2016-01-27 Sap欧洲公司 Defect localization in software integration tests
CN109240911A (en) * 2018-08-13 2019-01-18 腾讯科技(北京)有限公司 Accurate test method, device and computer equipment

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9946634B2 (en) * 2013-12-09 2018-04-17 International Business Machines Corporation System and method for determining test coverage
US10114737B2 (en) * 2015-09-14 2018-10-30 Salesforce.Com, Inc. Methods and systems for computing code coverage using grouped/filtered source classes during testing of an application
CN106557413A (en) * 2015-09-25 2017-04-05 伊姆西公司 Based on the method and apparatus that code coverage obtains test case
US10324066B1 (en) * 2015-12-31 2019-06-18 VeriPhase, Inc. System and method for the improved analysis of ultrasonic weld data
CN109542789B (en) * 2018-11-26 2022-03-25 泰康保险集团股份有限公司 Code coverage rate statistical method and device
CN109614341A (en) * 2018-12-29 2019-04-12 微梦创科网络科技(中国)有限公司 A method and system for testing code coverage

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105279084A (en) * 2014-06-24 2016-01-27 Sap欧洲公司 Defect localization in software integration tests
CN109240911A (en) * 2018-08-13 2019-01-18 腾讯科技(北京)有限公司 Accurate test method, device and computer equipment

Also Published As

Publication number Publication date
CN113220560A (en) 2021-08-06

Similar Documents

Publication Publication Date Title
CN111666206A (en) Method, device, equipment and storage medium for acquiring influence range of change code
CN111831512B (en) Method and device for detecting operation and maintenance abnormality, electronic equipment and storage medium
CN111639027B (en) Test method and device and electronic equipment
CN110532159B (en) Data monitoring method, device, equipment and computer readable storage medium
CN111666217A (en) Method and apparatus for testing code
CN111913998A (en) Data processing method, device, equipment and storage medium
JP2018005392A (en) Formulation support system and formulation support method for operation maintenance knowledge information
CN111061743A (en) Data processing method and device and electronic equipment
CN111241396B (en) Information pushing method and device, electronic equipment and storage medium
CN110880128A (en) Abnormal information mining method, device and system and terminal equipment
CN111654495A (en) Method, apparatus, device and storage medium for determining traffic generation source
CN109800124B (en) CPU utilization monitoring method and device, electronic equipment and storage medium
US11379091B2 (en) Operation support device and operation support method
CN113220560B (en) Code testing method and device, electronic equipment and storage medium
CN111538656B (en) Monitoring method, device and equipment for gradient inspection and storage medium
CN112307372A (en) Data processing method and device
CN112084000A (en) Container cluster testing method and device
CN110677643A (en) Touch screen television, touch screen television testing method, device and medium
CN113377638B (en) Method and device for generating performance test tool
CN115576831A (en) Test case recommendation method, device, equipment and storage medium
US20120016890A1 (en) Assigning visual characteristics to records
CN113778973A (en) Data storage method and device
CN109840179B (en) RocktMQ thread number monitoring method and device, electronic equipment and storage medium
CN111782542A (en) Test method, device, equipment, system and computer storage medium
CN113467941A (en) Method and device for sharing information

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