WO2022134581A1 - Test case sorting method and related device - Google Patents

Test case sorting method and related device Download PDF

Info

Publication number
WO2022134581A1
WO2022134581A1 PCT/CN2021/109431 CN2021109431W WO2022134581A1 WO 2022134581 A1 WO2022134581 A1 WO 2022134581A1 CN 2021109431 W CN2021109431 W CN 2021109431W WO 2022134581 A1 WO2022134581 A1 WO 2022134581A1
Authority
WO
WIPO (PCT)
Prior art keywords
test case
population
case sequence
generation
sequence
Prior art date
Application number
PCT/CN2021/109431
Other languages
French (fr)
Chinese (zh)
Inventor
崔冬
Original Assignee
深圳壹账通智能科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳壹账通智能科技有限公司 filed Critical 深圳壹账通智能科技有限公司
Publication of WO2022134581A1 publication Critical patent/WO2022134581A1/en

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
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/12Computing arrangements based on biological models using genetic models
    • G06N3/126Evolutionary algorithms, e.g. genetic algorithms or genetic programming

Definitions

  • the present application relates to the field of software testing, in particular to a test case sorting method and related equipment.
  • test case prioritization is to set the limited level of test cases according to the established test objectives without reducing the number of test cases, so that the test cases with higher priority are limitedly executed, and the purpose is to detect failures as early as possible to speed up failures positioning, thereby reducing the cost of regression testing.
  • the inventor realizes that most of the existing test case sorting is based on single-objective optimization, and the current software program is increasingly complex, and the single-objective test case prioritization technology cannot meet the needs of regression testing.
  • test case sorting method and related equipment it is necessary to propose a test case sorting method and related equipment to realize quick sorting of test cases.
  • a first aspect of the present application provides a method for sorting test cases, and the method for sorting test cases includes:
  • test case set Obtaining a test case set, arranging the test cases in the test case set in random order to obtain a first-scale test case sequence, and using the first-scale test case sequence as a population of first-generation test case sequences;
  • the single-point crossover operator and/or the sequence number mutation operator calculates the test case sequence obtained by random selection without playback to obtain the first-generation progeny test case sequence population, and combines the first-generation progeny test case sequence population with the The first-generation test case sequence population obtains the second-scale first-generation test case sequence merged population;
  • a preset operation is performed on the first-generation test case sequence population until g is equal to a preset threshold, and the g-th generation test case sequence population is used as the optimal solution set, and the optimal solution set is output.
  • a second aspect of the present application provides an electronic device, the electronic device includes a processor and a memory, the processor is configured to execute computer-readable instructions stored in the memory to implement the following steps:
  • test case set Obtaining a test case set, arranging the test cases in the test case set in random order to obtain a first-scale test case sequence, and using the first-scale test case sequence as a population of first-generation test case sequences;
  • the single-point crossover operator and/or the sequence number mutation operator calculates the test case sequence obtained by random selection without playback to obtain the first-generation progeny test case sequence population, and combines the first-generation progeny test case sequence population with the The first-generation test case sequence population obtains the second-scale first-generation test case sequence merged population;
  • a preset operation is performed on the first-generation test case sequence population until g is equal to a preset threshold, and the g-th generation test case sequence population is used as the optimal solution set, and the optimal solution set is output.
  • a third aspect of the present application provides a computer-readable storage medium on which at least one computer-readable instruction is stored, and the at least one computer-readable instruction is executed by a processor to implement the following steps:
  • test case set Obtaining a test case set, arranging the test cases in the test case set in random order to obtain a first-scale test case sequence, and using the first-scale test case sequence as a population of first-generation test case sequences;
  • the single-point crossover operator and/or the sequence number mutation operator calculates the test case sequence obtained by random selection without playback to obtain the first-generation progeny test case sequence population, and combines the first-generation progeny test case sequence population with the The first-generation test case sequence population obtains the second-scale first-generation test case sequence merged population;
  • a preset operation is performed on the first-generation test case sequence population until g is equal to a preset threshold, and the g-th generation test case sequence population is used as the optimal solution set, and the optimal solution set is output.
  • a fourth aspect of the present application provides an apparatus for sorting test cases, the apparatus for sorting test cases includes:
  • a population initialization module used for acquiring a test case set, arranging the test cases in the test case set in random order to obtain a first-scale test case sequence, and using the first-scale test case sequence as the first-generation test case sequence population;
  • an encoding module configured to perform binary encoding on each test case sequence in the primary test case sequence population
  • the merging module is configured to use a selection function to evaluate the binary-coded population of the first-generation test case sequences to obtain evaluation values of the test case sequences, and perform no playback on the population of the first-generation test case sequences according to the evaluation value of each test case sequence Randomly select, and use the single-point crossover operator and/or the sequence number mutation operator to calculate the test case sequence obtained by random selection without playback to obtain the first-generation progeny test case sequence population, and combine the first-generation progeny test cases.
  • the sequence population and the first-generation test case sequence population obtain a second-scale first-generation test case sequence merged population;
  • the sorting module is configured to perform non-dominated sorting on the combined population of the first-generation test case sequences, calculate the crowding degree of the combined population of the first-generation test case sequences, and use a crowding degree comparison operator to perform a sorting of all the combined populations according to the crowding degree.
  • the output module is configured to perform a preset operation on the first-generation test case sequence population until g is equal to a preset threshold value, take the g-th generation test case sequence population as the optimal solution set, and output the optimal solution set.
  • the initial test case set is initialized to obtain the first generation test case sequence population, the first generation test case sequence population is encoded, the selection function is used to evaluate the test case sequence in the first generation test case sequence population, and the selection, Crossover and/or serial number mutation method to obtain the descendant test case sequence population, merge the descendant test case population and the original test case population to obtain the merged population, use to sort the population, and use the crowding degree comparison operator to obtain the next generation population, through the loop
  • FIG. 1 is a flowchart of a method for sorting test cases in an embodiment of the present application.
  • FIG. 2 is a structural diagram of an apparatus for sorting test cases in an embodiment of the present application.
  • FIG. 3 is a schematic diagram of an electronic device in an embodiment of the present application.
  • Fig. 4 is a step of obtaining a first-scale descendant test case sequence population from the primary test case sequence population by using a random selection operator without playback, a single-point crossover operator and/or a sequence number mutation operator according to the evaluation value in the present application Schematic.
  • FIG. 5 is a schematic diagram of steps of obtaining an initial resource pool by using a random selection operator without playback according to the evaluation value in this application.
  • the test case sorting method of the present application is applied in one or more electronic devices.
  • the electronic device is a device that can automatically perform numerical calculation and/or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (ASICs) , programmable gate array (Field-Programmable Gate Array, FPGA), digital processor (Digital Signal Processor, DSP), embedded equipment, etc.
  • ASICs application specific integrated circuits
  • FPGA Field-Programmable Gate Array
  • DSP Digital Signal Processor
  • the electronic device may be a computing device such as a desktop computer, a notebook computer, a tablet computer, and a cloud server.
  • the device can perform human-computer interaction with the user through a keyboard, a mouse, a remote control, a touch pad, or a voice-activated device.
  • FIG. 1 is a flowchart of a method for sorting test cases in an embodiment of the present application. According to different requirements, the order of the steps in the flowchart can be changed, and some steps can be omitted.
  • the test case sorting method can acquire and process related data based on artificial intelligence technology.
  • Artificial Intelligence is a theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results. .
  • the basic technologies of artificial intelligence generally include technologies such as sensors, special artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation/interaction systems, and mechatronics.
  • Artificial intelligence software technology mainly includes computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning/deep learning.
  • test case sorting method specifically includes the following steps:
  • Step S11 acquiring a test case set, arranging the test cases in the test case set in random order to obtain a first-scale test case sequence, and using the first-scale test case sequence as the first-generation test case sequence population.
  • the size of the primary test case sequence population is determined according to the number of test cases in the test case set.
  • test case set is composed of test cases
  • test case sequence is obtained by arranging the test cases in the test case set in random order
  • test case sequence population is composed of test case sequences.
  • Step S12 binary coding is performed on each test case sequence in the primary test case sequence population.
  • the binary encoding of each test case sequence in the primary test case sequence population includes:
  • test case sequence in the primary test case sequence population is encoded according to the locus of the test case sequence in a binary coding manner, and the locus of the test case sequence is the serial number of the corresponding test case.
  • the code of the test case sequence may be "00000001010110011011".
  • Step S13 using a selection function to evaluate the binary-coded first-generation test case sequence population to obtain an evaluation value of the test case sequence, and randomly select the first-generation test case sequence population without playback according to the evaluation value of each test case sequence. , and use the single-point crossover operator and/or the serial number mutation operator to calculate the test case sequence randomly selected without playback to obtain the first-generation progeny test case sequence population, and combine the first-generation progeny test case sequence population A combined population of first-generation test-case sequences of a second scale is obtained with the primary-generation test-case sequence population.
  • the evaluation value of the test case sequence obtained by evaluating the binary-coded first-generation test case sequence population by using a selection function includes:
  • the calculation method is Among them, S(x i ,x j ) represents the similarity between x i and x j , and the calculation method is:
  • the calculation method is: Among them, D(x i , x j ) represents the dissimilarity between x i and x j , and the calculation method is:
  • ⁇ and ⁇ take a value of 0.5, and in other embodiments of the present application, ⁇ and ⁇ can take other values.
  • the first-generation test case sequence population is randomly selected without playback according to the evaluation value of each test case sequence, and a single-point crossover operator and/or Or the sequence number mutation operator calculates the test case sequence obtained by random selection without playback to obtain the first-generation descendant test case sequence population including:
  • the creating step is to create the first-generation progeny test case sequence population
  • the initial resource pool is obtained by randomly selecting the population of the first-generation test case sequence without playback;
  • the crossover mutation step is to use the single-point crossover operator and/or the sequence number mutation operator to crossover and mutate the test case sequence in the initial resource pool, and add the crossover and mutated test case sequence to the test case sequence. Describe the descendant test case sequence population;
  • the random selection step and the crossover mutation step are repeated until the population size of the progeny test case sequence is the first size.
  • the initial resource pool obtained by using a random selection operator without playback includes:
  • the objective function value of , n is the size of the population of the first-generation test case sequence;
  • the test case sequence in the initial test case sequence population is randomly selected to enter the initial resource pool, if the test case sequence in the initial resource pool is selected and performed with the single-point crossover operator. operation, then the expected survival number M in the next generation of the test case sequence in the initial resource pool is minus 0.5, if the test case sequence in the initial resource pool is not selected and not related to the single point If the crossover operator is performed, the expected number of survival of the test case sequence in the initial resource pool in the next generation is subtracted by 1;
  • the random selection step is repeated until the expected survival number of the test case sequence in the initial resource pool is less than 0.
  • the test case sequence in the initial resource pool is no longer selected.
  • the objective function value is calculated by an objective function, and the objective function includes an average fault detection rate APFD (Average Percentage of Faults Detected), a statement coverage rate APSC (Average Percentage of Statement Coverage) , Effective execution time EET (Effective Execution Time).
  • APFD Average Percentage of Faults Detected
  • APSC Average Percentage of Statement Coverage
  • Effective execution time EET Effective Execution Time
  • the average failure detection rate is based on the formula Calculated, where APFD is the average failure detection rate, n is the number of test cases in the test case set T, m 1 is the total number of software defects under test, and TF i represents the first detection in the sequence of test cases T' after sorting The order in which the test cases for defect i are placed in this execution order.
  • the average failure detection rate is used to calculate the average cumulative proportion of defects detected during the execution of the test case.
  • the statement coverage is based on the formula Calculated, where APSC is the statement coverage rate, n is the number of test cases in the test case set T, m 2 is the total number of software statements under test, TS i represents the first coverage of the i-th test case sequence T' after sorting The order in which the test cases of the line of code are placed in this execution order.
  • the statement coverage rate is used to calculate the ratio of the number of executable statements to the number of all executable statements used when the test case is executed.
  • the effective execution time is based on the formula Calculated, wherein, EET is the effective execution time, and ET i represents the time consumed when executing the i-th test case.
  • the effective execution time is used to calculate the total execution time when the fault detection rate and the statement coverage rate of the test case reach the maximum.
  • using a single-point crossover operator to cross the test cases in the initial resource pool includes:
  • the single point intersection includes:
  • the No. 1 parent test case sequence is [A, B, C, D, E, F, G]
  • the No. 2 parent test case sequence is [G, D, A, C, E, B, F]
  • the coding length of the test case sequence is 7
  • the cross position 3 is randomly selected, and the first 3 genes of the No. 1 parent test case sequence are directly used as the first 3 genes of the No. 1 child test case sequence genes, namely [A, B, C], remove the same genes in the No. 2 parent test case sequence as the first three genes in the No. 1 parent test case sequence to obtain a new gene with a length of 4 Fragment [G, D, E, F], as the last 4 genes of the sub-test case sequence No. 1, the sub-test case sequence No. 1 is [A, B, C, G, D, E , F], using the same method to obtain the No. 2 sub-test case sequence [G, D, A, B, C, E, F].
  • using the sequence number mutation operator to mutate the test case sequence in the initial resource pool includes:
  • test case sequence [A, B, C, D, E, F, G] is randomly selected, and two loci C and G on the test case sequence are randomly selected. Swap the two loci to get [A, B, G, D, E, F, C].
  • Step S14 Perform non-dominant sorting on the combined population of the first-generation test case sequences, calculate the crowding degree of the combined population of the first-generation test case sequences, and use a crowding degree comparison operator to rank the first-generation test case sequence combined population according to the crowding degree.
  • the non-dominated sorting of the first-generation test case sequence merged population includes:
  • the calculation step is to calculate the fault detection rate, statement coverage rate and effective execution time of all test case sequences in the population, and use the fault detection rate, the statement coverage rate and the effective execution time as a sorting objective function, Get three arrays of objective function values;
  • a sorting step creating an external non-dominated solution set, with the goal of maximizing the fault detection rate, maximizing the statement coverage, and minimizing the effective execution time, according to the three arrays consisting of objective function values, Obtain paired non-dominated solutions, add the paired non-dominated solutions to the external non-dominated solution set, compare the test case sequences in the external non-dominated solution set pairwise, and remove the solutions that are not non-dominated solutions, so that The test case sequences in the external non-dominated solution set are mutually non-dominated solutions, wherein the non-dominated solutions are test case sequences of non-dominated relationships;
  • the solution set generation step is to perform the calculation step and the sorting step on all test case sequences in the merged population of the first-generation test case sequences except the test case sequences in the external non-dominated solution set, to obtain a non-dominated ranking
  • the subsequent external non-dominated solution set series, the failure detection rate of any test case in the external non-dominated solution set ranked first in the non-dominated sorted external non-dominated solution set series is greater than that of the external non-dominated solution set after the ranking.
  • the failure detection rate of all test cases in the set, and the statement coverage rate of any test case in the external non-dominated solution set ranked first in the external non-dominated solution set series after the non-dominated sorting is greater than that of the external non-dominated solution set ranked last.
  • R k and R r when APFD k >APFD r and APSC k >APSC r and EET k >EET r , or APFD k ⁇ APFD r and APSC k ⁇ APSC r and EET When k ⁇ EET r , or APFD k >APFD r and APSC k ⁇ APSC r and EET k ⁇ EET r , or APFD k ⁇ APFD r and APSC k >APSC r and EET k >EET r , or APFD k ⁇ When APFD r and APSC k >APSC r and EET k ⁇ EET r , or when APFD k >APFD r and APSC k ⁇ APSC r and EET k >EET r , R k and R r are mutually non-dominant solutions.
  • the calculating the crowding degree of the combined population of the first-generation test case sequences includes:
  • the first-generation test case sequence population of the first scale obtained by calculating the first-generation test case sequence merged population by using a crowding degree comparison operator according to the crowding degree includes:
  • the size of the first-generation preliminary population is equal to the first size, use the first-generation preliminary population as the first-generation test case sequence population; or
  • using the crowding degree comparison operator to sort the first-generation preliminary population includes:
  • test Case sequence i is ranked better than test case sequence j;
  • test case sequence i and test case sequence j are in the same external non-dominated solution set and the crowding degree of test case sequence i is greater than that of test case sequence j, the ordering of test case sequence i is better than that of test case sequence j.
  • Step S15 Perform a preset operation on the first-generation test case sequence population until g is equal to a preset threshold, take the g-th generation test case sequence population as the optimal solution set, and output the optimal solution set.
  • the performing a preset operation includes:
  • the crossover operator and/or the improved mutation operator calculate the test case sequence obtained by random selection without playback to obtain the g+1 generation offspring test case sequence population;
  • Using the improved mutation operator to obtain the first-scale g+1-th generation test case sequence population according to the first-scale g-th generation test case sequence population includes:
  • the data and output results in the processing process can be stored in the blockchain, such as the test case set, the The primary test case sequence population, the progeny test case sequence population, the optimal test case sequence, etc.
  • initialize the test case set to obtain the initial test case sequence population encode the initial test case sequence population, use the selection function to evaluate the test case sequence in the initial test case sequence population, use the selection, crossover and/or sequence number mutation method to obtain
  • the descendant test case sequence population merge the descendant test case population and the original test case population to obtain the combined population, sort the population, and use the crowding degree comparison operator to obtain the next generation population, through cyclic selection, crossover and/or according to the number of iterations
  • Dominance sorting improves the efficiency of software fault detection and regression testing, thereby reducing software testing costs.
  • FIG. 2 is a structural diagram of a test case sorting apparatus 30 in an embodiment of the present application.
  • test case sequencing apparatus 30 runs in an electronic device.
  • the test case sequencing apparatus 30 may include a plurality of functional modules composed of program code segments.
  • the program codes of each program segment in the test case sequencing apparatus 30 may be stored in a memory and executed by at least one processor to perform a test case sequencing function.
  • the test case sorting apparatus 30 may be divided into a plurality of functional modules according to the functions performed by the test case sorting apparatus 30 .
  • the test case sorting apparatus 30 may include a population initialization module 301 , an encoding module 302 , a merging module 303 , a sorting module 304 and an output module 305 .
  • a module referred to in this application refers to a series of computer-readable instruction segments that can be executed by at least one processor and can perform fixed functions, and are stored in a memory. The functions of each module will be described in detail in subsequent embodiments.
  • the population initialization module 301 obtains a test case set to obtain a test case set, arranges the test cases in the test case set in random order to obtain a first-scale test case sequence, and uses the first-scale test case sequence as the first-generation test case. sequence population.
  • the size of the primary test case sequence population is determined according to the number of test cases in the test case set.
  • test case set is composed of test cases
  • test case sequence is obtained by arranging the test cases in the test case set in random order
  • test case sequence population is composed of test case sequences.
  • the encoding module 302 performs binary encoding on each test case sequence in the population of primary test case sequences.
  • the binary encoding of each test case sequence in the primary test case sequence population includes:
  • test case sequence in the primary test case sequence population is encoded according to the locus of the test case sequence in a binary coding manner, and the locus of the test case sequence is the serial number of the corresponding test case.
  • the merging module 303 uses a selection function to evaluate the binary-coded first-generation test case sequence population to obtain an evaluation value of the test case sequence, and performs no playback on the first-generation test case sequence population according to the evaluation value of each test case sequence. Randomly select, and use the single-point crossover operator and/or the sequence number mutation operator to calculate the test case sequence obtained by random selection without playback to obtain the first-generation progeny test case sequence population, and combine the first-generation progeny test cases.
  • the sequence population is combined with the primary test case sequence population to obtain a second-scale merged population of primary test case sequences.
  • the merging module 303 uses a selection function to evaluate the binary-coded first-generation test case sequence population to obtain an evaluation value of the test case sequence including:
  • the calculation method is Among them, S(x i ,x j ) represents the similarity between x i and x j , and the calculation method is:
  • the calculation method is: Among them, D(x i , x j ) represents the dissimilarity between x i and x j , and the calculation method is:
  • ⁇ and ⁇ take a value of 0.5, and in other embodiments of the present application, ⁇ and ⁇ can take other values.
  • the merging module 303 randomly selects the initial test case sequence population without playback according to the evaluation value of each test case sequence, and uses a single-point crossover operator and/or The sequence number mutation operator calculates the test case sequence obtained by random selection without playback to obtain the first-generation descendant test case sequence population including:
  • the creating step is to create the first-generation progeny test case sequence population
  • the initial resource pool is obtained by randomly selecting the population of the first-generation test case sequence without playback;
  • the crossover mutation step is to use the single-point crossover operator and/or the sequence number mutation operator to crossover and mutate the test case sequence in the initial resource pool, and add the crossover and mutated test case sequence to the test case sequence. Describe the descendant test case sequence population;
  • the random selection step and the crossover mutation step are repeated until the population size of the progeny test case sequence is the first size.
  • the initial test case sequence population according to the evaluation value, using a random selection operator without playback to obtain the initial resource pool includes:
  • the test case sequence in the initial test case sequence population is randomly selected to enter the initial resource pool, if the test case sequence in the initial resource pool is selected and performed with the single-point crossover operator. operation, then the expected survival number M in the next generation of the test case sequence in the initial resource pool is minus 0.5, if the test case sequence in the initial resource pool is not selected and not related to the single point If the crossover operator is performed, the expected number of survival of the test case sequence in the initial resource pool in the next generation is subtracted by 1;
  • the random selection step is repeated until the expected survival number of the test case sequence in the initial resource pool is less than 0.
  • the test case sequence in the initial resource pool is no longer selected.
  • the objective function value is calculated by an objective function, and the objective function includes an average fault detection rate APFD (Average Percentage of Faults Detected), a statement coverage rate APSC (Average Percentage of Statement Coverage) , Effective execution time EET (Effective Execution Time).
  • APFD Average Percentage of Faults Detected
  • APSC Average Percentage of Statement Coverage
  • Effective execution time EET Effective Execution Time
  • the average failure detection rate is based on the formula Calculated, where APFD is the average failure detection rate, n is the number of test cases in the test case set T, m 1 is the total number of software defects under test, and TF i represents the first detection in the sequence of test cases T' after sorting The order in which the test cases for defect i are placed in this execution order.
  • the average failure detection rate is used to calculate the average cumulative proportion of defects detected during the execution of the test case.
  • the statement coverage is based on the formula Calculated, where APSC is the statement coverage rate, n is the number of test cases in the test case set T, m 2 is the total number of software statements under test, TS i represents the first coverage of the i-th test case sequence T' after sorting The order in which the test cases of the line of code are placed in this execution order.
  • the statement coverage rate is used to calculate the ratio of the number of executable statements to the number of all executable statements used when the test case is executed.
  • the effective execution time is based on the formula Calculated, wherein, EET is the effective execution time, and ET i represents the time consumed when executing the i-th test case.
  • the effective execution time is used to calculate the total execution time when the fault detection rate and the statement coverage rate of the test case reach the maximum.
  • using a single-point crossover operator to cross the test cases in the initial resource pool includes:
  • the single point intersection includes:
  • the No. 1 parent test case sequence and the No. 2 parent test case sequence For a pair of parent test case sequences, the No. 1 parent test case sequence and the No. 2 parent test case sequence, the cross position k, k ⁇ [0, L] is randomly selected, where L is the coding length of the population test case sequence, and the No. 1 parent test case sequence is The first k genes of the test case sequence are directly used as the first k genes of the No. 1 sub-test case sequence, and the same genes in the No. 2 parent test case sequence as the first k genes of the No. 1 parent test case sequence are removed to obtain a A new gene fragment of length L-k is used as the last L-k genes of the sub-test case sequence No. 1, and the same method is used to generate the sub-test case sequence No. 2.
  • using the sequence number mutation operator to mutate the test case sequence in the initial resource pool includes:
  • the sorting module 304 performs non-dominant sorting on the combined population of the first-generation test case sequences, calculates the crowding degree of the combined population of the first-generation test case sequences, and uses a crowding degree comparison operator to perform a non-dominant sorting on the combined population of the first-generation test case sequences according to the crowding degree.
  • the non-dominated sorting of the first-generation test case sequence merged population includes:
  • the calculation step is to calculate the fault detection rate, statement coverage rate and effective execution time of all test case sequences in the population, and use the fault detection rate, the statement coverage rate and the effective execution time as a sorting objective function, Get three arrays of objective function values;
  • a sorting step creating an external non-dominated solution set, with the goal of maximizing the fault detection rate, maximizing the statement coverage, and minimizing the effective execution time, according to the three arrays consisting of objective function values, Obtain paired non-dominated solutions, add the paired non-dominated solutions to the external non-dominated solution set, compare the test case sequences in the external non-dominated solution set pairwise, and remove the solutions that are not non-dominated solutions, so that The test case sequences in the external non-dominated solution set are mutually non-dominated solutions, wherein the non-dominated solutions are test case sequences of non-dominated relationships;
  • the solution set generation step is to perform the calculation step and the sorting step on all test case sequences in the merged population of the first-generation test case sequences except the test case sequences in the external non-dominated solution set, to obtain a non-dominated ranking
  • the subsequent external non-dominated solution set series, the failure detection rate of any test case in the external non-dominated solution set ranked first in the non-dominated sorted external non-dominated solution set series is greater than that of the external non-dominated solution set after the ranking.
  • the failure detection rate of all test cases in the set, and the statement coverage rate of any test case in the external non-dominated solution set ranked first in the external non-dominated solution set series after the non-dominated sorting is greater than that of the external non-dominated solution set ranked last.
  • the non-dominated sorting for any two test case sequences R k and R r includes:
  • the calculating the crowding degree of the combined population of the first-generation test case sequences includes:
  • the first-generation test case sequence population of the first scale obtained by calculating the first-generation test case sequence merged population by using a crowding degree comparison operator according to the crowding degree includes:
  • the size of the first-generation preliminary population is equal to the first size, use the first-generation preliminary population as the first-generation test case sequence population; or
  • using the crowding degree comparison operator to sort the first-generation preliminary population includes:
  • test Case sequence i is ranked better than test case sequence j;
  • test case sequence i and test case sequence j are located in the same external non-dominated solution set and the crowding degree of test case sequence i is greater than that of test case sequence j, the ordering of test case sequence i is better than that of test case sequence j.
  • the output module 305 performs a preset operation on the first-generation test case sequence population until g is equal to a preset threshold, takes the g-th generation test case sequence population as the optimal solution set, and outputs the optimal solution set.
  • the performing a preset operation includes:
  • the crossover operator and/or the improved mutation operator calculate the test case sequence obtained by random selection without playback to obtain the g+1 generation offspring test case sequence population;
  • Using the improved mutation operator to obtain the first-scale g+1-th generation test case sequence population according to the first-scale g-th generation test case sequence population includes:
  • initialize the test case set to obtain the initial test case sequence population encode the initial test case sequence population, use the selection function to evaluate the test case sequence in the initial test case sequence population, and use the selection, crossover and/or sequence number mutation method to obtain
  • the descendant test case sequence population merge the descendant test case population and the original test case population to obtain the combined population, sort the population, and use the crowding degree comparison operator to obtain the next generation population, through cyclic selection, crossover and/or according to the number of iterations
  • FIG. 3 is a schematic diagram of an electronic device 6 in an embodiment of the present application.
  • the electronic device 6 includes a memory 61 , a processor 62 and computer readable instructions stored in the memory 61 and executable on the processor 62 .
  • the processor 62 executes the computer-readable instructions, the steps in the above embodiment of the test case sorting method are implemented, for example, steps S11 to S15 shown in FIG. 1 .
  • the processor 62 executes the computer-readable instructions, the functions of each module/unit in the above-mentioned embodiment of the apparatus for sorting test cases, such as modules 301 to 305 in FIG. 2 , are implemented.
  • the computer-readable instructions may be divided into one or more modules/units, and the one or more modules/units are stored in the memory 61 and executed by the processor 62 to Complete this application.
  • the one or more modules/units may be a series of computer-readable instruction segments capable of accomplishing specific functions, and the instruction segments are used to describe the execution process of the computer-readable instructions in the electronic device 6 .
  • the computer-readable instructions can be divided into a population initialization module 301, an encoding module 302, a merging module 303, a sorting module 304, and an output module 305 in FIG.
  • the electronic device 6 may be a computing device such as a desktop computer, a notebook, a palmtop computer, a server, and a cloud terminal device.
  • a computing device such as a desktop computer, a notebook, a palmtop computer, a server, and a cloud terminal device.
  • the schematic diagram is only an example of the electronic device 6, and does not constitute a limitation to the electronic device 6, and may include more or less components than the one shown, or combine some components, or different Components such as the electronic device 6 may also include input and output devices, network access devices, buses, and the like.
  • the so-called processor 62 may be a central processing module (Central Processing Unit, CPU), or other general-purpose processors, digital signal processors (Digital Signal Processor, DSP), application specific integrated circuits (Application Specific Integrated Circuit, ASIC), Field-Programmable Gate Array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.
  • the general-purpose processor can be a microprocessor or the processor 62 can also be any conventional processor, etc.
  • the processor 62 is the control center of the electronic device 6, and uses various interfaces and lines to connect the entire electronic device 6. of each part.
  • the memory 61 may be used to store the computer-readable instructions and/or modules/units, and the processor 62 executes or executes the computer-readable instructions and/or modules/units stored in the memory 61, and calls The data stored in the memory 61 realizes various functions of the electronic device 6 .
  • the memory 61 may mainly include a stored program area and a stored data area, wherein the stored program area may store an operating system, an application program required for at least one function (such as a sound playback function, an image playback function, etc.); the storage data area may Data and the like created according to the use of the electronic device 6 are stored.
  • the memory 61 may include volatile memory, and may also include non-volatile memory, such as hard disk, internal memory, plug-in hard disk, Smart Media Card (SMC), Secure Digital (SD) card , a flash memory card (Flash Card), at least one disk storage device, flash memory device, or other storage device.
  • non-volatile memory such as hard disk, internal memory, plug-in hard disk, Smart Media Card (SMC), Secure Digital (SD) card , a flash memory card (Flash Card), at least one disk storage device, flash memory device, or other storage device.
  • the modules/units integrated in the electronic device 6 are implemented in the form of software functional modules and sold or used as independent products, they may be stored in a computer-readable storage medium. Based on this understanding, the present application can implement all or part of the processes in the methods of the above embodiments, and can also be completed by instructing relevant hardware through computer-readable instructions, and the computer-readable instructions can be stored in a computer-readable storage medium. , the computer-readable instructions, when executed by the processor, can implement the steps of the above-mentioned method embodiments.
  • the computer-readable storage medium may be a non-volatile storage medium or a volatile storage medium.
  • the computer-readable instructions include computer-readable instruction code, which may be in source code form, object code form, executable file, or some intermediate form, and the like.
  • the blockchain referred to in this application is a new application mode of computer technologies such as distributed data storage, point-to-point transmission, consensus mechanism, and encryption algorithm.
  • Blockchain essentially a decentralized database, is a series of data blocks associated with cryptographic methods. Each data block contains a batch of network transaction information to verify its Validity of information (anti-counterfeiting) and generation of the next block.
  • the blockchain can include the underlying platform of the blockchain, the platform product service layer, and the application service layer.
  • each functional module in each embodiment of the present application may be integrated in the same processing module, or each module may exist physically alone, or two or more modules may be integrated in the same module.
  • the above-mentioned integrated modules can be implemented in the form of hardware, or can be implemented in the form of hardware plus software function modules.

Abstract

The present application relates to the fields of artificial intelligence and software testing, and provides a test case sorting method and a related device. The method comprises: initializing a test case set to obtain a primary-generation test case sequence population; encoding the primary-generation test case sequence population; evaluating a test case sequence in the primary-generation test case sequence population by using a selection function, obtaining a child-generation test case sequence population by using a selection, crossover, and/or serial number variation method, and merging the child-generation test case sequence population and the primary-generation test case sequence population to obtain a merged population; and performing non-dominated sorting on the population, obtaining a next-generation population by using a congestion degree comparison operator, obtaining an optimal solution set by circulating the foregoing method, and outputting the optimal solution set. By performing rapid non-dominated sorting on the test cases, the present application improves the fault detection and regression testing efficiency of software, thereby reducing the test cost of the software.

Description

测试用例排序方法及相关设备Test case sequencing method and related equipment
本申请要求于2020年12月24日提交中国专利局,申请号为202011552451.8,发明名称为“测试用例排序方法及电子设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of the Chinese patent application with the application number 202011552451.8 and the invention titled "Test Case Ranking Method and Electronic Device" filed with the China Patent Office on December 24, 2020, the entire contents of which are incorporated in this application by reference .
技术领域technical field
本申请涉及软件测试领域,具体涉及一种测试用例排序方法及相关设备。The present application relates to the field of software testing, in particular to a test case sorting method and related equipment.
背景技术Background technique
随着人工智能的发展,软件需求范围不断扩大,现有技术中,由于软件需求范围不断扩大,开发人员对软件不断地迭代修改,导致测试用例集变得越来越庞大和复杂,软件测试面临的主要问题就是如何高效的利用已有的测试用例对软件进行测试,测试用例优先级排序就是解决高效率的软件测试的途径之一。测试用例优先级排序是在不减少测试用例数量的情况下,按照既定的测试目标设置测试用例的有限级别,使得具有较高优先级的测试用例有限执行,目的是尽早地检测到故障以加快故障定位,从而降低回归测试的成本。发明人意识到,现有的测试用例排序大多以单目标优化为主,而当前的软件程序日趋复杂,单目标的测试用例优先级排序技术难以满足回归测试的需求。With the development of artificial intelligence, the scope of software requirements continues to expand. In the existing technology, due to the continuous expansion of the scope of software requirements, developers continue to iteratively modify the software, resulting in a larger and more complex set of test cases. The main problem is how to efficiently use the existing test cases to test the software, and the test case prioritization is one of the ways to solve the high-efficiency software testing. Test case prioritization is to set the limited level of test cases according to the established test objectives without reducing the number of test cases, so that the test cases with higher priority are limitedly executed, and the purpose is to detect failures as early as possible to speed up failures positioning, thereby reducing the cost of regression testing. The inventor realizes that most of the existing test case sorting is based on single-objective optimization, and the current software program is increasingly complex, and the single-objective test case prioritization technology cannot meet the needs of regression testing.
发明内容SUMMARY OF THE INVENTION
鉴于以上内容,有必要提出一种测试用例排序方法及相关设备以实现对测试用例的快速排序。In view of the above content, it is necessary to propose a test case sorting method and related equipment to realize quick sorting of test cases.
本申请的第一方面提供一种测试用例排序方法,所述测试用例排序方法包括:A first aspect of the present application provides a method for sorting test cases, and the method for sorting test cases includes:
获取测试用例集,对所述测试用例集中的测试用例按随机顺序进行排列得到第一规模测试用例序列,将所述第一规模测试用例序列作为初代测试用例序列种群;Obtaining a test case set, arranging the test cases in the test case set in random order to obtain a first-scale test case sequence, and using the first-scale test case sequence as a population of first-generation test case sequences;
对所述初代测试用例序列种群中的每个测试用例序列进行二进制编码;performing binary coding on each test case sequence in the primary test case sequence population;
使用选择函数对经过二进制编码的所述初代测试用例序列种群进行评价得到测试用例序列的评价值,根据每个测试用例序列的评价值对所述初代测试用例序列种群进行无回放随机选择,并使用单点交叉算子和/或序号变异算子对无回放随机选择得到的测试用例序列进行计算得到第一代子代测试用例序列种群,合并所述第一代子代测试用例序列种群与所述初代测试用例序列种群得到第二规模的第一代测试用例序列合并种群;Use a selection function to evaluate the binary-coded primary test case sequence population to obtain the evaluation value of the test case sequence, and perform random selection without playback on the primary test case sequence population according to the evaluation value of each test case sequence, and use The single-point crossover operator and/or the sequence number mutation operator calculates the test case sequence obtained by random selection without playback to obtain the first-generation progeny test case sequence population, and combines the first-generation progeny test case sequence population with the The first-generation test case sequence population obtains the second-scale first-generation test case sequence merged population;
对所述第一代测试用例序列合并种群进行非支配排序,计算所述第一代测试用例序列合并种群的拥挤度,并根据所述拥挤度使用拥挤度比较算子对所述第一代测试用例序列合并种群进行计算得到第一规模的第一代测试用例序列种群,并令迭代次数g=1;Perform non-dominated sorting on the combined population of the first-generation test case sequences, calculate the crowding degree of the combined population of the first-generation test case sequences, and use a crowding degree comparison operator to test the first generation according to the crowding degree The use case sequence is combined with the population for calculation to obtain the first-generation test case sequence population of the first scale, and the number of iterations g=1;
对所述第一代测试用例序列种群执行预设操作直至g等于预设阈值,将第g代测试用例序列种群作为最优解集,输出所述最优解集。A preset operation is performed on the first-generation test case sequence population until g is equal to a preset threshold, and the g-th generation test case sequence population is used as the optimal solution set, and the optimal solution set is output.
本申请的第二方面提供一种电子设备,所述电子设备包括处理器和存储器,所述处理器用于执行所述存储器中存储的计算机可读指令以实现以下步骤:A second aspect of the present application provides an electronic device, the electronic device includes a processor and a memory, the processor is configured to execute computer-readable instructions stored in the memory to implement the following steps:
获取测试用例集,对所述测试用例集中的测试用例按随机顺序进行排列得到第一规模测试用例序列,将所述第一规模测试用例序列作为初代测试用例序列种群;Obtaining a test case set, arranging the test cases in the test case set in random order to obtain a first-scale test case sequence, and using the first-scale test case sequence as a population of first-generation test case sequences;
对所述初代测试用例序列种群中的每个测试用例序列进行二进制编码;performing binary coding on each test case sequence in the primary test case sequence population;
使用选择函数对经过二进制编码的所述初代测试用例序列种群进行评价得到测试用例序列的评价值,根据每个测试用例序列的评价值对所述初代测试用例序列种群进行无回放随机选择,并使用单点交叉算子和/或序号变异算子对无回放随机选择得到的测试用 例序列进行计算得到第一代子代测试用例序列种群,合并所述第一代子代测试用例序列种群与所述初代测试用例序列种群得到第二规模的第一代测试用例序列合并种群;Use a selection function to evaluate the binary-coded primary test case sequence population to obtain the evaluation value of the test case sequence, and perform random selection without playback on the primary test case sequence population according to the evaluation value of each test case sequence, and use The single-point crossover operator and/or the sequence number mutation operator calculates the test case sequence obtained by random selection without playback to obtain the first-generation progeny test case sequence population, and combines the first-generation progeny test case sequence population with the The first-generation test case sequence population obtains the second-scale first-generation test case sequence merged population;
对所述第一代测试用例序列合并种群进行非支配排序,计算所述第一代测试用例序列合并种群的拥挤度,并根据所述拥挤度使用拥挤度比较算子对所述第一代测试用例序列合并种群进行计算得到第一规模的第一代测试用例序列种群,并令迭代次数g=1;Perform non-dominated sorting on the combined population of the first-generation test case sequences, calculate the crowding degree of the combined population of the first-generation test case sequences, and use a crowding degree comparison operator to test the first generation according to the crowding degree The use case sequence is combined with the population for calculation to obtain the first-generation test case sequence population of the first scale, and the number of iterations g=1;
对所述第一代测试用例序列种群执行预设操作直至g等于预设阈值,将第g代测试用例序列种群作为最优解集,输出所述最优解集。A preset operation is performed on the first-generation test case sequence population until g is equal to a preset threshold, and the g-th generation test case sequence population is used as the optimal solution set, and the optimal solution set is output.
本申请的第三方面提供一种计算机可读存储介质,所述计算机可读存储介质上存储有至少一个计算机可读指令,所述至少一个计算机可读指令被处理器执行以实现以下步骤:A third aspect of the present application provides a computer-readable storage medium on which at least one computer-readable instruction is stored, and the at least one computer-readable instruction is executed by a processor to implement the following steps:
获取测试用例集,对所述测试用例集中的测试用例按随机顺序进行排列得到第一规模测试用例序列,将所述第一规模测试用例序列作为初代测试用例序列种群;Obtaining a test case set, arranging the test cases in the test case set in random order to obtain a first-scale test case sequence, and using the first-scale test case sequence as a population of first-generation test case sequences;
对所述初代测试用例序列种群中的每个测试用例序列进行二进制编码;performing binary coding on each test case sequence in the primary test case sequence population;
使用选择函数对经过二进制编码的所述初代测试用例序列种群进行评价得到测试用例序列的评价值,根据每个测试用例序列的评价值对所述初代测试用例序列种群进行无回放随机选择,并使用单点交叉算子和/或序号变异算子对无回放随机选择得到的测试用例序列进行计算得到第一代子代测试用例序列种群,合并所述第一代子代测试用例序列种群与所述初代测试用例序列种群得到第二规模的第一代测试用例序列合并种群;Use a selection function to evaluate the binary-coded primary test case sequence population to obtain the evaluation value of the test case sequence, and perform random selection without playback on the primary test case sequence population according to the evaluation value of each test case sequence, and use The single-point crossover operator and/or the sequence number mutation operator calculates the test case sequence obtained by random selection without playback to obtain the first-generation progeny test case sequence population, and combines the first-generation progeny test case sequence population with the The first-generation test case sequence population obtains the second-scale first-generation test case sequence merged population;
对所述第一代测试用例序列合并种群进行非支配排序,计算所述第一代测试用例序列合并种群的拥挤度,并根据所述拥挤度使用拥挤度比较算子对所述第一代测试用例序列合并种群进行计算得到第一规模的第一代测试用例序列种群,并令迭代次数g=1;Perform non-dominated sorting on the combined population of the first-generation test case sequences, calculate the crowding degree of the combined population of the first-generation test case sequences, and use a crowding degree comparison operator to test the first generation according to the crowding degree The use case sequence is combined with the population for calculation to obtain the first-generation test case sequence population of the first scale, and the number of iterations g=1;
对所述第一代测试用例序列种群执行预设操作直至g等于预设阈值,将第g代测试用例序列种群作为最优解集,输出所述最优解集。A preset operation is performed on the first-generation test case sequence population until g is equal to a preset threshold, and the g-th generation test case sequence population is used as the optimal solution set, and the optimal solution set is output.
本申请的第四方面提供一种测试用例排序装置,所述测试用例排序装置包括:A fourth aspect of the present application provides an apparatus for sorting test cases, the apparatus for sorting test cases includes:
种群初始化模块,用于获取测试用例集,对所述测试用例集中的测试用例按随机顺序进行排列得到第一规模测试用例序列,将所述第一规模测试用例序列作为初代测试用例序列种群;a population initialization module, used for acquiring a test case set, arranging the test cases in the test case set in random order to obtain a first-scale test case sequence, and using the first-scale test case sequence as the first-generation test case sequence population;
编码模块,用于对所述初代测试用例序列种群中的每个测试用例序列进行二进制编码;an encoding module, configured to perform binary encoding on each test case sequence in the primary test case sequence population;
合并模块,用于使用选择函数对经过二进制编码的所述初代测试用例序列种群进行评价得到测试用例序列的评价值,根据每个测试用例序列的评价值对所述初代测试用例序列种群进行无回放随机选择,并使用单点交叉算子和/或序号变异算子对无回放随机选择得到的测试用例序列进行计算得到第一代子代测试用例序列种群,合并所述第一代子代测试用例序列种群与所述初代测试用例序列种群得到第二规模的第一代测试用例序列合并种群;The merging module is configured to use a selection function to evaluate the binary-coded population of the first-generation test case sequences to obtain evaluation values of the test case sequences, and perform no playback on the population of the first-generation test case sequences according to the evaluation value of each test case sequence Randomly select, and use the single-point crossover operator and/or the sequence number mutation operator to calculate the test case sequence obtained by random selection without playback to obtain the first-generation progeny test case sequence population, and combine the first-generation progeny test cases. The sequence population and the first-generation test case sequence population obtain a second-scale first-generation test case sequence merged population;
排序模块,用于对所述第一代测试用例序列合并种群进行非支配排序,计算所述第一代测试用例序列合并种群的拥挤度,并根据所述拥挤度使用拥挤度比较算子对所述第一代测试用例序列合并种群进行计算得到第一规模的第一代测试用例序列种群,并令迭代次数g=1;The sorting module is configured to perform non-dominated sorting on the combined population of the first-generation test case sequences, calculate the crowding degree of the combined population of the first-generation test case sequences, and use a crowding degree comparison operator to perform a sorting of all the combined populations according to the crowding degree. The first-generation test case sequence is combined with the population for calculation to obtain the first-scale first-generation test case sequence population, and the number of iterations g=1;
输出模块,用于对所述第一代测试用例序列种群执行预设操作直至g等于预设阈值,将第g代测试用例序列种群作为最优解集,输出所述最优解集。The output module is configured to perform a preset operation on the first-generation test case sequence population until g is equal to a preset threshold value, take the g-th generation test case sequence population as the optimal solution set, and output the optimal solution set.
由以上技术方案可以看出,本申请中,初始化测试用例集得到初代测试用例序列种群,对初代测试用例序列种群进行编码,使用选择函数评价初代测试用例序列种群中的测试用例序列,使用选择、交叉和/或序号变异方法得到子代测试用例序列种群,合并子代测试用例种群与初代测试用例种群得到合并种群,使用对种群进行排序,并使用拥挤度比较算子得到下一代种群,通过循环选择、交叉和/或根据迭代次数对测试用例序列进 行变异的方法及使用基于帕累托最优的非支配排序遗传算法、拥挤度比较算子,得到最优解集,并输出最优测试用例序列,通过对测试用例的快速非支配排序,提高了软件的故障检测和回归测试的效率,进而降低软件的测试成本。It can be seen from the above technical solutions that in this application, the initial test case set is initialized to obtain the first generation test case sequence population, the first generation test case sequence population is encoded, the selection function is used to evaluate the test case sequence in the first generation test case sequence population, and the selection, Crossover and/or serial number mutation method to obtain the descendant test case sequence population, merge the descendant test case population and the original test case population to obtain the merged population, use to sort the population, and use the crowding degree comparison operator to obtain the next generation population, through the loop The method of selecting, crossing and/or mutating the test case sequence according to the number of iterations and using the non-dominated sorting genetic algorithm based on Pareto optimality and the crowding degree comparison operator to obtain the optimal solution set and output the optimal test case Sequence, through the rapid non-dominant sorting of test cases, improves the efficiency of software fault detection and regression testing, thereby reducing software testing costs.
附图说明Description of drawings
图1为本申请一实施方式中测试用例排序方法的流程图。FIG. 1 is a flowchart of a method for sorting test cases in an embodiment of the present application.
图2为本申请一实施方式中测试用例排序装置的结构图。FIG. 2 is a structural diagram of an apparatus for sorting test cases in an embodiment of the present application.
图3为本申请一实施方式中电子设备的示意图。FIG. 3 is a schematic diagram of an electronic device in an embodiment of the present application.
图4为本申请中根据评价值使用无回放随机选择算子、单点交叉算子和/或序号变异算子由所述初代测试用例序列种群得到第一规模的子代测试用例序列种群的步骤示意图。Fig. 4 is a step of obtaining a first-scale descendant test case sequence population from the primary test case sequence population by using a random selection operator without playback, a single-point crossover operator and/or a sequence number mutation operator according to the evaluation value in the present application Schematic.
图5为本申请中根据所述评价值使用无回放随机选择算子得到初始资源池的步骤示意图。FIG. 5 is a schematic diagram of steps of obtaining an initial resource pool by using a random selection operator without playback according to the evaluation value in this application.
具体实施方式Detailed ways
为了能够更清楚地理解本申请的上述目的、特征和优点,下面结合附图和具体实施例对本申请进行详细描述。需要说明的是,在不冲突的情况下,本申请的实施例及实施例中的特征可以相互组合。In order to more clearly understand the above objects, features and advantages of the present application, the present application will be described in detail below with reference to the accompanying drawings and specific embodiments. It should be noted that the embodiments of the present application and the features in the embodiments may be combined with each other in the case of no conflict.
在下面的描述中阐述了很多具体细节以便于充分理解本申请,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获取的所有其他实施例,都属于本申请保护的范围。In the following description, many specific details are set forth to facilitate a full understanding of the present application, and the described embodiments are only a part of the embodiments of the present application, but not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the protection scope of the present application.
除非另有定义,本文所使用的所有的技术和科学术语与属于本申请的技术领域的技术人员通常理解的含义相同。本文中在本申请的说明书中所使用的术语只是为了描述具体的实施例的目的,不是旨在于限制本申请。Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the technical field to which this application belongs. The terms used herein in the specification of the application are for the purpose of describing specific embodiments only, and are not intended to limit the application.
优选地,本申请测试用例排序方法应用在一个或者多个电子设备中。所述电子设备是一种能够按照事先设定或存储的指令,自动进行数值计算和/或信息处理的设备,其硬件包括但不限于微处理器、专用集成电路(Application Specific Integrated Circuit,ASIC)、可编程门阵列(Field-Programmable Gate Array,FPGA)、数字处理器(Digital Signal Processor,DSP)、嵌入式设备等。Preferably, the test case sorting method of the present application is applied in one or more electronic devices. The electronic device is a device that can automatically perform numerical calculation and/or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (ASICs) , programmable gate array (Field-Programmable Gate Array, FPGA), digital processor (Digital Signal Processor, DSP), embedded equipment, etc.
所述电子设备可以是桌上型计算机、笔记本电脑、平板电脑及云端服务器等计算设备。所述设备可以与用户通过键盘、鼠标、遥控器、触摸板或声控设备等方式进行人机交互。The electronic device may be a computing device such as a desktop computer, a notebook computer, a tablet computer, and a cloud server. The device can perform human-computer interaction with the user through a keyboard, a mouse, a remote control, a touch pad, or a voice-activated device.
实施例1Example 1
图1是本申请一实施方式中测试用例排序方法的流程图。根据不同的需求,所述流程图中步骤的顺序可以改变,某些步骤可以省略。FIG. 1 is a flowchart of a method for sorting test cases in an embodiment of the present application. According to different requirements, the order of the steps in the flowchart can be changed, and some steps can be omitted.
所述测试用例排序方法可以基于人工智能技术对相关的数据进行获取和处理。其中,人工智能(Artificial Intelligence,AI)是利用数字计算机或者数字计算机控制的机器模拟、延伸和扩展人的智能,感知环境、获取知识并使用知识获得最佳结果的理论、方法、技术及应用系统。The test case sorting method can acquire and process related data based on artificial intelligence technology. Among them, Artificial Intelligence (AI) is a theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results. .
人工智能基础技术一般包括如传感器、专用人工智能芯片、云计算、分布式存储、大数据处理技术、操作/交互系统、机电一体化等技术。人工智能软件技术主要包括计算机视觉技术、机器人技术、生物识别技术、语音处理技术、自然语言处理技术以及机器学习/深度学习等几大方向。The basic technologies of artificial intelligence generally include technologies such as sensors, special artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation/interaction systems, and mechatronics. Artificial intelligence software technology mainly includes computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning/deep learning.
参阅图1所示,所述测试用例排序方法具体包括以下步骤:Referring to Figure 1, the test case sorting method specifically includes the following steps:
步骤S11,获取测试用例集,对所述测试用例集中的测试用例按随机顺序进行排列得到第一规模测试用例序列,将所述第一规模测试用例序列作为初代测试用例序列种群。Step S11 , acquiring a test case set, arranging the test cases in the test case set in random order to obtain a first-scale test case sequence, and using the first-scale test case sequence as the first-generation test case sequence population.
在本申请的至少一个实施方式中,所述初代测试用例序列种群的规模根据所述测试用例集中测试用例的数量确定。In at least one embodiment of the present application, the size of the primary test case sequence population is determined according to the number of test cases in the test case set.
具体地,所述测试用例集由测试用例组成,测试用例序列由所述测试用例集中的测试用例按随机顺序进行排列得到,测试用例序列种群由测试用例序列组成。Specifically, the test case set is composed of test cases, the test case sequence is obtained by arranging the test cases in the test case set in random order, and the test case sequence population is composed of test case sequences.
步骤S12,对所述初代测试用例序列种群中的每个测试用例序列进行二进制编码。Step S12, binary coding is performed on each test case sequence in the primary test case sequence population.
在本申请的至少一个实施方式中,所述对所述初代测试用例序列种群中的每个测试用例序列进行二进制编码包括:In at least one embodiment of the present application, the binary encoding of each test case sequence in the primary test case sequence population includes:
采用二进制编码方式按照所述测试用例序列的基因位对所述初代测试用例序列种群中的测试用例序列进行编码,所述测试用例序列的基因位为相应的测试用例的序列号。The test case sequence in the primary test case sequence population is encoded according to the locus of the test case sequence in a binary coding manner, and the locus of the test case sequence is the serial number of the corresponding test case.
例如,当一个测试用例序列中测试用例的序列号为[0000,0001,0101,1001,1011]时,所述测试用例序列的编码可以是“00000001010110011011”。For example, when the serial number of the test case in a test case sequence is [0000, 0001, 0101, 1001, 1011], the code of the test case sequence may be "00000001010110011011".
步骤S13,使用选择函数对经过二进制编码的所述初代测试用例序列种群进行评价得到测试用例序列的评价值,根据每个测试用例序列的评价值对所述初代测试用例序列种群进行无回放随机选择,并使用单点交叉算子和/或序号变异算子对无回放随机选择得到的测试用例序列进行计算得到第一代子代测试用例序列种群,合并所述第一代子代测试用例序列种群与所述初代测试用例序列种群得到第二规模的第一代测试用例序列合并种群。Step S13, using a selection function to evaluate the binary-coded first-generation test case sequence population to obtain an evaluation value of the test case sequence, and randomly select the first-generation test case sequence population without playback according to the evaluation value of each test case sequence. , and use the single-point crossover operator and/or the serial number mutation operator to calculate the test case sequence randomly selected without playback to obtain the first-generation progeny test case sequence population, and combine the first-generation progeny test case sequence population A combined population of first-generation test-case sequences of a second scale is obtained with the primary-generation test-case sequence population.
在本申请的至少一个实施方式中,所述使用选择函数对经过二进制编码的所述初代测试用例序列种群进行评价得到测试用例序列的评价值包括:In at least one embodiment of the present application, the evaluation value of the test case sequence obtained by evaluating the binary-coded first-generation test case sequence population by using a selection function includes:
根据公式
Figure PCTCN2021109431-appb-000001
对所述第一规模的初代测试用例序列种群进行评价得到测试用例序列的评价值
Figure PCTCN2021109431-appb-000002
其中,
Figure PCTCN2021109431-appb-000003
代表测试用例序列的相似度,
Figure PCTCN2021109431-appb-000004
代表测试用例序列的相异度;
According to the formula
Figure PCTCN2021109431-appb-000001
Evaluate the population of the first-generation test case sequence of the first scale to obtain the evaluation value of the test case sequence
Figure PCTCN2021109431-appb-000002
in,
Figure PCTCN2021109431-appb-000003
represents the similarity of the test case sequence,
Figure PCTCN2021109431-appb-000004
Represents the dissimilarity of the test case sequence;
Figure PCTCN2021109431-appb-000005
的计算方法为
Figure PCTCN2021109431-appb-000006
其中,S(x i,x j)表示x i和x j的相似度,计算方法为:
Figure PCTCN2021109431-appb-000005
The calculation method is
Figure PCTCN2021109431-appb-000006
Among them, S(x i ,x j ) represents the similarity between x i and x j , and the calculation method is:
Figure PCTCN2021109431-appb-000007
Figure PCTCN2021109431-appb-000007
Figure PCTCN2021109431-appb-000008
Figure PCTCN2021109431-appb-000008
Figure PCTCN2021109431-appb-000009
的计算方法为:
Figure PCTCN2021109431-appb-000010
其中,D(x i,x j)表示x i和x j的相异度,计算方法为:
Figure PCTCN2021109431-appb-000009
The calculation method is:
Figure PCTCN2021109431-appb-000010
Among them, D(x i , x j ) represents the dissimilarity between x i and x j , and the calculation method is:
Figure PCTCN2021109431-appb-000011
Figure PCTCN2021109431-appb-000011
Figure PCTCN2021109431-appb-000012
Figure PCTCN2021109431-appb-000012
在本申请的至少一个实施方式中,α和β取值为0.5,在本申请的其他实施方式中,α和β可以取其他数值。In at least one embodiment of the present application, α and β take a value of 0.5, and in other embodiments of the present application, α and β can take other values.
在本申请的至少一个实施方式中,如图4所示,所述根据每个测试用例序列的评价值对所述初代测试用例序列种群进行无回放随机选择,并使用单点交叉算子和/或序号变异算子对无回放随机选择得到的测试用例序列进行计算得到第一代子代测试用例序列种群包括:In at least one embodiment of the present application, as shown in FIG. 4 , the first-generation test case sequence population is randomly selected without playback according to the evaluation value of each test case sequence, and a single-point crossover operator and/or Or the sequence number mutation operator calculates the test case sequence obtained by random selection without playback to obtain the first-generation descendant test case sequence population including:
创建步骤,创建所述第一代子代测试用例序列种群;The creating step is to create the first-generation progeny test case sequence population;
随机选择步骤,根据每个测试用例序列的评价值对所述初代测试用例序列种群进行无回放随机选择得到初始资源池;In the random selection step, according to the evaluation value of each test case sequence, the initial resource pool is obtained by randomly selecting the population of the first-generation test case sequence without playback;
交叉变异步骤,使用所述单点交叉算子和/或所述序号变异算子对所述初始资源池中的测试用例序列进行交叉和变异,将经过交叉和变异的所述测试用例序列加入所述子代测试用例序列种群;The crossover mutation step is to use the single-point crossover operator and/or the sequence number mutation operator to crossover and mutate the test case sequence in the initial resource pool, and add the crossover and mutated test case sequence to the test case sequence. Describe the descendant test case sequence population;
种群生成步骤,重复所述随机选择步骤与所述交叉变异步骤,直至所述子代测试用例序列种群规模为所述第一规模。In the population generation step, the random selection step and the crossover mutation step are repeated until the population size of the progeny test case sequence is the first size.
在本申请的至少一个实施方式中,如图5所示,根据所述初代测试用例序列种群,根据所述评价值使用无回放随机选择算子得到初始资源池包括:In at least one embodiment of the present application, as shown in FIG. 5 , according to the initial test case sequence population, according to the evaluation value, the initial resource pool obtained by using a random selection operator without playback includes:
生存期望数目计算步骤,根据公式M=f i/∑f i/n计算所述初代测试用例序列种群中每个测试用例序列在下一代的生存期望数目M,其中,f i为测试用例序列i的目标函数值,n为所述初代测试用例序列种群的规模; In the calculation step of the expected number of survival, the expected number of survival M of each test case sequence in the first generation test case sequence population in the next generation is calculated according to the formula M=f i /∑f i /n, where f i is the test case sequence i The objective function value of , n is the size of the population of the first-generation test case sequence;
随机选择步骤,根据所述评价值随机选择所述初代测试用例序列种群中的测试用例序列进入初始资源池,若所述初始资源池中的测试用例序列被选中并与所述单点交叉算子进行运算,则所述初始资源池中的所述测试用例序列在下一代的生存期望数目M减去0.5,若所述初始资源池中的所述测试用例序列不被选中且不与所述单点交叉算子进行运算,则所述初始资源池中的所述测试用例序列在下一代的生存期望数目减去1;In the random selection step, according to the evaluation value, the test case sequence in the initial test case sequence population is randomly selected to enter the initial resource pool, if the test case sequence in the initial resource pool is selected and performed with the single-point crossover operator. operation, then the expected survival number M in the next generation of the test case sequence in the initial resource pool is minus 0.5, if the test case sequence in the initial resource pool is not selected and not related to the single point If the crossover operator is performed, the expected number of survival of the test case sequence in the initial resource pool in the next generation is subtracted by 1;
重复进行所述随机选择步骤,直到所述初始资源池中的所述测试用例序列的生存期望数目小于0。The random selection step is repeated until the expected survival number of the test case sequence in the initial resource pool is less than 0.
在本申请的至少一个实施方式中,当所述初始资源池中的所述测试用例序列的生存期望小于0时,所述初始资源池中的所述测试用例序列不再被选中。In at least one embodiment of the present application, when the survival expectation of the test case sequence in the initial resource pool is less than 0, the test case sequence in the initial resource pool is no longer selected.
在本申请的至少一个实施方式中,所述目标函数值由目标函数计算得到,所述目标函数包括平均故障检测率APFD(Average Percentage of Faults Detected)、语句覆盖率APSC(Average Percentage of Statement Coverage)、有效执行时间EET(Effective Execution Time)。In at least one embodiment of the present application, the objective function value is calculated by an objective function, and the objective function includes an average fault detection rate APFD (Average Percentage of Faults Detected), a statement coverage rate APSC (Average Percentage of Statement Coverage) , Effective execution time EET (Effective Execution Time).
在本申请的至少一个实施方式中,所述平均故障检测率根据公式
Figure PCTCN2021109431-appb-000013
Figure PCTCN2021109431-appb-000014
计算得到,其中,APFD为所述平均故障检测率,n为测试用例集T中的测试用例数量,m 1为被测软件缺陷总数量,TF i表示排序后测试用例序列T′中首次检测到缺陷i的测试用例在该执行次序中所处的次序。
In at least one embodiment of the present application, the average failure detection rate is based on the formula
Figure PCTCN2021109431-appb-000013
Figure PCTCN2021109431-appb-000014
Calculated, where APFD is the average failure detection rate, n is the number of test cases in the test case set T, m 1 is the total number of software defects under test, and TF i represents the first detection in the sequence of test cases T' after sorting The order in which the test cases for defect i are placed in this execution order.
本实施例中,所述平均故障检测率用于计算测试用例执行过程中检测到缺陷的平均累计比例。In this embodiment, the average failure detection rate is used to calculate the average cumulative proportion of defects detected during the execution of the test case.
在本申请的至少一个实施方式中,所述语句覆盖率根据公式
Figure PCTCN2021109431-appb-000015
Figure PCTCN2021109431-appb-000016
计算得到,其中,APSC为所述语句覆盖率,n为测试用例集T中测试用例的数量,m 2为被测软件语句总数量,TS i表示排序后测试用例序列T′中首次覆盖第i行代码的测试用例在该执行次序中所处的次序。
In at least one embodiment of the present application, the statement coverage is based on the formula
Figure PCTCN2021109431-appb-000015
Figure PCTCN2021109431-appb-000016
Calculated, where APSC is the statement coverage rate, n is the number of test cases in the test case set T, m 2 is the total number of software statements under test, TS i represents the first coverage of the i-th test case sequence T' after sorting The order in which the test cases of the line of code are placed in this execution order.
本实施例中,所述语句覆盖率用于计算在测试用例执行时,所用到的可执行语句数与全部可执行语句数的比例。In this embodiment, the statement coverage rate is used to calculate the ratio of the number of executable statements to the number of all executable statements used when the test case is executed.
在本申请的至少一个实施方式中,所述有效执行时间根据公式
Figure PCTCN2021109431-appb-000017
计算得到,其中,EET为所述有效执行时间,ET i表示执行第i个测试用例时所消耗的时间。
In at least one embodiment of the present application, the effective execution time is based on the formula
Figure PCTCN2021109431-appb-000017
Calculated, wherein, EET is the effective execution time, and ET i represents the time consumed when executing the i-th test case.
本实施例中,所述有效执行时间用于计算测试用例的故障检测率和语句覆盖率达到最大时的执行总时间。In this embodiment, the effective execution time is used to calculate the total execution time when the fault detection rate and the statement coverage rate of the test case reach the maximum.
本申请的至少一个实施方式中,使用单点交叉算子对所述初始资源池中的测试用例进行交叉包括:In at least one embodiment of the present application, using a single-point crossover operator to cross the test cases in the initial resource pool includes:
在所述初始资源池中随机选择至少一对父测试用例序列;randomly select at least one pair of parent test case sequences in the initial resource pool;
对于所述至少一对父测试用例序列的每对父测试用例序列,进行单点交叉;for each pair of parent test case sequences of the at least one pair of parent test case sequences, perform single-point crossover;
所述单点交叉包括:The single point intersection includes:
对于一对父测试用例序列,1号父测试用例序列和2号父测试用例序列,随机选取交叉位置k,k∈[0,L],L为测试用例序列的编码长度,将1号父测试用例序列的前k个基因直接作为1号子测试用例序列的前k个基因,将2号父测试用例序列中与1号父测试用例序列的前k个基因中相同的基因去掉,得到一个长度为L-k的新基因片段,并将 其作为1号子测试用例序列的后L-k个基因,采用相同的方法产生2号子测试用例序列。For a pair of parent test case sequences, No. 1 parent test case sequence and No. 2 parent test case sequence, randomly select the intersection position k, k∈[0, L], L is the coding length of the test case sequence, and the No. 1 parent test case The first k genes of the test case sequence are directly used as the first k genes of the sub-test case sequence No. 1, and the genes in the parent test case sequence No. 2 that are the same as the first k genes of the parent test case sequence No. 1 are removed to obtain a length of is the new gene fragment of L-k, and takes it as the last L-k genes of the sub-test case sequence No. 1, and uses the same method to generate the sub-test case sequence No. 2.
例如,当所述1号父测试用例序列为[A,B,C,D,E,F,G],所述2号父测试用例序列为[G,D,A,C,E,B,F]时,所述测试用例序列的编码长度为7,所述随机选取交叉位置3,将所述1号父测试用例序列的前3个基因直接作为所述1号子测试用例序列的前3个基因,即[A,B,C],将所述2号父测试用例序列中与所述1号父测试用例序列的前3个基因中相同的基因去掉,得到一个长度为4的新基因片段[G,D,E,F],将其作为所述1号子测试用例序列的后4个基因,则所述1号子测试用例序列为[A,B,C,G,D,E,F],采用相同方法得到所述2号子测试用例序列[G,D,A,B,C,E,F]。For example, when the No. 1 parent test case sequence is [A, B, C, D, E, F, G], the No. 2 parent test case sequence is [G, D, A, C, E, B, F], the coding length of the test case sequence is 7, the cross position 3 is randomly selected, and the first 3 genes of the No. 1 parent test case sequence are directly used as the first 3 genes of the No. 1 child test case sequence genes, namely [A, B, C], remove the same genes in the No. 2 parent test case sequence as the first three genes in the No. 1 parent test case sequence to obtain a new gene with a length of 4 Fragment [G, D, E, F], as the last 4 genes of the sub-test case sequence No. 1, the sub-test case sequence No. 1 is [A, B, C, G, D, E , F], using the same method to obtain the No. 2 sub-test case sequence [G, D, A, B, C, E, F].
在本申请的至少一个实施方式中,使用所述序号变异算子对所述初始资源池中的测试用例序列进行变异包括:In at least one embodiment of the present application, using the sequence number mutation operator to mutate the test case sequence in the initial resource pool includes:
随机选择所述初始资源池中至少一个测试用例序列,对于所述至少一个测试用例序列中的每个测试用例序列,随机选择所述测试用例序列上的两个基因位,将两个基因位的值进行交换。Randomly select at least one test case sequence in the initial resource pool, for each test case sequence in the at least one test case sequence, randomly select two loci on the test case sequence, and combine the two loci of the test case sequence. value is exchanged.
例如,随机选择一个测试用例序列[A,B,C,D,E,F,G],随机选择所述测试用例序列上的两个基因位C和G。将两个基因位交换,得到[A,B,G,D,E,F,C]。For example, a test case sequence [A, B, C, D, E, F, G] is randomly selected, and two loci C and G on the test case sequence are randomly selected. Swap the two loci to get [A, B, G, D, E, F, C].
步骤S14,对所述第一代测试用例序列合并种群进行非支配排序,计算所述第一代测试用例序列合并种群的拥挤度,并根据所述拥挤度使用拥挤度比较算子对所述第一代测试用例序列合并种群进行计算得到第一规模的第一代测试用例序列种群,并令迭代次数g=1。Step S14: Perform non-dominant sorting on the combined population of the first-generation test case sequences, calculate the crowding degree of the combined population of the first-generation test case sequences, and use a crowding degree comparison operator to rank the first-generation test case sequence combined population according to the crowding degree. The first-generation test case sequence population is calculated by merging the population of the first-generation test case sequence, and the number of iterations g=1.
在本申请的至少一个实施方式中,所述对所述第一代测试用例序列合并种群进行非支配排序包括:In at least one embodiment of the present application, the non-dominated sorting of the first-generation test case sequence merged population includes:
计算步骤,计算所述种群中的所有测试用例序列的故障检测率、语句覆盖率和有效执行时间,并将所述故障检测率、所述语句覆盖率和所述有效执行时间作为排序目标函数,得到三个由目标函数值组成的数组;The calculation step is to calculate the fault detection rate, statement coverage rate and effective execution time of all test case sequences in the population, and use the fault detection rate, the statement coverage rate and the effective execution time as a sorting objective function, Get three arrays of objective function values;
排序步骤,创建外部非支配解集,以最大化所述故障检测率、最大化所述语句覆盖率、最小化所述有效执行时间为目标,根据所述三个由目标函数值组成的数组,得到成对的非支配解,将所述成对的非支配解加入所述外部非支配解集,两两比较所述外部非支配解集中的测试用例序列,去除不是非支配解的解,使得所述外部非支配解集中的测试用例序列两两互为非支配解,其中,所述非支配解为非支配关系的测试用例序列;A sorting step, creating an external non-dominated solution set, with the goal of maximizing the fault detection rate, maximizing the statement coverage, and minimizing the effective execution time, according to the three arrays consisting of objective function values, Obtain paired non-dominated solutions, add the paired non-dominated solutions to the external non-dominated solution set, compare the test case sequences in the external non-dominated solution set pairwise, and remove the solutions that are not non-dominated solutions, so that The test case sequences in the external non-dominated solution set are mutually non-dominated solutions, wherein the non-dominated solutions are test case sequences of non-dominated relationships;
解集生成步骤,对所述第一代测试用例序列合并种群中除所述外部非支配解集中的测试用例序列外的所有测试用例序列执行所述计算步骤与所述排序步骤,得到非支配排序后的外部非支配解集系列,所述非支配排序后的外部非支配解集系列中排序在前的外部非支配解集中的任一测试用例的故障检测率大于排序在后的外部非支配解集中的所有测试用例的故障检测率,且所述非支配排序后的外部非支配解集系列中排序在前的外部非支配解集中的任一测试用例的语句覆盖率大于排序在后的外部非支配解集中的所有测试用例的语句覆盖率,且所述非支配排序后的外部非支配解集系列中排序在前的外部非支配解集中的任一测试用例的有效执行时间小于排序在后的外部非支配解集中的所有测试用例。The solution set generation step is to perform the calculation step and the sorting step on all test case sequences in the merged population of the first-generation test case sequences except the test case sequences in the external non-dominated solution set, to obtain a non-dominated ranking The subsequent external non-dominated solution set series, the failure detection rate of any test case in the external non-dominated solution set ranked first in the non-dominated sorted external non-dominated solution set series is greater than that of the external non-dominated solution set after the ranking. The failure detection rate of all test cases in the set, and the statement coverage rate of any test case in the external non-dominated solution set ranked first in the external non-dominated solution set series after the non-dominated sorting is greater than that of the external non-dominated solution set ranked last. The statement coverage of all test cases in the dominant solution set, and the effective execution time of any test case in the external non-dominated solution set ranked first in the non-dominated sorted external non-dominated solution set series is less than that of the later sorted external non-dominated solution set. All test cases in the outer non-dominated solution set.
具体地,对于任意两个测试用例序列R k和R r,当APFD k>APFD r且APSC k>APSC r且EET k>EET r时,或APFD k<APFD r且APSC k<APSC r且EET k<EET r时,或APFD k>APFD r且APSC k<APSC r且EET k<EET r时,或APFD k<APFD r且APSC k>APSC r且EET k>EET r时,或APFD k<APFD r且APSC k>APSC r且EET k<EET r时,或APFD k>APFD r且APSC k<APSC r且EET k>EET r时,R k和R r互为非支配解。 Specifically, for any two test case sequences R k and R r , when APFD k >APFD r and APSC k >APSC r and EET k >EET r , or APFD k < APFD r and APSC k < APSC r and EET When k < EET r , or APFD k >APFD r and APSC k < APSC r and EET k < EET r , or APFD k < APFD r and APSC k >APSC r and EET k >EET r , or APFD k < When APFD r and APSC k >APSC r and EET k <EET r , or when APFD k >APFD r and APSC k <APSC r and EET k >EET r , R k and R r are mutually non-dominant solutions.
在本申请的至少一个实施方式中,所述计算所述第一代测试用例序列合并种群的拥挤度包括:In at least one embodiment of the present application, the calculating the crowding degree of the combined population of the first-generation test case sequences includes:
令所述第一代测试用例序列合并种群中的测试用例序列t的拥挤度d t=0,其中,t表示测试用例序列,t=1,2,…,n; Let the crowding degree of the test case sequence t in the first-generation test case sequence merged population d t =0, where t represents the test case sequence, t=1, 2,...,n;
对于每个目标函数f(x)进行如下操作:For each objective function f(x) do the following:
基于所述目标函数f(x)对第一代测试用例序列合并种群中的测试用例序列进行单目标排序;Based on the objective function f(x), single-objective sorting is performed on the test case sequences in the merged population of the first-generation test case sequences;
令边界的两个测试用例序列d 1、d n的拥挤度为无穷,即d 1=d n=∞; Let the crowding degree of the two test case sequences d 1 and d n be infinite, that is, d 1 =d n =∞;
根据公式d t=d t+(f(t+1)-f(t-1))计算所述测试用例序列t的拥挤度,其中,t=2,3,…,n-1。 The crowding degree of the test case sequence t is calculated according to the formula d t =d t +(f(t+1)-f(t-1)), where t=2,3,...,n-1.
在本申请的一个实施方式中,所述根据所述拥挤度使用拥挤度比较算子对所述第一代测试用例序列合并种群进行计算得到第一规模的第一代测试用例序列种群包括:In an embodiment of the present application, the first-generation test case sequence population of the first scale obtained by calculating the first-generation test case sequence merged population by using a crowding degree comparison operator according to the crowding degree includes:
创建第一代预备种群;Create a first-generation reserve population;
将所述非支配排序后的外部非支配解集系列中的外部非支配解集按次序加入所述第一代预备种群,直至所述第一代预备种群规模大于或等于第一规模;或adding the external non-dominated solution sets in the non-dominated sorted external non-dominated solution set series to the first-generation preliminary population in order, until the first-generation preliminary population size is greater than or equal to the first size; or
当所述第一代预备种群规模等于第一规模时,将所述第一代预备种群作为所述第一代测试用例序列种群;或When the size of the first-generation preliminary population is equal to the first size, use the first-generation preliminary population as the first-generation test case sequence population; or
当所述第一代预备种群规模大于第一规模时,根据所述拥挤度使用所述拥挤度比较算子对所述第一代预备种群进行排序,得到第一规模的所述第一代测试用例序列种群。When the scale of the first-generation preliminary population is larger than the first scale, use the crowding degree comparison operator to sort the first-generation preliminary population according to the crowding degree to obtain the first-generation test of the first scale Use case sequence population.
在本申请的至少一个实施方式中,使用所述拥挤度比较算子对所述第一代预备种群进行排序包括:In at least one embodiment of the present application, using the crowding degree comparison operator to sort the first-generation preliminary population includes:
对于所述第一代预备种群中的两个测试用例序列i和j,当测试用例序列i所处的外部非支配解集次序优于测试用例序列j所处的外部非支配解集时,测试用例序列i的排序优于测试用例序列j;或For the two test case sequences i and j in the first-generation preliminary population, when the outer non-dominated solution set where the test case sequence i is located is better than the outer non-dominated solution set where the test case sequence j is located, the test Case sequence i is ranked better than test case sequence j; or
当测试用例序列i和测试用例序列j所处的外部非支配解集相同且测试用例序列i的拥挤度大于测试用例序列j的拥挤度时,测试用例序列i的排序优于测试用例序列j。When test case sequence i and test case sequence j are in the same external non-dominated solution set and the crowding degree of test case sequence i is greater than that of test case sequence j, the ordering of test case sequence i is better than that of test case sequence j.
步骤S15,对所述第一代测试用例序列种群执行预设操作直至g等于预设阈值,将第g代测试用例序列种群作为最优解集,输出所述最优解集。Step S15: Perform a preset operation on the first-generation test case sequence population until g is equal to a preset threshold, take the g-th generation test case sequence population as the optimal solution set, and output the optimal solution set.
本实施例中,所述执行预设操作包括:In this embodiment, the performing a preset operation includes:
使用选择函数对第g代测试用例序列种群进行评价得到测试用例序列的评价值,根据每个测试用例序列的评价值对所述第g代测试用例序列种群进行无回放随机选择,并使用单点交叉算子和/或改进变异算子对无回放随机选择得到的测试用例序列进行计算得到第g+1代子代测试用例序列种群;Use the selection function to evaluate the g-th generation test case sequence population to obtain the evaluation value of the test case sequence, and perform random selection without playback on the g-th generation test case sequence population according to the evaluation value of each test case sequence, and use a single point The crossover operator and/or the improved mutation operator calculate the test case sequence obtained by random selection without playback to obtain the g+1 generation offspring test case sequence population;
合并所述第g代测试用例序列种群和所述第g+1代子代测试用例序列种群得到第二规模的第g+1代测试用例序列合并种群;combining the g-th generation test case sequence population and the g+1-th generation progeny test-case sequence population to obtain a second-scale combined population of the g+1-th generation test case sequence;
对所述第g+1代测试用例序列合并种群进行非支配排序;Perform non-dominated sorting on the combined population of the g+1 generation test case sequence;
计算所述第g+1代测试用例序列合并种群的拥挤度;Calculate the crowding degree of the combined population of the g+1 generation test case sequence;
根据所述第g+1代测试用例序列合并种群的拥挤度使用拥挤度比较算子得到第一规模的第g+1代测试用例序列种群,令迭代次数g=g+1。According to the crowding degree of the combined population of the g+1-th generation test case sequence, the crowding degree comparison operator is used to obtain the first-scale g+1-th generation test case sequence population, and the number of iterations g=g+1.
使用所述改进变异算子根据第一规模的第g代测试用例序列种群得到第一规模的第g+1代测试用例序列种群包括:Using the improved mutation operator to obtain the first-scale g+1-th generation test case sequence population according to the first-scale g-th generation test case sequence population includes:
设定gen1,其中,1<gen1<n/2,设定gen2,其中,gen1<gen2<n,n为所述第一规模;Set gen1, where 1<gen1<n/2, set gen2, where gen1<gen2<n, n is the first scale;
设定所述第g代测试用例序列种群中测试用例序列的高位区为[0,length/3],测试用例序列的中位区为(length/3,length*2/3],测试用例序列的低位区为(length*2/3,length],length为所述测试用例序列的长度;Set the high-order region of the test case sequence in the g-th generation test case sequence population to [0, length/3], the median region of the test case sequence to be (length/3, length*2/3], and the test case sequence The low-order area of is (length*2/3, length], and length is the length of the test case sequence;
当1≤g<gen1时,随机选择所述第g代测试用例序列种群中的至少一个测试用例序列,对所述至少一个测试用例序列中的每个测试用例序列,随机选择所述每个测试用 例序列的高位区的两个基因位,将所述两个基因位的值进行交换;When 1≤g<gen1, randomly select at least one test case sequence in the g-th generation test case sequence population, and randomly select each test case sequence in the at least one test case sequence Using the two loci in the high order region of the case sequence, the values of the two loci are exchanged;
当gen1≤g<gen2时,随机选择所述第g代测试用例序列种群中的至少一个测试用例序列,对所述至少一个测试用例序列中的每个测试用例序列,随机选择所述每个测试用例序列的中位区的两个基因位,将所述两个基因位的值进行交换;When gen1≤g<gen2, randomly select at least one test case sequence in the g-th generation test case sequence population, and randomly select each test case sequence in the at least one test case sequence Using the two loci of the median region of the sequence of the case, the values of the two loci are exchanged;
当gen2≤g<n时,随机选择所述第g代测试用例序列种群中的至少一个测试用例序列,对所述至少一个测试用例序列中的每个测试用例序列,随机选择所述每个测试用例序列的低位区的两个基因位,将所述两个基因位的值进行交换。When gen2≤g<n, randomly select at least one test case sequence in the g-th generation test case sequence population, and randomly select each test case sequence in the at least one test case sequence Using two loci in the lower region of the case sequence, the values of the two loci are swapped.
需要说明的是,为保证上述处理过程中的数据和输出结果的私密性和安全性,所述处理过程中的数据和输出结果可存储于区块链中,比如所述测试用例集、所述初代测试用例序列种群、所述子代测试用例序列种群、所述最优测试用例序列等。It should be noted that, in order to ensure the privacy and security of the data and output results in the above processing process, the data and output results in the processing process can be stored in the blockchain, such as the test case set, the The primary test case sequence population, the progeny test case sequence population, the optimal test case sequence, etc.
本申请中,初始化测试用例集得到初代测试用例序列种群,对初代测试用例序列种群进行编码,使用选择函数评价初代测试用例序列种群中的测试用例序列,使用选择、交叉和/或序号变异方法得到子代测试用例序列种群,合并子代测试用例种群与初代测试用例种群得到合并种群,对种群进行排序,并使用拥挤度比较算子得到下一代种群,通过循环选择、交叉和/或根据迭代次数对测试用例序列进行变异的方法及使用基于帕累托最优的非支配排序遗传算法、拥挤度比较算子,得到最优解集,并输出最优测试用例序列,通过对测试用例的快速非支配排序,提高了软件的故障检测和回归测试的效率,进而降低软件的测试成本。In this application, initialize the test case set to obtain the initial test case sequence population, encode the initial test case sequence population, use the selection function to evaluate the test case sequence in the initial test case sequence population, use the selection, crossover and/or sequence number mutation method to obtain The descendant test case sequence population, merge the descendant test case population and the original test case population to obtain the combined population, sort the population, and use the crowding degree comparison operator to obtain the next generation population, through cyclic selection, crossover and/or according to the number of iterations The method of mutating the test case sequence and using the non-dominated sorting genetic algorithm based on Pareto optimality and the crowding degree comparison operator to obtain the optimal solution set, and output the optimal test case sequence. Dominance sorting improves the efficiency of software fault detection and regression testing, thereby reducing software testing costs.
实施例2Example 2
图2为本申请一实施方式中测试用例排序装置30的结构图。FIG. 2 is a structural diagram of a test case sorting apparatus 30 in an embodiment of the present application.
在一些实施例中,所述测试用例排序装置30运行于电子设备中。所述测试用例排序装置30可以包括多个由程序代码段所组成的功能模块。所述测试用例排序装置30中的各个程序段的程序代码可以存储于存储器中,并由至少一个处理器所执行,以执行测试用例排序功能。In some embodiments, the test case sequencing apparatus 30 runs in an electronic device. The test case sequencing apparatus 30 may include a plurality of functional modules composed of program code segments. The program codes of each program segment in the test case sequencing apparatus 30 may be stored in a memory and executed by at least one processor to perform a test case sequencing function.
本实施例中,所述测试用例排序装置30根据其所执行的功能,可以被划分为多个功能模块。参阅图2所示,所述测试用例排序装置30可以包括种群初始化模块301、编码模块302、合并模块303、排序模块304及输出模块305。本申请所称的模块是指一种能够被至少一个处理器所执行并且能够完成固定功能的一系列计算机可读指令段,其存储在存储器中。关于各模块的功能将在后续的实施例中详述。In this embodiment, the test case sorting apparatus 30 may be divided into a plurality of functional modules according to the functions performed by the test case sorting apparatus 30 . Referring to FIG. 2 , the test case sorting apparatus 30 may include a population initialization module 301 , an encoding module 302 , a merging module 303 , a sorting module 304 and an output module 305 . A module referred to in this application refers to a series of computer-readable instruction segments that can be executed by at least one processor and can perform fixed functions, and are stored in a memory. The functions of each module will be described in detail in subsequent embodiments.
所述种群初始化模块301获取测试用例集获取测试用例集,对所述测试用例集中的测试用例按随机顺序进行排列得到第一规模测试用例序列,将所述第一规模测试用例序列作为初代测试用例序列种群。The population initialization module 301 obtains a test case set to obtain a test case set, arranges the test cases in the test case set in random order to obtain a first-scale test case sequence, and uses the first-scale test case sequence as the first-generation test case. sequence population.
在本申请的至少一个实施方式中,所述初代测试用例序列种群的规模根据所述测试用例集中测试用例的数量确定。In at least one embodiment of the present application, the size of the primary test case sequence population is determined according to the number of test cases in the test case set.
具体地,所述测试用例集由测试用例组成,测试用例序列由所述测试用例集中的测试用例按随机顺序进行排列得到,测试用例序列种群由测试用例序列组成。Specifically, the test case set is composed of test cases, the test case sequence is obtained by arranging the test cases in the test case set in random order, and the test case sequence population is composed of test case sequences.
所述编码模块302对所述初代测试用例序列种群中的每个测试用例序列进行二进制编码。The encoding module 302 performs binary encoding on each test case sequence in the population of primary test case sequences.
在本申请的至少一个实施方式中,所述对所述初代测试用例序列种群中的每个测试用例序列进行二进制编码包括:In at least one embodiment of the present application, the binary encoding of each test case sequence in the primary test case sequence population includes:
采用二进制编码方式按照所述测试用例序列的基因位对所述初代测试用例序列种群中的测试用例序列进行编码,所述测试用例序列的基因位为相应的测试用例的序列号。The test case sequence in the primary test case sequence population is encoded according to the locus of the test case sequence in a binary coding manner, and the locus of the test case sequence is the serial number of the corresponding test case.
所述合并模块303使用选择函数对经过二进制编码的所述初代测试用例序列种群进行评价得到测试用例序列的评价值,根据每个测试用例序列的评价值对所述初代测试用例序列种群进行无回放随机选择,并使用单点交叉算子和/或序号变异算子对无回放随机选择得到的测试用例序列进行计算得到第一代子代测试用例序列种群,合并所述第一代 子代测试用例序列种群与所述初代测试用例序列种群得到第二规模的第一代测试用例序列合并种群。The merging module 303 uses a selection function to evaluate the binary-coded first-generation test case sequence population to obtain an evaluation value of the test case sequence, and performs no playback on the first-generation test case sequence population according to the evaluation value of each test case sequence. Randomly select, and use the single-point crossover operator and/or the sequence number mutation operator to calculate the test case sequence obtained by random selection without playback to obtain the first-generation progeny test case sequence population, and combine the first-generation progeny test cases. The sequence population is combined with the primary test case sequence population to obtain a second-scale merged population of primary test case sequences.
在本申请的至少一个实施方式中,所述合并模块303使用选择函数对经过二进制编码的所述初代测试用例序列种群进行评价得到测试用例序列的评价值包括:In at least one embodiment of the present application, the merging module 303 uses a selection function to evaluate the binary-coded first-generation test case sequence population to obtain an evaluation value of the test case sequence including:
根据公式
Figure PCTCN2021109431-appb-000018
对所述第一规模的初代测试用例序列种群进行评价得到测试用例序列的评价值
Figure PCTCN2021109431-appb-000019
其中,
Figure PCTCN2021109431-appb-000020
代表测试用例序列的相似度,
Figure PCTCN2021109431-appb-000021
代表测试用例序列的相异度;
According to the formula
Figure PCTCN2021109431-appb-000018
Evaluate the population of the first-generation test case sequence of the first scale to obtain the evaluation value of the test case sequence
Figure PCTCN2021109431-appb-000019
in,
Figure PCTCN2021109431-appb-000020
represents the similarity of the test case sequence,
Figure PCTCN2021109431-appb-000021
Represents the dissimilarity of the test case sequence;
Figure PCTCN2021109431-appb-000022
的计算方法为
Figure PCTCN2021109431-appb-000023
其中,S(x i,x j)表示x i和x j的相似度,计算方法为:
Figure PCTCN2021109431-appb-000022
The calculation method is
Figure PCTCN2021109431-appb-000023
Among them, S(x i ,x j ) represents the similarity between x i and x j , and the calculation method is:
Figure PCTCN2021109431-appb-000024
Figure PCTCN2021109431-appb-000024
Figure PCTCN2021109431-appb-000025
Figure PCTCN2021109431-appb-000025
Figure PCTCN2021109431-appb-000026
的计算方法为:
Figure PCTCN2021109431-appb-000027
其中,D(x i,x j)表示x i和x j的相异度,计算方法为:
Figure PCTCN2021109431-appb-000026
The calculation method is:
Figure PCTCN2021109431-appb-000027
Among them, D(x i , x j ) represents the dissimilarity between x i and x j , and the calculation method is:
Figure PCTCN2021109431-appb-000028
Figure PCTCN2021109431-appb-000028
Figure PCTCN2021109431-appb-000029
Figure PCTCN2021109431-appb-000029
在本申请的至少一个实施方式中,α和β取值为0.5,在本申请的其他实施方式中,α和β可以取其他数值。In at least one embodiment of the present application, α and β take a value of 0.5, and in other embodiments of the present application, α and β can take other values.
在本申请的至少一个实施方式中,所述合并模块303所述根据每个测试用例序列的评价值对所述初代测试用例序列种群进行无回放随机选择,并使用单点交叉算子和/或序号变异算子对无回放随机选择得到的测试用例序列进行计算得到第一代子代测试用例序列种群包括:In at least one embodiment of the present application, the merging module 303 randomly selects the initial test case sequence population without playback according to the evaluation value of each test case sequence, and uses a single-point crossover operator and/or The sequence number mutation operator calculates the test case sequence obtained by random selection without playback to obtain the first-generation descendant test case sequence population including:
创建步骤,创建所述第一代子代测试用例序列种群;The creating step is to create the first-generation progeny test case sequence population;
随机选择步骤,根据每个测试用例序列的评价值对所述初代测试用例序列种群进行无回放随机选择得到初始资源池;In the random selection step, according to the evaluation value of each test case sequence, the initial resource pool is obtained by randomly selecting the population of the first-generation test case sequence without playback;
交叉变异步骤,使用所述单点交叉算子和/或所述序号变异算子对所述初始资源池中的测试用例序列进行交叉和变异,将经过交叉和变异的所述测试用例序列加入所述子代测试用例序列种群;The crossover mutation step is to use the single-point crossover operator and/or the sequence number mutation operator to crossover and mutate the test case sequence in the initial resource pool, and add the crossover and mutated test case sequence to the test case sequence. Describe the descendant test case sequence population;
种群生成步骤,重复所述随机选择步骤与所述交叉变异步骤,直至所述子代测试用例序列种群规模为所述第一规模。In the population generation step, the random selection step and the crossover mutation step are repeated until the population size of the progeny test case sequence is the first size.
在本申请的至少一个实施方式中,根据所述初代测试用例序列种群,根据所述评价值使用无回放随机选择算子得到初始资源池包括:In at least one embodiment of the present application, according to the initial test case sequence population, according to the evaluation value, using a random selection operator without playback to obtain the initial resource pool includes:
根据公式M=f i/∑f i/n计算所述初代测试用例序列种群中每个测试用例序列在下一代的生存期望数目M,其中,f i为测试用例序列i的目标函数值,n为所述初代测试用例序列种群的规模; Calculate the expected survival number M of each test case sequence in the first generation test case sequence population in the next generation according to the formula M=f i /∑f i /n, where f i is the objective function value of the test case sequence i, n is the size of the primary test case sequence population;
随机选择步骤,根据所述评价值随机选择所述初代测试用例序列种群中的测试用例序列进入初始资源池,若所述初始资源池中的测试用例序列被选中并与所述单点交叉算子进行运算,则所述初始资源池中的所述测试用例序列在下一代的生存期望数目M减去0.5,若所述初始资源池中的所述测试用例序列不被选中且不与所述单点交叉算子进行运算,则所述初始资源池中的所述测试用例序列在下一代的生存期望数目减去1;In the random selection step, according to the evaluation value, the test case sequence in the initial test case sequence population is randomly selected to enter the initial resource pool, if the test case sequence in the initial resource pool is selected and performed with the single-point crossover operator. operation, then the expected survival number M in the next generation of the test case sequence in the initial resource pool is minus 0.5, if the test case sequence in the initial resource pool is not selected and not related to the single point If the crossover operator is performed, the expected number of survival of the test case sequence in the initial resource pool in the next generation is subtracted by 1;
重复进行所述随机选择步骤,直到所述初始资源池中的所述测试用例序列的生存期望数目小于0。The random selection step is repeated until the expected survival number of the test case sequence in the initial resource pool is less than 0.
在本申请的至少一个实施方式中,当所述初始资源池中的所述测试用例序列的生存 期望小于0时,所述初始资源池中的所述测试用例序列不再被选中。In at least one embodiment of the present application, when the survival expectation of the test case sequence in the initial resource pool is less than 0, the test case sequence in the initial resource pool is no longer selected.
在本申请的至少一个实施方式中,所述目标函数值由目标函数计算得到,所述目标函数包括平均故障检测率APFD(Average Percentage of Faults Detected)、语句覆盖率APSC(Average Percentage of Statement Coverage)、有效执行时间EET(Effective Execution Time)。In at least one embodiment of the present application, the objective function value is calculated by an objective function, and the objective function includes an average fault detection rate APFD (Average Percentage of Faults Detected), a statement coverage rate APSC (Average Percentage of Statement Coverage) , Effective execution time EET (Effective Execution Time).
在本申请的至少一个实施方式中,所述平均故障检测率根据公式
Figure PCTCN2021109431-appb-000030
Figure PCTCN2021109431-appb-000031
计算得到,其中,APFD为所述平均故障检测率,n为测试用例集T中的测试用例数量,m 1为被测软件缺陷总数量,TF i表示排序后测试用例序列T′中首次检测到缺陷i的测试用例在该执行次序中所处的次序。
In at least one embodiment of the present application, the average failure detection rate is based on the formula
Figure PCTCN2021109431-appb-000030
Figure PCTCN2021109431-appb-000031
Calculated, where APFD is the average failure detection rate, n is the number of test cases in the test case set T, m 1 is the total number of software defects under test, and TF i represents the first detection in the sequence of test cases T' after sorting The order in which the test cases for defect i are placed in this execution order.
本实施例中,所述平均故障检测率用于计算测试用例执行过程中检测到缺陷的平均累计比例。In this embodiment, the average failure detection rate is used to calculate the average cumulative proportion of defects detected during the execution of the test case.
在本申请的至少一个实施方式中,所述语句覆盖率根据公式
Figure PCTCN2021109431-appb-000032
Figure PCTCN2021109431-appb-000033
计算得到,其中,APSC为所述语句覆盖率,n为测试用例集T中测试用例的数量,m 2为被测软件语句总数量,TS i表示排序后测试用例序列T′中首次覆盖第i行代码的测试用例在该执行次序中所处的次序。
In at least one embodiment of the present application, the statement coverage is based on the formula
Figure PCTCN2021109431-appb-000032
Figure PCTCN2021109431-appb-000033
Calculated, where APSC is the statement coverage rate, n is the number of test cases in the test case set T, m 2 is the total number of software statements under test, TS i represents the first coverage of the i-th test case sequence T' after sorting The order in which the test cases of the line of code are placed in this execution order.
本实施例中,所述语句覆盖率用于计算在测试用例执行时,所用到的可执行语句数与全部可执行语句数的比例。In this embodiment, the statement coverage rate is used to calculate the ratio of the number of executable statements to the number of all executable statements used when the test case is executed.
在本申请的至少一个实施方式中,所述有效执行时间根据公式
Figure PCTCN2021109431-appb-000034
计算得到,其中,EET为所述有效执行时间,ET i表示执行第i个测试用例时所消耗的时间。
In at least one embodiment of the present application, the effective execution time is based on the formula
Figure PCTCN2021109431-appb-000034
Calculated, wherein, EET is the effective execution time, and ET i represents the time consumed when executing the i-th test case.
本实施例中,所述有效执行时间用于计算测试用例的故障检测率和语句覆盖率达到最大时的执行总时间。In this embodiment, the effective execution time is used to calculate the total execution time when the fault detection rate and the statement coverage rate of the test case reach the maximum.
本申请的至少一个实施方式中,使用单点交叉算子对所述初始资源池中的测试用例进行交叉包括:In at least one embodiment of the present application, using a single-point crossover operator to cross the test cases in the initial resource pool includes:
在所述初始资源池中随机选择至少一对父测试用例序列;randomly select at least one pair of parent test case sequences in the initial resource pool;
对于所述至少一对父测试用例序列的每对父测试用例序列,进行单点交叉;for each pair of parent test case sequences of the at least one pair of parent test case sequences, perform single-point crossover;
所述单点交叉包括:The single point intersection includes:
对于一对父测试用例序列,1号父测试用例序列和2号父测试用例序列,随机选取交叉位置k,k∈[0,L],L为种群测试用例序列的编码长度,将1号父测试用例序列的前k个基因直接作为1号子测试用例序列的前k个基因,将2号父测试用例序列中与1号父测试用例序列的前k个基因中相同的基因去掉,得到一个长度为L-k的新基因片段,并将其作为1号子测试用例序列的后L-k个基因,采用相同的方法产生2号子测试用例序列。For a pair of parent test case sequences, the No. 1 parent test case sequence and the No. 2 parent test case sequence, the cross position k, k∈[0, L] is randomly selected, where L is the coding length of the population test case sequence, and the No. 1 parent test case sequence is The first k genes of the test case sequence are directly used as the first k genes of the No. 1 sub-test case sequence, and the same genes in the No. 2 parent test case sequence as the first k genes of the No. 1 parent test case sequence are removed to obtain a A new gene fragment of length L-k is used as the last L-k genes of the sub-test case sequence No. 1, and the same method is used to generate the sub-test case sequence No. 2.
在本申请的至少一个实施方式中,使用所述序号变异算子对所述初始资源池中的测试用例序列进行变异包括:In at least one embodiment of the present application, using the sequence number mutation operator to mutate the test case sequence in the initial resource pool includes:
随机选择所述初始资源池中至少一个测试用例序列,对于所述至少一个测试用例序列中的每个测试用例序列,随机选择所述测试用例序列上的两个基因位,将两个基因位的值进行交换。Randomly select at least one test case sequence in the initial resource pool, for each test case sequence in the at least one test case sequence, randomly select two loci on the test case sequence, and combine the two loci of the test case sequence. value is exchanged.
所述排序模块304对所述第一代测试用例序列合并种群进行非支配排序,计算所述第一代测试用例序列合并种群的拥挤度,并根据所述拥挤度使用拥挤度比较算子对所述第一代测试用例序列合并种群进行计算得到第一规模的第一代测试用例序列种群,并令迭代次数g=1。The sorting module 304 performs non-dominant sorting on the combined population of the first-generation test case sequences, calculates the crowding degree of the combined population of the first-generation test case sequences, and uses a crowding degree comparison operator to perform a non-dominant sorting on the combined population of the first-generation test case sequences according to the crowding degree. The first-generation test case sequence is combined with the population for calculation to obtain the first-scale first-generation test case sequence population, and the number of iterations g=1.
在本申请的至少一个实施方式中,所述对所述第一代测试用例序列合并种群进行非支配排序包括:In at least one embodiment of the present application, the non-dominated sorting of the first-generation test case sequence merged population includes:
计算步骤,计算所述种群中的所有测试用例序列的故障检测率、语句覆盖率和有效执行时间,并将所述故障检测率、所述语句覆盖率和所述有效执行时间作为排序目标函 数,得到三个由目标函数值组成的数组;The calculation step is to calculate the fault detection rate, statement coverage rate and effective execution time of all test case sequences in the population, and use the fault detection rate, the statement coverage rate and the effective execution time as a sorting objective function, Get three arrays of objective function values;
排序步骤,创建外部非支配解集,以最大化所述故障检测率、最大化所述语句覆盖率、最小化所述有效执行时间为目标,根据所述三个由目标函数值组成的数组,得到成对的非支配解,将所述成对的非支配解加入所述外部非支配解集,两两比较所述外部非支配解集中的测试用例序列,去除不是非支配解的解,使得所述外部非支配解集中的测试用例序列两两互为非支配解,其中,所述非支配解为非支配关系的测试用例序列;A sorting step, creating an external non-dominated solution set, with the goal of maximizing the fault detection rate, maximizing the statement coverage, and minimizing the effective execution time, according to the three arrays consisting of objective function values, Obtain paired non-dominated solutions, add the paired non-dominated solutions to the external non-dominated solution set, compare the test case sequences in the external non-dominated solution set pairwise, and remove the solutions that are not non-dominated solutions, so that The test case sequences in the external non-dominated solution set are mutually non-dominated solutions, wherein the non-dominated solutions are test case sequences of non-dominated relationships;
解集生成步骤,对所述第一代测试用例序列合并种群中除所述外部非支配解集中的测试用例序列外的所有测试用例序列执行所述计算步骤与所述排序步骤,得到非支配排序后的外部非支配解集系列,所述非支配排序后的外部非支配解集系列中排序在前的外部非支配解集中的任一测试用例的故障检测率大于排序在后的外部非支配解集中的所有测试用例的故障检测率,且所述非支配排序后的外部非支配解集系列中排序在前的外部非支配解集中的任一测试用例的语句覆盖率大于排序在后的外部非支配解集中的所有测试用例的语句覆盖率,且所述非支配排序后的外部非支配解集系列中排序在前的外部非支配解集中的任一测试用例的有效执行时间小于排序在后的外部非支配解集中的所有测试用例。The solution set generation step is to perform the calculation step and the sorting step on all test case sequences in the merged population of the first-generation test case sequences except the test case sequences in the external non-dominated solution set, to obtain a non-dominated ranking The subsequent external non-dominated solution set series, the failure detection rate of any test case in the external non-dominated solution set ranked first in the non-dominated sorted external non-dominated solution set series is greater than that of the external non-dominated solution set after the ranking. The failure detection rate of all test cases in the set, and the statement coverage rate of any test case in the external non-dominated solution set ranked first in the external non-dominated solution set series after the non-dominated sorting is greater than that of the external non-dominated solution set ranked last. The statement coverage of all test cases in the dominant solution set, and the effective execution time of any test case in the external non-dominated solution set ranked first in the non-dominated sorted external non-dominated solution set series is less than that of the later sorted external non-dominated solution set. All test cases in the outer non-dominated solution set.
具体地,对于任意两个测试用例序列R k和R r进行非支配排序包括: Specifically, the non-dominated sorting for any two test case sequences R k and R r includes:
当APFD k>APFD r且APSC k>APSC r且EET k>EET r时,或APFD k<APFD r且APSC k<APSC r且EET k<EET r时,或APFD k>APFD r且APSC k<APSC r且EET k<EET r时,或APFD k<APFD r且APSC k>APSC r且EET k>EET r时,或APFD k<APFD r且APSC k>APSC r且EET k<EET r时,或APFD k>APFD r且APSC k<APSC r且EET k>EET r时,R k和R r互为非支配解。 When APFD k >APFD r and APSC k >APSC r and EET k >EET r , or APFD k < APFD r and APSC k < APSC r and EET k < EET r , or APFD k >APFD r and APSC k < APSC r and EET k < EET r , or APFD k < APFD r and APSC k >APSC r and EET k >EET r , or APFD k < APFD r and APSC k >APSC r and EET k < EET r , Or when APFD k >APFD r and APSC k <APSC r and EET k >EET r , R k and R r are mutually non-dominated solutions.
在本申请的至少一个实施方式中,所述计算所述第一代测试用例序列合并种群的拥挤度包括:In at least one embodiment of the present application, the calculating the crowding degree of the combined population of the first-generation test case sequences includes:
令所述第一代测试用例序列合并种群中的测试用例序列t的拥挤度d t=0,其中,t表示测试用例序列,t=1,2,…,n; Let the crowding degree of the test case sequence t in the first-generation test case sequence merged population d t =0, where t represents the test case sequence, t=1, 2,...,n;
对于每个目标函数f(x)进行如下操作:For each objective function f(x) do the following:
基于所述目标函数f(x)对第一代测试用例序列合并种群中的测试用例序列进行单目标排序;Based on the objective function f(x), single-objective sorting is performed on the test case sequences in the merged population of the first-generation test case sequences;
令边界的两个测试用例序列d 1、d n的拥挤度为无穷,即d 1=d n=∞; Let the crowding degree of the two test case sequences d 1 and d n be infinite, that is, d 1 =d n =∞;
根据公式d t=d t+(f(f+1)-f(t-1))计算所述测试用例序列t的拥挤度,其中,t=2,3,…,n-1。 The crowding degree of the test case sequence t is calculated according to the formula d t =d t +(f(f+1)-f(t-1)), where t=2,3,...,n-1.
在本申请的一个实施方式中,所述根据所述拥挤度使用拥挤度比较算子对所述第一代测试用例序列合并种群进行计算得到第一规模的第一代测试用例序列种群包括:In an embodiment of the present application, the first-generation test case sequence population of the first scale obtained by calculating the first-generation test case sequence merged population by using a crowding degree comparison operator according to the crowding degree includes:
创建第一代预备种群;Create a first-generation reserve population;
将所述非支配排序后的外部非支配解集系列中的外部非支配解集按次序加入所述第一代预备种群,直至所述第一代预备种群规模大于或等于第一规模;或adding the external non-dominated solution sets in the non-dominated sorted external non-dominated solution set series to the first-generation preliminary population in order, until the first-generation preliminary population size is greater than or equal to the first size; or
当所述第一代预备种群规模等于第一规模时,将所述第一代预备种群作为所述第一代测试用例序列种群;或When the size of the first-generation preliminary population is equal to the first size, use the first-generation preliminary population as the first-generation test case sequence population; or
当所述第一代预备种群规模大于第一规模时,根据所述拥挤度使用所述拥挤度比较算子对所述第一代预备种群进行排序,得到第一规模的所述第一代测试用例序列种群。When the scale of the first-generation preliminary population is larger than the first scale, use the crowding degree comparison operator to sort the first-generation preliminary population according to the crowding degree to obtain the first-generation test of the first scale Use case sequence population.
在本申请的至少一个实施方式中,使用所述拥挤度比较算子对所述第一代预备种群进行排序包括:In at least one embodiment of the present application, using the crowding degree comparison operator to sort the first-generation preliminary population includes:
对于所述第一代预备种群中的两个测试用例序列i和j,当测试用例序列i所处的外部非支配解集次序优于测试用例序列j所处的外部非支配解集时,测试用例序列i的排序优于测试用例序列j;或For the two test case sequences i and j in the first-generation preliminary population, when the outer non-dominated solution set where the test case sequence i is located is better than the outer non-dominated solution set where the test case sequence j is located, the test Case sequence i is ranked better than test case sequence j; or
当测试用例序列i和测试用例序列j所处的外部非支配解集相同且测试用例序列i的拥 挤度大于测试用例序列j的拥挤度时,测试用例序列i的排序优于测试用例序列j。When test case sequence i and test case sequence j are located in the same external non-dominated solution set and the crowding degree of test case sequence i is greater than that of test case sequence j, the ordering of test case sequence i is better than that of test case sequence j.
所述输出模块305对所述第一代测试用例序列种群执行预设操作直至g等于预设阈值,将第g代测试用例序列种群作为最优解集,输出所述最优解集。The output module 305 performs a preset operation on the first-generation test case sequence population until g is equal to a preset threshold, takes the g-th generation test case sequence population as the optimal solution set, and outputs the optimal solution set.
本实施例中,所述执行预设操作包括:In this embodiment, the performing a preset operation includes:
使用选择函数对第g代测试用例序列种群进行评价得到测试用例序列的评价值,根据每个测试用例序列的评价值对所述第g代测试用例序列种群进行无回放随机选择,并使用单点交叉算子和/或改进变异算子对无回放随机选择得到的测试用例序列进行计算得到第g+1代子代测试用例序列种群;Use the selection function to evaluate the g-th generation test case sequence population to obtain the evaluation value of the test case sequence, and perform random selection without playback on the g-th generation test case sequence population according to the evaluation value of each test case sequence, and use a single point The crossover operator and/or the improved mutation operator calculate the test case sequence obtained by random selection without playback to obtain the g+1 generation offspring test case sequence population;
合并所述第g代测试用例序列种群和所述第g+1代子代测试用例序列种群得到第二规模的第g+1代测试用例序列合并种群;combining the g-th generation test case sequence population and the g+1-th generation progeny test case sequence population to obtain a second-scale combined population of the g+1-th generation test case sequence;
对所述第g+1代测试用例序列合并种群进行非支配排序;Perform non-dominated sorting on the combined population of the g+1 generation test case sequence;
计算所述第g+1代测试用例序列合并种群的拥挤度;Calculate the crowding degree of the combined population of the g+1 generation test case sequence;
根据所述第g+1代测试用例序列合并种群的拥挤度使用拥挤度比较算子得到第一规模的第g+1代测试用例序列种群,令迭代次数g=g+1。According to the crowding degree of the combined population of the test case sequence of the g+1 generation, the crowding degree comparison operator is used to obtain the test case sequence population of the g+1 generation of the first scale, and the number of iterations is g=g+1.
使用所述改进变异算子根据第一规模的第g代测试用例序列种群得到第一规模的第g+1代测试用例序列种群包括:Using the improved mutation operator to obtain the first-scale g+1-th generation test case sequence population according to the first-scale g-th generation test case sequence population includes:
设定gen1,其中,1<gen1<n/2,设定gen2,其中,gen1<gen2<n,n为所述第一规模;Set gen1, where 1<gen1<n/2, set gen2, where gen1<gen2<n, n is the first scale;
设定所述第g代测试用例序列种群中测试用例序列的高位区为[0,length/3],测试用例序列的中位区为(length/3,length*2/3],测试用例序列的低位区为(length*2/3,length],length为所述测试用例序列的长度;Set the high-order region of the test case sequence in the g-th generation test case sequence population as [0, length/3], the median region of the test case sequence as (length/3, length*2/3], and the test case sequence The low-order area of is (length*2/3, length], and length is the length of the test case sequence;
当1≤g<gen1时,随机选择所述第g代测试用例序列种群中的至少一个测试用例序列,对所述至少一个测试用例序列中的每个测试用例序列,随机选择所述每个测试用例序列的高位区的两个基因位,将所述两个基因位的值进行交换;When 1≤g<gen1, randomly select at least one test case sequence in the g-th generation test case sequence population, and randomly select each test case sequence in the at least one test case sequence Using two loci in the high order region of the case sequence, the values of the two loci are exchanged;
当gen1≤g<gen2时,随机选择所述第g代测试用例序列种群中的至少一个测试用例序列,对所述至少一个测试用例序列中的每个测试用例序列,随机选择所述每个测试用例序列的中位区的两个基因位,将所述两个基因位的值进行交换;When gen1≤g<gen2, randomly select at least one test case sequence in the g-th generation test case sequence population, and randomly select each test case sequence in the at least one test case sequence Using the two loci of the median region of the case sequence, the values of the two loci are exchanged;
当gen2≤g<n时,随机选择所述第g代测试用例序列种群中的至少一个测试用例序列,对所述至少一个测试用例序列中的每个测试用例序列,随机选择所述每个测试用例序列的低位区的两个基因位,将所述两个基因位的值进行交换。When gen2≤g<n, randomly select at least one test case sequence in the g-th generation test case sequence population, and randomly select each test case sequence in the at least one test case sequence Using two loci in the lower region of the case sequence, the values of the two loci are swapped.
本申请中,初始化测试用例集得到初代测试用例序列种群,对初代测试用例序列种群进行编码,使用选择函数评价初代测试用例序列种群中的测试用例序列,使用选择、交叉和/或序号变异方法得到子代测试用例序列种群,合并子代测试用例种群与初代测试用例种群得到合并种群,对种群进行排序,并使用拥挤度比较算子得到下一代种群,通过循环选择、交叉和/或根据迭代次数对测试用例序列进行变异的方法及使用基于帕累托最优的非支配排序遗传算法、拥挤度比较算子,得到最优解集,并输出最优测试用例,通过对测试用例的快速非支配排序,提高了软件的故障检测和回归测试的效率,进而降低软件的测试成本。In this application, initialize the test case set to obtain the initial test case sequence population, encode the initial test case sequence population, use the selection function to evaluate the test case sequence in the initial test case sequence population, and use the selection, crossover and/or sequence number mutation method to obtain The descendant test case sequence population, merge the descendant test case population and the original test case population to obtain the combined population, sort the population, and use the crowding degree comparison operator to obtain the next generation population, through cyclic selection, crossover and/or according to the number of iterations The method of mutating the test case sequence and using the non-dominated sorting genetic algorithm based on Pareto optimality and the crowding degree comparison operator to obtain the optimal solution set, and output the optimal test case. Sorting improves the efficiency of software fault detection and regression testing, thereby reducing software testing costs.
实施例3Example 3
图3为本申请一实施方式中电子设备6的示意图。FIG. 3 is a schematic diagram of an electronic device 6 in an embodiment of the present application.
所述电子设备6包括存储器61、处理器62以及存储在所述存储器61中并可在所述处理器62上运行的计算机可读指令。所述处理器62执行所述计算机可读指令时实现上述测试用例排序方法实施例中的步骤,例如图1所示的步骤S11~S15。或者,所述处理器62执行所述计算机可读指令时实现上述测试用例排序装置实施例中各模块/单元的功能,例如图2中的模块301~305。The electronic device 6 includes a memory 61 , a processor 62 and computer readable instructions stored in the memory 61 and executable on the processor 62 . When the processor 62 executes the computer-readable instructions, the steps in the above embodiment of the test case sorting method are implemented, for example, steps S11 to S15 shown in FIG. 1 . Alternatively, when the processor 62 executes the computer-readable instructions, the functions of each module/unit in the above-mentioned embodiment of the apparatus for sorting test cases, such as modules 301 to 305 in FIG. 2 , are implemented.
示例性的,所述计算机可读指令可以被分割成一个或多个模块/单元,所述一个或者多个模块/单元被存储在所述存储器61中,并由所述处理器62执行,以完成本申请。所 述一个或多个模块/单元可以是能够完成特定功能的一系列计算机可读指令段,所述指令段用于描述所述计算机可读指令在所述电子设备6中的执行过程。例如,所述计算机可读指令可以被分割成图2中的种群初始化模块301、编码模块302、合并模块303、排序模块304及输出模块305,各模块具体功能参见实施例2。Exemplarily, the computer-readable instructions may be divided into one or more modules/units, and the one or more modules/units are stored in the memory 61 and executed by the processor 62 to Complete this application. The one or more modules/units may be a series of computer-readable instruction segments capable of accomplishing specific functions, and the instruction segments are used to describe the execution process of the computer-readable instructions in the electronic device 6 . For example, the computer-readable instructions can be divided into a population initialization module 301, an encoding module 302, a merging module 303, a sorting module 304, and an output module 305 in FIG.
本实施方式中,所述电子设备6可以是桌上型计算机、笔记本、掌上电脑、服务器及云端终端装置等计算设备。本领域技术人员可以理解,所述示意图仅仅是电子设备6的示例,并不构成对电子设备6的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件,例如所述电子设备6还可以包括输入输出设备、网络接入设备、总线等。In this embodiment, the electronic device 6 may be a computing device such as a desktop computer, a notebook, a palmtop computer, a server, and a cloud terminal device. Those skilled in the art can understand that the schematic diagram is only an example of the electronic device 6, and does not constitute a limitation to the electronic device 6, and may include more or less components than the one shown, or combine some components, or different Components such as the electronic device 6 may also include input and output devices, network access devices, buses, and the like.
所称处理器62可以是中央处理模块(Central Processing Unit,CPU),还可以是其他通用处理器、数字信号处理器(Digital Signal Processor,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现场可编程门阵列(Field-Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。通用处理器可以是微处理器或者所述处理器62也可以是任何常规的处理器等,所述处理器62是所述电子设备6的控制中心,利用各种接口和线路连接整个电子设备6的各个部分。The so-called processor 62 may be a central processing module (Central Processing Unit, CPU), or other general-purpose processors, digital signal processors (Digital Signal Processor, DSP), application specific integrated circuits (Application Specific Integrated Circuit, ASIC), Field-Programmable Gate Array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or the processor 62 can also be any conventional processor, etc. The processor 62 is the control center of the electronic device 6, and uses various interfaces and lines to connect the entire electronic device 6. of each part.
所述存储器61可用于存储所述计算机可读指令和/或模块/单元,所述处理器62通过运行或执行存储在所述存储器61内的计算机可读指令和/或模块/单元,以及调用存储在存储器61内的数据,实现所述电子设备6的各种功能。所述存储器61可主要包括存储程序区和存储数据区,其中,存储程序区可存储操作系统、至少一个功能所需的应用程序(比如声音播放功能、图像播放功能等)等;存储数据区可存储根据电子设备6的使用所创建的数据等。此外,存储器61可以包括易失性存储器,还可以包括非易失性存储器,例如硬盘、内存、插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(Flash Card)、至少一个磁盘存储器件、闪存器件、或其他存储器件。The memory 61 may be used to store the computer-readable instructions and/or modules/units, and the processor 62 executes or executes the computer-readable instructions and/or modules/units stored in the memory 61, and calls The data stored in the memory 61 realizes various functions of the electronic device 6 . The memory 61 may mainly include a stored program area and a stored data area, wherein the stored program area may store an operating system, an application program required for at least one function (such as a sound playback function, an image playback function, etc.); the storage data area may Data and the like created according to the use of the electronic device 6 are stored. In addition, the memory 61 may include volatile memory, and may also include non-volatile memory, such as hard disk, internal memory, plug-in hard disk, Smart Media Card (SMC), Secure Digital (SD) card , a flash memory card (Flash Card), at least one disk storage device, flash memory device, or other storage device.
所述电子设备6集成的模块/单元如果以软件功能模块的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请实现上述实施例方法中的全部或部分流程,也可以通过计算机可读指令来指令相关的硬件来完成,所述的计算机可读指令可存储于一计算机可读存储介质中,所述计算机可读指令在被处理器执行时,可实现上述各个方法实施例的步骤。其中,所述计算机可读存储介质可以是非易失性的存储介质,也可以是易失性的存储介质。所述计算机可读指令包括计算机可读指令代码,所述计算机可读指令代码可以为源代码形式、对象代码形式、可执行文件或某些中间形式等。If the modules/units integrated in the electronic device 6 are implemented in the form of software functional modules and sold or used as independent products, they may be stored in a computer-readable storage medium. Based on this understanding, the present application can implement all or part of the processes in the methods of the above embodiments, and can also be completed by instructing relevant hardware through computer-readable instructions, and the computer-readable instructions can be stored in a computer-readable storage medium. , the computer-readable instructions, when executed by the processor, can implement the steps of the above-mentioned method embodiments. The computer-readable storage medium may be a non-volatile storage medium or a volatile storage medium. The computer-readable instructions include computer-readable instruction code, which may be in source code form, object code form, executable file, or some intermediate form, and the like.
本申请所指区块链是分布式数据存储、点对点传输、共识机制、加密算法等计算机技术的新型应用模式。区块链(Blockchain),本质上是一个去中心化的数据库,是一串使用密码学方法相关联产生的数据块,每一个数据块中包含了一批次网络交易的信息,用于验证其信息的有效性(防伪)和生成下一个区块。区块链可以包括区块链底层平台、平台产品服务层以及应用服务层等。The blockchain referred to in this application is a new application mode of computer technologies such as distributed data storage, point-to-point transmission, consensus mechanism, and encryption algorithm. Blockchain, essentially a decentralized database, is a series of data blocks associated with cryptographic methods. Each data block contains a batch of network transaction information to verify its Validity of information (anti-counterfeiting) and generation of the next block. The blockchain can include the underlying platform of the blockchain, the platform product service layer, and the application service layer.
在本申请所提供的几个实施例中,应该理解到,所揭露的装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述模块的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式。In the several embodiments provided in this application, it should be understood that the disclosed apparatus and method may be implemented in other manners. For example, the apparatus embodiments described above are only illustrative. For example, the division of the modules is only a logical function division, and there may be other division manners in actual implementation.
另外,在本申请各个实施例中的各功能模块可以集成在相同处理模块中,也可以是各个模块单独物理存在,也可以两个或两个以上模块集成在相同模块中。上述集成的模块既可以采用硬件的形式实现,也可以采用硬件加软件功能模块的形式实现。In addition, each functional module in each embodiment of the present application may be integrated in the same processing module, or each module may exist physically alone, or two or more modules may be integrated in the same module. The above-mentioned integrated modules can be implemented in the form of hardware, or can be implemented in the form of hardware plus software function modules.
对于本领域技术人员而言,显然本申请不限于上述示范性实施例的细节,而且在不背离本申请的精神或基本特征的情况下,能够以其他的具体形式实现本申请。因此,无论从哪一点来看,均应将实施例看作是示范性的,而且是非限制性的,本申请的范围由 所附权利要求而不是上述说明限定,因此旨在将落在权利要求的等同要件的含义和范围内的所有变化涵括在本申请内。不应将权利要求中的任何附图标记视为限制所涉及的权利要求。此外,显然“包括”一词不排除其他模块或步骤,单数不排除复数。本申请中陈述的多个模块或电子设备也可以由同一个模块或电子设备通过软件或者硬件来实现。第一,第二等词语用来表示名称,而并不表示任何特定的顺序。It will be apparent to those skilled in the art that the present application is not limited to the details of the above-described exemplary embodiments, but that the present application can be implemented in other specific forms without departing from the spirit or essential characteristics of the present application. Accordingly, the embodiments are to be regarded in all respects as illustrative and not restrictive, and the scope of the application is to be defined by the appended claims rather than the foregoing description, which is therefore intended to fall within the scope of the claims. All changes within the meaning and scope of the equivalents of , are included in this application. Any reference signs in the claims shall not be construed as limiting the involved claim. Furthermore, it is clear that the word "comprising" does not exclude other modules or steps, and the singular does not exclude the plural. Multiple modules or electronic devices stated in this application may also be implemented by the same module or electronic device through software or hardware. The terms first, second, etc. are used to denote names and do not denote any particular order.
最后应说明的是,以上实施例仅用以说明本申请的技术方案而非限制,尽管参照较佳实施例对本申请进行了详细说明,本领域的普通技术人员应当理解,可以对本申请的技术方案进行修改或等同替换,而不脱离本申请技术方案的精神和范围。Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application rather than limitations. Although the present application has been described in detail with reference to the preferred embodiments, those of ordinary skill in the art should understand that the technical solutions of the present application can be Modifications or equivalent substitutions can be made without departing from the spirit and scope of the technical solutions of the present application.

Claims (20)

  1. 一种测试用例排序方法,其中,所述测试用例排序方法包括:A test case sorting method, wherein the test case sorting method comprises:
    获取测试用例集,对所述测试用例集中的测试用例按随机顺序进行排列得到第一规模测试用例序列,将所述第一规模测试用例序列作为初代测试用例序列种群;Obtaining a test case set, arranging the test cases in the test case set in random order to obtain a first-scale test case sequence, and using the first-scale test case sequence as a population of first-generation test case sequences;
    对所述初代测试用例序列种群中的每个测试用例序列进行二进制编码;performing binary coding on each test case sequence in the primary test case sequence population;
    使用选择函数对经过二进制编码的所述初代测试用例序列种群进行评价得到测试用例序列的评价值,根据每个测试用例序列的评价值对所述初代测试用例序列种群进行无回放随机选择,并使用单点交叉算子和/或序号变异算子对无回放随机选择得到的测试用例序列进行计算得到第一代子代测试用例序列种群,合并所述第一代子代测试用例序列种群与所述初代测试用例序列种群得到第二规模的第一代测试用例序列合并种群;Use a selection function to evaluate the binary-coded primary test case sequence population to obtain the evaluation value of the test case sequence, and perform random selection without playback on the primary test case sequence population according to the evaluation value of each test case sequence, and use The single-point crossover operator and/or the sequence number mutation operator calculates the test case sequence obtained by random selection without playback to obtain the first-generation progeny test case sequence population, and combines the first-generation progeny test case sequence population with the The first-generation test case sequence population obtains the second-scale first-generation test case sequence merged population;
    对所述第一代测试用例序列合并种群进行非支配排序,计算所述第一代测试用例序列合并种群的拥挤度,并根据所述拥挤度使用拥挤度比较算子对所述第一代测试用例序列合并种群进行计算得到第一规模的第一代测试用例序列种群,并令迭代次数g=1;Perform non-dominated sorting on the combined population of the first-generation test case sequences, calculate the crowding degree of the combined population of the first-generation test case sequences, and use a crowding degree comparison operator to test the first generation according to the crowding degree The use case sequence is combined with the population for calculation to obtain the first-generation test case sequence population of the first scale, and the number of iterations g=1;
    对所述第一代测试用例序列种群执行预设操作直至g等于预设阈值,将第g代测试用例序列种群作为最优解集,输出所述最优解集。A preset operation is performed on the first-generation test case sequence population until g is equal to a preset threshold, and the g-th generation test case sequence population is used as the optimal solution set, and the optimal solution set is output.
  2. 根据权利要求1所述的测试用例排序方法,其中,所述执行预设操作包括:The method for sorting test cases according to claim 1, wherein the performing a preset operation comprises:
    使用选择函数对第g代测试用例序列种群进行评价得到测试用例序列的评价值,根据每个测试用例序列的评价值对所述第g代测试用例序列种群进行无回放随机选择,并使用单点交叉算子和/或改进变异算子对无回放随机选择得到的测试用例序列进行计算得到第g+1代子代测试用例序列种群;Use the selection function to evaluate the g-th generation test case sequence population to obtain the evaluation value of the test case sequence, and perform random selection without playback on the g-th generation test case sequence population according to the evaluation value of each test case sequence, and use a single point The crossover operator and/or the improved mutation operator calculate the test case sequence obtained by random selection without playback to obtain the g+1 generation offspring test case sequence population;
    合并所述第g代测试用例序列种群和所述第g+1代子代测试用例序列种群得到第二规模的第g+1代测试用例序列合并种群;combining the g-th generation test case sequence population and the g+1-th generation progeny test case sequence population to obtain a second-scale combined population of the g+1-th generation test case sequence;
    对所述第g+1代测试用例序列合并种群进行非支配排序;Perform non-dominated sorting on the combined population of the g+1 generation test case sequence;
    计算所述第g+1代测试用例序列合并种群的拥挤度;Calculate the crowding degree of the combined population of the g+1 generation test case sequence;
    根据所述第g+1代测试用例序列合并种群的拥挤度使用拥挤度比较算子得到第一规模的第g+1代测试用例序列种群,令迭代次数g=g+1。According to the crowding degree of the combined population of the test case sequence of the g+1 generation, the crowding degree comparison operator is used to obtain the test case sequence population of the g+1 generation of the first scale, and the number of iterations is g=g+1.
  3. 根据权利要求1所述的测试用例排序方法,其中,所述根据每个测试用例序列的评价值对所述初代测试用例序列种群进行无回放随机选择,并使用单点交叉算子和/或序号变异算子对无回放随机选择得到的测试用例序列进行计算得到第一代子代测试用例序列种群包括:The test case sorting method according to claim 1, wherein the first-generation test case sequence population is randomly selected without playback according to the evaluation value of each test case sequence, and a single-point crossover operator and/or serial number are used. The mutation operator calculates the test case sequence obtained by random selection without playback to obtain the first-generation descendant test case sequence population including:
    创建步骤,创建所述第一代子代测试用例序列种群;The creating step is to create the first-generation progeny test case sequence population;
    随机选择步骤,根据每个测试用例序列的评价值对所述初代测试用例序列种群进行无回放随机选择得到初始资源池;In the random selection step, according to the evaluation value of each test case sequence, the initial resource pool is obtained by randomly selecting the population of the first-generation test case sequence without playback;
    交叉变异步骤,使用所述单点交叉算子和/或所述序号变异算子对所述初始资源池中的测试用例序列进行交叉和变异,将经过交叉和变异的所述测试用例序列加入所述子代测试用例序列种群;The crossover mutation step is to use the single-point crossover operator and/or the sequence number mutation operator to crossover and mutate the test case sequence in the initial resource pool, and add the crossover and mutated test case sequence to the test case sequence. Describe the descendant test case sequence population;
    种群生成步骤,重复所述随机选择步骤与所述交叉变异步骤,直至所述子代测试用例序列种群规模为所述第一规模。In the population generation step, the random selection step and the crossover mutation step are repeated until the population size of the progeny test case sequence is the first size.
  4. 根据权利要求3所述的测试用例排序方法,其中,使用所述序号变异算子对所述初始资源池中的测试用例序列进行变异包括:The test case sorting method according to claim 3, wherein using the sequence number mutation operator to mutate the test case sequence in the initial resource pool comprises:
    随机选择所述初始资源池中至少一个测试用例序列,对于所述至少一个测试用例序列中的每个测试用例序列,随机选择所述测试用例序列上的两个基因位,交换两个所述基因位对应的测试用例。Randomly select at least one test case sequence in the initial resource pool, for each test case sequence in the at least one test case sequence, randomly select two loci on the test case sequence, and exchange two of the genes Bit corresponding to the test case.
  5. 根据权利要求1所述的测试用例排序方法,其中,所述对所述第一代测试用例序列合并种群进行非支配排序包括:The test case sorting method according to claim 1, wherein the non-dominated sorting of the first-generation test case sequence merged population comprises:
    计算步骤,计算所述种群中的所有测试用例序列的故障检测率、语句覆盖率和有效执行时间,并将所述故障检测率、所述语句覆盖率和所述有效执行时间作为排序目标函数,得到三个由目标函数值组成的数组;The calculation step is to calculate the fault detection rate, statement coverage rate and effective execution time of all test case sequences in the population, and use the fault detection rate, the statement coverage rate and the effective execution time as a sorting objective function, Get three arrays of objective function values;
    排序步骤,创建外部非支配解集,以最大化所述故障检测率、最大化所述语句覆盖率、最小化所述有效执行时间为目标,根据所述三个由目标函数值组成的数组,得到成对的非支配解,将所述成对的非支配解加入所述外部非支配解集,两两比较所述外部非支配解集中的测试用例序列,去除不是非支配解的解,使得所述外部非支配解集中的测试用例序列两两互为非支配解,其中,所述非支配解为非支配关系的测试用例序列;A sorting step, creating an external non-dominated solution set, with the goal of maximizing the fault detection rate, maximizing the statement coverage, and minimizing the effective execution time, according to the three arrays consisting of objective function values, Obtain paired non-dominated solutions, add the paired non-dominated solutions to the external non-dominated solution set, compare the test case sequences in the external non-dominated solution set pairwise, and remove the solutions that are not non-dominated solutions, so that The test case sequences in the external non-dominated solution set are mutually non-dominated solutions, wherein the non-dominated solutions are test case sequences of non-dominated relationships;
    解集生成步骤,对所述第一代测试用例序列合并种群中除所述外部非支配解集中的测试用例序列外的所有测试用例序列执行所述计算步骤与所述排序步骤,得到非支配排序后的外部非支配解集系列,所述非支配排序后的外部非支配解集系列中排序在前的外部非支配解集中的任一测试用例的故障检测率大于排序在后的外部非支配解集中的所有测试用例的故障检测率,且所述非支配排序后的外部非支配解集系列中排序在前的外部非支配解集中的任一测试用例的语句覆盖率大于排序在后的外部非支配解集中的所有测试用例的语句覆盖率,且所述非支配排序后的外部非支配解集系列中排序在前的外部非支配解集中的任一测试用例的有效执行时间小于排序在后的外部非支配解集中的所有测试用例。The solution set generation step is to perform the calculation step and the sorting step on all test case sequences in the merged population of the first-generation test case sequences except the test case sequences in the external non-dominated solution set, to obtain a non-dominated ranking The subsequent external non-dominated solution set series, the failure detection rate of any test case in the external non-dominated solution set ranked first in the non-dominated sorted external non-dominated solution set series is greater than that of the external non-dominated solution set after the ranking. The failure detection rate of all test cases in the set, and the statement coverage rate of any test case in the external non-dominated solution set ranked first in the external non-dominated solution set series after the non-dominated sorting is greater than that of the external non-dominated solution set ranked last. The statement coverage of all test cases in the dominant solution set, and the effective execution time of any test case in the external non-dominated solution set ranked first in the non-dominated sorted external non-dominated solution set series is less than that of the later sorted external non-dominated solution set. All test cases in the outer non-dominated solution set.
  6. 根据权利要求1所述的测试用例排序方法,其中,所述计算所述第一代测试用例序列合并种群的拥挤度包括:The test case sorting method according to claim 1, wherein the calculating the crowding degree of the merged population of the first-generation test case sequences comprises:
    令所述第一代测试用例序列合并种群中的测试用例序列t的拥挤度d t=0,其中,t表示测试用例序列,t=1,2,…,n; Let the crowding degree of the test case sequence t in the first-generation test case sequence merged population d t =0, where t represents the test case sequence, t=1, 2,...,n;
    对于每个目标函数f(x)进行如下操作:For each objective function f(x) do the following:
    基于所述目标函数f(x)对第一代测试用例序列合并种群中的测试用例序列进行单目标排序;Based on the objective function f(x), single-objective sorting is performed on the test case sequences in the merged population of the first-generation test case sequences;
    令边界的两个测试用例序列d 1、d n的拥挤度为无穷,即d 1=d n=∞; Let the crowding degree of the two test case sequences d 1 and d n be infinite, that is, d 1 =d n =∞;
    根据公式d t=d t+(f(t+1)-f(t-1))计算所述测试用例序列t的拥挤度,其中,t=2,3,…,n-1。 The crowding degree of the test case sequence t is calculated according to the formula d t =d t +(f(t+1)-f(t-1)), where t=2,3,...,n-1.
  7. 根据权利要求5所述的测试用例排序方法,其中,所述根据所述拥挤度使用拥挤度比较算子对所述第一代测试用例序列合并种群进行计算得到第一规模的第一代测试用例序列种群包括:The test case sorting method according to claim 5, wherein the first generation test case of the first scale is obtained by calculating the merged population of the first generation test case sequence using a crowding degree comparison operator according to the congestion degree Sequence populations include:
    创建第一代预备种群;Create a first-generation reserve population;
    将所述非支配排序后的外部非支配解集系列中的外部非支配解集按次序加入所述第一代预备种群,直至所述第一代预备种群规模大于或等于第一规模;或adding the external non-dominated solution sets in the non-dominated sorted external non-dominated solution set series to the first-generation preliminary population in order, until the first-generation preliminary population size is greater than or equal to the first size; or
    当所述第一代预备种群规模等于第一规模时,将所述第一代预备种群作为所述第一代测试用例序列种群;或When the size of the first-generation preliminary population is equal to the first size, use the first-generation preliminary population as the first-generation test case sequence population; or
    当所述第一代预备种群规模大于第一规模时,根据所述拥挤度使用所述拥挤度比较算子对所述第一代预备种群进行排序,得到第一规模的所述第一代测试用例序列种群。When the scale of the first-generation preliminary population is larger than the first scale, use the crowding degree comparison operator to sort the first-generation preliminary population according to the crowding degree to obtain the first-generation test of the first scale Use case sequence population.
  8. 根据权利要求7所述的测试用例排序方法,其中,使用所述拥挤度比较算子对所述第一代预备种群进行排序包括:The method for sorting test cases according to claim 7, wherein sorting the first-generation preliminary population by using the crowding degree comparison operator comprises:
    对于所述第一代预备种群中的两个测试用例序列i和j,当测试用例序列i所处的外部非支配解集次序优于测试用例序列j所处的外部非支配解集时,测试用例序列i的排序优于测试用例序列j;或For the two test case sequences i and j in the first-generation preliminary population, when the outer non-dominated solution set where the test case sequence i is located is better than the outer non-dominated solution set where the test case sequence j is located, the test Case sequence i is ranked better than test case sequence j; or
    当测试用例序列i和测试用例序列j所处的外部非支配解集相同且测试用例序列i的拥挤度大于测试用例序列j的拥挤度时,测试用例序列i的排序优于测试用例序列j。When test case sequence i and test case sequence j are in the same external non-dominated solution set and the crowding degree of test case sequence i is greater than that of test case sequence j, the ordering of test case sequence i is better than that of test case sequence j.
  9. 根据权利要求2所述的测试用例排序方法,其中,使用所述改进变异算子根据第一规模的第g代测试用例序列种群得到第一规模的第g+1代测试用例序列种群包括:The test case sorting method according to claim 2, wherein using the improved mutation operator to obtain the first-scale g+1-th generation test case sequence population according to the first-scale g-th generation test case sequence population comprises:
    设定gen1,其中,1<gen1<n/2,设定gen2,其中,gen1<gen2<n,n为所述第一规模;Set gen1, where 1<gen1<n/2, set gen2, where gen1<gen2<n, n is the first scale;
    设定所述第g代测试用例序列种群中测试用例序列的高位区为[0,length/3],测试用例序列的中位区为(length/3,length*2/3],测试用例序列的低位区为(length*2/3,length],length为所述测试用例序列的长度;Set the high-order region of the test case sequence in the g-th generation test case sequence population as [0, length/3], the median region of the test case sequence as (length/3, length*2/3], and the test case sequence The low-order area of is (length*2/3, length], and length is the length of the test case sequence;
    当1≤g<gen1时,随机选择所述第g代测试用例序列种群中的至少一个测试用例序列,对所述至少一个测试用例序列中的每个测试用例序列,随机选择所述每个测试用例序列的高位区的任意两个基因位,将所述两个基因位的值进行交换;When 1≤g<gen1, randomly select at least one test case sequence in the g-th generation test case sequence population, and randomly select each test case sequence in the at least one test case sequence Use any two loci in the high-order region of the case sequence, and exchange the values of the two loci;
    当gen1≤g<gen2时,随机选择所述第g代测试用例序列种群中的至少一个测试用例序列,对所述至少一个测试用例序列中的每个测试用例序列,随机选择所述每个测试用例序列的中位区的任意两个基因位,将所述两个基因位的值进行交换;When gen1≤g<gen2, randomly select at least one test case sequence in the g-th generation test case sequence population, and randomly select each test case sequence in the at least one test case sequence Using any two loci in the median region of the case sequence, the values of the two loci are exchanged;
    当gen2≤g<n时,随机选择所述第g代测试用例序列种群中的至少一个测试用例序列,对所述至少一个测试用例序列中的每个测试用例序列,随机选择所述每个测试用例序列的低位区的任意两个基因位,将所述两个基因位的值进行交换。When gen2≤g<n, randomly select at least one test case sequence in the g-th generation test case sequence population, and randomly select each test case sequence in the at least one test case sequence Using any two loci in the lower region of the case sequence, the values of the two loci are exchanged.
  10. 一种电子设备,其中,所述电子设备包括处理器和存储器,所述处理器用于执行存储器中存储的至少一个计算机可读指令以实现以下步骤:An electronic device, wherein the electronic device includes a processor and a memory, and the processor is configured to execute at least one computer-readable instruction stored in the memory to implement the following steps:
    获取测试用例集,对所述测试用例集中的测试用例按随机顺序进行排列得到第一规模测试用例序列,将所述第一规模测试用例序列作为初代测试用例序列种群;Obtaining a test case set, arranging the test cases in the test case set in random order to obtain a first-scale test case sequence, and using the first-scale test case sequence as a population of first-generation test case sequences;
    对所述初代测试用例序列种群中的每个测试用例序列进行二进制编码;performing binary coding on each test case sequence in the primary test case sequence population;
    使用选择函数对经过二进制编码的所述初代测试用例序列种群进行评价得到测试用例序列的评价值,根据每个测试用例序列的评价值对所述初代测试用例序列种群进行无回放随机选择,并使用单点交叉算子和/或序号变异算子对无回放随机选择得到的测试用例序列进行计算得到第一代子代测试用例序列种群,合并所述第一代子代测试用例序列种群与所述初代测试用例序列种群得到第二规模的第一代测试用例序列合并种群;Use a selection function to evaluate the binary-coded primary test case sequence population to obtain the evaluation value of the test case sequence, and perform random selection without playback on the primary test case sequence population according to the evaluation value of each test case sequence, and use The single-point crossover operator and/or the sequence number mutation operator calculates the test case sequence obtained by random selection without playback to obtain the first-generation progeny test case sequence population, and combines the first-generation progeny test case sequence population with the The first-generation test case sequence population obtains the second-scale first-generation test case sequence merged population;
    对所述第一代测试用例序列合并种群进行非支配排序,计算所述第一代测试用例序列合并种群的拥挤度,并根据所述拥挤度使用拥挤度比较算子对所述第一代测试用例序列合并种群进行计算得到第一规模的第一代测试用例序列种群,并令迭代次数g=1;Perform non-dominated sorting on the combined population of the first-generation test case sequences, calculate the crowding degree of the combined population of the first-generation test case sequences, and use a crowding degree comparison operator to test the first generation according to the crowding degree The use case sequence is combined with the population for calculation to obtain the first-generation test case sequence population of the first scale, and the number of iterations g=1;
    对所述第一代测试用例序列种群执行预设操作直至g等于预设阈值,将第g代测试用例序列种群作为最优解集,输出所述最优解集。A preset operation is performed on the first-generation test case sequence population until g is equal to a preset threshold, and the g-th generation test case sequence population is used as the optimal solution set, and the optimal solution set is output.
  11. 根据权利要求10所述的电子设备,其中,在所述执行预设操作时,所述处理器执行所述至少一个计算机可读指令以实现以下步骤:The electronic device of claim 10, wherein, when performing the preset operation, the processor executes the at least one computer-readable instruction to implement the following steps:
    使用选择函数对第g代测试用例序列种群进行评价得到测试用例序列的评价值,根据每个测试用例序列的评价值对所述第g代测试用例序列种群进行无回放随机选择,并使用单点交叉算子和/或改进变异算子对无回放随机选择得到的测试用例序列进行计算得到第g+1代子代测试用例序列种群;Use the selection function to evaluate the g-th generation test case sequence population to obtain the evaluation value of the test case sequence, and perform random selection without playback on the g-th generation test case sequence population according to the evaluation value of each test case sequence, and use a single point The crossover operator and/or the improved mutation operator calculate the test case sequence obtained by random selection without playback to obtain the g+1 generation offspring test case sequence population;
    合并所述第g代测试用例序列种群和所述第g+1代子代测试用例序列种群得到第二规模的第g+1代测试用例序列合并种群;combining the g-th generation test case sequence population and the g+1-th generation progeny test case sequence population to obtain a second-scale combined population of the g+1-th generation test case sequence;
    对所述第g+1代测试用例序列合并种群进行非支配排序;Perform non-dominated sorting on the combined population of the g+1 generation test case sequence;
    计算所述第g+1代测试用例序列合并种群的拥挤度;Calculate the crowding degree of the combined population of the g+1 generation test case sequence;
    根据所述第g+1代测试用例序列合并种群的拥挤度使用拥挤度比较算子得到第一规模的第g+1代测试用例序列种群,令迭代次数g=g+1。According to the crowding degree of the combined population of the test case sequence of the g+1 generation, the crowding degree comparison operator is used to obtain the test case sequence population of the g+1 generation of the first scale, and the number of iterations is g=g+1.
  12. 根据权利要求10所述的电子设备,其中,在所述根据每个测试用例序列的评价值对所述初代测试用例序列种群进行无回放随机选择,并使用单点交叉算子和/或序号变异算子对无回放随机选择得到的测试用例序列进行计算得到第一代子代测试用例序列种群时,所述处理器执行所述至少一个计算机可读指令以实现以下步骤:The electronic device according to claim 10, wherein in the said first-generation test case sequence population is randomly selected without playback according to the evaluation value of each test case sequence, and a single-point crossover operator and/or sequence number mutation are used When the operator calculates the test case sequence obtained by random selection without replay to obtain the population of the first-generation progeny test case sequence, the processor executes the at least one computer-readable instruction to realize the following steps:
    创建步骤,创建所述第一代子代测试用例序列种群;The creating step is to create the first-generation progeny test case sequence population;
    随机选择步骤,根据每个测试用例序列的评价值对所述初代测试用例序列种群进行无回放随机选择得到初始资源池;In the random selection step, according to the evaluation value of each test case sequence, the initial resource pool is obtained by randomly selecting the population of the first-generation test case sequence without playback;
    交叉变异步骤,使用所述单点交叉算子和/或所述序号变异算子对所述初始资源池中的测试用例序列进行交叉和变异,将经过交叉和变异的所述测试用例序列加入所述子代测试用例序列种群;The crossover mutation step is to use the single-point crossover operator and/or the sequence number mutation operator to crossover and mutate the test case sequence in the initial resource pool, and add the crossover and mutated test case sequence to the test case sequence. Describe the descendant test case sequence population;
    种群生成步骤,重复所述随机选择步骤与所述交叉变异步骤,直至所述子代测试用例序列种群规模为所述第一规模。In the population generation step, the random selection step and the crossover mutation step are repeated until the population size of the progeny test case sequence is the first size.
  13. 根据权利要求12所述的电子设备,其中,在使用所述序号变异算子对所述初始资源池中的测试用例序列进行变异时,所述处理器执行所述至少一个计算机可读指令以实现以下步骤:13. The electronic device of claim 12, wherein, when using the sequence number mutation operator to mutate the sequence of test cases in the initial resource pool, the processor executes the at least one computer-readable instruction to achieve The following steps:
    随机选择所述初始资源池中至少一个测试用例序列,对于所述至少一个测试用例序列中的每个测试用例序列,随机选择所述测试用例序列上的两个基因位,交换两个所述基因位对应的测试用例。Randomly select at least one test case sequence in the initial resource pool, for each test case sequence in the at least one test case sequence, randomly select two loci on the test case sequence, and exchange two of the genes Bit corresponding to the test case.
  14. 根据权利要求10所述的电子设备,其中,在所述对所述第一代测试用例序列合并种群进行非支配排序时,所述处理器执行所述至少一个计算机可读指令以实现以下步骤:11. The electronic device of claim 10, wherein, in the non-dominated sorting of the first generation test case sequence pooled population, the processor executes the at least one computer-readable instruction to implement the following steps:
    计算步骤,计算所述种群中的所有测试用例序列的故障检测率、语句覆盖率和有效执行时间,并将所述故障检测率、所述语句覆盖率和所述有效执行时间作为排序目标函数,得到三个由目标函数值组成的数组;The calculation step is to calculate the fault detection rate, statement coverage rate and effective execution time of all test case sequences in the population, and use the fault detection rate, the statement coverage rate and the effective execution time as a sorting objective function, Get three arrays of objective function values;
    排序步骤,创建外部非支配解集,以最大化所述故障检测率、最大化所述语句覆盖率、最小化所述有效执行时间为目标,根据所述三个由目标函数值组成的数组,得到成对的非支配解,将所述成对的非支配解加入所述外部非支配解集,两两比较所述外部非支配解集中的测试用例序列,去除不是非支配解的解,使得所述外部非支配解集中的测试用例序列两两互为非支配解,其中,所述非支配解为非支配关系的测试用例序列;A sorting step, creating an external non-dominated solution set, with the goal of maximizing the fault detection rate, maximizing the statement coverage, and minimizing the effective execution time, according to the three arrays consisting of objective function values, Obtain paired non-dominated solutions, add the paired non-dominated solutions to the external non-dominated solution set, compare the test case sequences in the external non-dominated solution set pairwise, and remove the solutions that are not non-dominated solutions, so that The test case sequences in the external non-dominated solution set are mutually non-dominated solutions, wherein the non-dominated solutions are test case sequences of non-dominated relationships;
    解集生成步骤,对所述第一代测试用例序列合并种群中除所述外部非支配解集中的测试用例序列外的所有测试用例序列执行所述计算步骤与所述排序步骤,得到非支配排序后的外部非支配解集系列,所述非支配排序后的外部非支配解集系列中排序在前的外部非支配解集中的任一测试用例的故障检测率大于排序在后的外部非支配解集中的所有测试用例的故障检测率,且所述非支配排序后的外部非支配解集系列中排序在前的外部非支配解集中的任一测试用例的语句覆盖率大于排序在后的外部非支配解集中的所有测试用例的语句覆盖率,且所述非支配排序后的外部非支配解集系列中排序在前的外部非支配解集中的任一测试用例的有效执行时间小于排序在后的外部非支配解集中的所有测试用例。The solution set generation step is to perform the calculation step and the sorting step on all test case sequences in the merged population of the first-generation test case sequences except the test case sequences in the external non-dominated solution set, to obtain a non-dominated ranking The subsequent external non-dominated solution set series, the failure detection rate of any test case in the external non-dominated solution set ranked first in the non-dominated sorted external non-dominated solution set series is greater than that of the external non-dominated solution set after the ranking. The failure detection rate of all test cases in the set, and the statement coverage rate of any test case in the external non-dominated solution set ranked first in the external non-dominated solution set series after the non-dominated sorting is greater than that of the external non-dominated solution set ranked last. The statement coverage of all test cases in the dominant solution set, and the effective execution time of any test case in the external non-dominated solution set ranked first in the non-dominated sorted external non-dominated solution set series is less than that of the later sorted external non-dominated solution set. All test cases in the outer non-dominated solution set.
  15. 根据权利要求10所述的电子设备,其中,在所述计算所述第一代测试用例序列合并种群的拥挤度时,所述处理器执行所述至少一个计算机可读指令以实现以下步骤:11. The electronic device of claim 10, wherein, in said calculating the crowding degree of said first generation test case sequence merged population, said processor executes said at least one computer-readable instruction to implement the following steps:
    令所述第一代测试用例序列合并种群中的测试用例序列t的拥挤度d t=0,其中,t表示测试用例序列,t=1,2,…,n; Let the crowding degree of the test case sequence t in the first-generation test case sequence merged population d t =0, where t represents the test case sequence, t=1, 2,...,n;
    对于每个目标函数f(x)进行如下操作:For each objective function f(x) do the following:
    基于所述目标函数f(x)对第一代测试用例序列合并种群中的测试用例序列进行单目标排序;Based on the objective function f(x), single-objective sorting is performed on the test case sequences in the merged population of the first-generation test case sequences;
    令边界的两个测试用例序列d 1、d n的拥挤度为无穷,即d 1=d n=∞; Let the crowding degree of the two test case sequences d 1 and d n be infinite, that is, d 1 =d n =∞;
    根据公式d t=d t+(f(t+1)-f(t-1))计算所述测试用例序列t的拥挤度,其中,t=2,3,…,n-1。 The crowding degree of the test case sequence t is calculated according to the formula d t =d t +(f(t+1)-f(t-1)), where t=2,3,...,n-1.
  16. 根据权利要求14所述的电子设备,其中,在所述根据所述拥挤度使用拥挤度比较算子对所述第一代测试用例序列合并种群进行计算得到第一规模的第一代测试用例序列种群时,所述处理器执行所述至少一个计算机可读指令以实现以下步骤:The electronic device according to claim 14, wherein a first-generation test case sequence of a first scale is obtained by calculating the merged population of the first-generation test case sequences using a crowding degree comparison operator according to the crowding degree. During the population, the processor executes the at least one computer-readable instruction to implement the following steps:
    创建第一代预备种群;Create a first-generation reserve population;
    将所述非支配排序后的外部非支配解集系列中的外部非支配解集按次序加入所述第一代预备种群,直至所述第一代预备种群规模大于或等于第一规模;或adding the external non-dominated solution sets in the non-dominated sorted external non-dominated solution set series to the first-generation preliminary population in order, until the first-generation preliminary population size is greater than or equal to the first size; or
    当所述第一代预备种群规模等于第一规模时,将所述第一代预备种群作为所述第一代测试用例序列种群;或When the size of the first-generation preliminary population is equal to the first size, use the first-generation preliminary population as the first-generation test case sequence population; or
    当所述第一代预备种群规模大于第一规模时,根据所述拥挤度使用所述拥挤度比较算子对所述第一代预备种群进行排序,得到第一规模的所述第一代测试用例序列种群。When the scale of the first-generation preliminary population is larger than the first scale, use the crowding degree comparison operator to sort the first-generation preliminary population according to the crowding degree to obtain the first-generation test of the first scale Use case sequence population.
  17. 根据权利要求16所述的电子设备,其中,在使用所述拥挤度比较算子对所述第一代预备种群进行排序时,所述处理器执行所述至少一个计算机可读指令以实现以下步骤:17. The electronic device of claim 16, wherein, in ordering the first generation preliminary population using the crowding comparison operator, the processor executes the at least one computer-readable instruction to implement the following steps :
    对于所述第一代预备种群中的两个测试用例序列i和j,当测试用例序列i所处的外部非支配解集次序优于测试用例序列j所处的外部非支配解集时,测试用例序列i的排序优于测试用例序列j;或For the two test case sequences i and j in the first-generation preliminary population, when the outer non-dominated solution set where the test case sequence i is located is better than the outer non-dominated solution set where the test case sequence j is located, the test Case sequence i is ranked better than test case sequence j; or
    当测试用例序列i和测试用例序列j所处的外部非支配解集相同且测试用例序列i的拥挤度大于测试用例序列j的拥挤度时,测试用例序列i的排序优于测试用例序列j。When test case sequence i and test case sequence j are in the same external non-dominated solution set and the crowding degree of test case sequence i is greater than that of test case sequence j, the ordering of test case sequence i is better than that of test case sequence j.
  18. 根据权利要求11所述的电子设备,其中,在使用所述改进变异算子根据第一规模的第g代测试用例序列种群得到第一规模的第g+1代测试用例序列种群时,所述处理器执行所述至少一个计算机可读指令以实现以下步骤:The electronic device according to claim 11, wherein when using the improved mutation operator to obtain the first-scale g+1-th generation test case sequence population according to the first-scale g-th generation test case sequence population, the The processor executes the at least one computer-readable instruction to implement the following steps:
    设定gen1,其中,1<gen1<n/2,设定gen2,其中,gen1<gen2<n,n为所述第一规模;Set gen1, where 1<gen1<n/2, set gen2, where gen1<gen2<n, n is the first scale;
    设定所述第g代测试用例序列种群中测试用例序列的高位区为[0,length/3],测试用例序列的中位区为(length/3,length*2/3],测试用例序列的低位区为(length*2/3,length],length为所述测试用例序列的长度;Set the high-order region of the test case sequence in the g-th generation test case sequence population as [0, length/3], the median region of the test case sequence as (length/3, length*2/3], and the test case sequence The low-order area of is (length*2/3, length], and length is the length of the test case sequence;
    当1≤g<gen1时,随机选择所述第g代测试用例序列种群中的至少一个测试用例序列,对所述至少一个测试用例序列中的每个测试用例序列,随机选择所述每个测试用例序列的高位区的任意两个基因位,将所述两个基因位的值进行交换;When 1≤g<gen1, randomly select at least one test case sequence in the g-th generation test case sequence population, and randomly select each test case sequence in the at least one test case sequence Use any two loci in the high-order region of the case sequence, and exchange the values of the two loci;
    当gen1≤g<gen2时,随机选择所述第g代测试用例序列种群中的至少一个测试用例序列,对所述至少一个测试用例序列中的每个测试用例序列,随机选择所述每个测试用例序列的中位区的任意两个基因位,将所述两个基因位的值进行交换;When gen1≤g<gen2, randomly select at least one test case sequence in the g-th generation test case sequence population, and randomly select each test case sequence in the at least one test case sequence Using any two loci in the median region of the case sequence, the values of the two loci are exchanged;
    当gen2≤g<n时,随机选择所述第g代测试用例序列种群中的至少一个测试用例序列,对所述至少一个测试用例序列中的每个测试用例序列,随机选择所述每个测试用例序列的低位区的任意两个基因位,将所述两个基因位的值进行交换。When gen2≤g<n, randomly select at least one test case sequence in the g-th generation test case sequence population, and randomly select each test case sequence in the at least one test case sequence Using any two loci in the lower region of the case sequence, the values of the two loci are exchanged.
  19. 一种计算机可读存储介质,其中,所述计算机可读存储介质存储有至少一个计算机可读指令,所述至少一个计算机可读指令被处理器执行时实现以下步骤:A computer-readable storage medium, wherein the computer-readable storage medium stores at least one computer-readable instruction, and the at least one computer-readable instruction implements the following steps when executed by a processor:
    获取测试用例集,对所述测试用例集中的测试用例按随机顺序进行排列得到第一规模测试用例序列,将所述第一规模测试用例序列作为初代测试用例序列种群;Obtaining a test case set, arranging the test cases in the test case set in random order to obtain a first-scale test case sequence, and using the first-scale test case sequence as a population of first-generation test case sequences;
    对所述初代测试用例序列种群中的每个测试用例序列进行二进制编码;performing binary coding on each test case sequence in the primary test case sequence population;
    使用选择函数对经过二进制编码的所述初代测试用例序列种群进行评价得到测试用例序列的评价值,根据每个测试用例序列的评价值对所述初代测试用例序列种群进行无回放随机选择,并使用单点交叉算子和/或序号变异算子对无回放随机选择得到的测试用例序列进行计算得到第一代子代测试用例序列种群,合并所述第一代子代测试用例序列种群与所述初代测试用例序列种群得到第二规模的第一代测试用例序列合并种群;Use a selection function to evaluate the binary-coded primary test case sequence population to obtain the evaluation value of the test case sequence, and perform random selection without playback on the primary test case sequence population according to the evaluation value of each test case sequence, and use The single-point crossover operator and/or the sequence number mutation operator calculates the test case sequence obtained by random selection without playback to obtain the first-generation progeny test case sequence population, and combines the first-generation progeny test case sequence population with the The first-generation test case sequence population obtains the second-scale first-generation test case sequence merged population;
    对所述第一代测试用例序列合并种群进行非支配排序,计算所述第一代测试用例序列合并种群的拥挤度,并根据所述拥挤度使用拥挤度比较算子对所述第一代测试用例序列合并种群进行计算得到第一规模的第一代测试用例序列种群,并令迭代次数g=1;Perform non-dominated sorting on the combined population of the first-generation test case sequences, calculate the crowding degree of the combined population of the first-generation test case sequences, and use a crowding degree comparison operator to test the first generation according to the crowding degree The use case sequence is combined with the population for calculation to obtain the first-generation test case sequence population of the first scale, and the number of iterations g=1;
    对所述第一代测试用例序列种群执行预设操作直至g等于预设阈值,将第g代测试用例序列种群作为最优解集,输出所述最优解集。A preset operation is performed on the first-generation test case sequence population until g is equal to a preset threshold, and the g-th generation test case sequence population is used as the optimal solution set, and the optimal solution set is output.
  20. 一种测试用例排序装置,其中,所述测试用例排序装置包括:An apparatus for sorting test cases, wherein the apparatus for sorting test cases includes:
    种群初始化模块,用于获取测试用例集,对所述测试用例集中的测试用例按随机顺序进行排列得到第一规模测试用例序列,将所述第一规模测试用例序列作为初代测试用例序列种群;a population initialization module, used for acquiring a test case set, arranging the test cases in the test case set in random order to obtain a first-scale test case sequence, and using the first-scale test case sequence as the first-generation test case sequence population;
    编码模块,用于对所述初代测试用例序列种群中的每个测试用例序列进行二进制编码;an encoding module, configured to perform binary encoding on each test case sequence in the primary test case sequence population;
    合并模块,用于使用选择函数对经过二进制编码的所述初代测试用例序列种群进行评价得到测试用例序列的评价值,根据每个测试用例序列的评价值对所述初代测试用例序列种群进行无回放随机选择,并使用单点交叉算子和/或序号变异算子对无回放随机选择得到的测试用例序列进行计算得到第一代子代测试用例序列种群,合并所述第一代子代测试用例序列种群与所述初代测试用例序列种群得到第二规模的第一代测试用例序列合并种群;The merging module is configured to use the selection function to evaluate the binary-coded population of the first-generation test case sequences to obtain the evaluation value of the test case sequence, and perform no playback on the population of the first-generation test case sequence according to the evaluation value of each test case sequence Randomly select, and use the single-point crossover operator and/or the sequence number mutation operator to calculate the test case sequence obtained by random selection without playback to obtain the first-generation progeny test case sequence population, and combine the first-generation progeny test cases. The sequence population and the first-generation test case sequence population obtain a second-scale first-generation test case sequence merged population;
    排序模块,用于对所述第一代测试用例序列合并种群进行非支配排序,计算所述第一代测试用例序列合并种群的拥挤度,并根据所述拥挤度使用拥挤度比较算子对所述第一代测试用例序列合并种群进行计算得到第一规模的第一代测试用例序列种群,并令迭代次数g=1;The sorting module is configured to perform non-dominated sorting on the combined population of the first-generation test case sequences, calculate the crowding degree of the combined population of the first-generation test case sequences, and use a crowding degree comparison operator to perform a sorting of all the combined populations according to the crowding degree. The first-generation test case sequence is combined with the population for calculation to obtain the first-scale first-generation test case sequence population, and the number of iterations g=1;
    输出模块,用于对所述第一代测试用例序列种群执行预设操作直至g等于预设阈值,将第g代测试用例序列种群作为最优解集,输出所述最优解集。The output module is configured to perform a preset operation on the first-generation test case sequence population until g is equal to a preset threshold value, take the g-th generation test case sequence population as the optimal solution set, and output the optimal solution set.
PCT/CN2021/109431 2020-12-24 2021-07-30 Test case sorting method and related device WO2022134581A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202011552451.8A CN112559374A (en) 2020-12-24 2020-12-24 Test case sequencing method and electronic equipment
CN202011552451.8 2020-12-24

Publications (1)

Publication Number Publication Date
WO2022134581A1 true WO2022134581A1 (en) 2022-06-30

Family

ID=75033702

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/109431 WO2022134581A1 (en) 2020-12-24 2021-07-30 Test case sorting method and related device

Country Status (2)

Country Link
CN (1) CN112559374A (en)
WO (1) WO2022134581A1 (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115442087A (en) * 2022-08-19 2022-12-06 中国人民解放军国防科技大学 Intelligent attack detection method and system based on DNA calculation
CN117522090A (en) * 2024-01-08 2024-02-06 佛山市达衍数据科技有限公司 Dynamic scheduling method, system and storage medium for clothing production
CN117632770B (en) * 2024-01-25 2024-04-19 江西财经大学 Multipath coverage test case generation method and system

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112559374A (en) * 2020-12-24 2021-03-26 深圳壹账通智能科技有限公司 Test case sequencing method and electronic equipment
CN113612758B (en) * 2021-07-29 2022-12-13 石家庄学院 Block chain-based Internet of things data security management system and method
CN115809202A (en) * 2023-01-04 2023-03-17 南京邮电大学 Test case priority ordering method facing parameter value switching

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103605611A (en) * 2013-12-10 2014-02-26 浪潮电子信息产业股份有限公司 Test case optimization method based on genetic algorithm
CN110059015A (en) * 2019-04-28 2019-07-26 西安邮电大学 Evolution of Population multiple target priorities of test cases sort method
CN111666209A (en) * 2020-05-20 2020-09-15 牡丹江师范学院 Multi-objective optimization-based test case priority ordering method
CN112559374A (en) * 2020-12-24 2021-03-26 深圳壹账通智能科技有限公司 Test case sequencing method and electronic equipment

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103605611A (en) * 2013-12-10 2014-02-26 浪潮电子信息产业股份有限公司 Test case optimization method based on genetic algorithm
CN110059015A (en) * 2019-04-28 2019-07-26 西安邮电大学 Evolution of Population multiple target priorities of test cases sort method
CN111666209A (en) * 2020-05-20 2020-09-15 牡丹江师范学院 Multi-objective optimization-based test case priority ordering method
CN112559374A (en) * 2020-12-24 2021-03-26 深圳壹账通智能科技有限公司 Test case sequencing method and electronic equipment

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
"Frontier Technologies Series in Artificial Intelligence: Concise Artificial Intelligence", 30 September 2019, XI'AN UNIVERSITY OF ELECTRONIC SCIENCE AND TECHNOLOGY, CN, ISBN: 978-7-5606-5345-7, article JIAO, LICHENG; LIU, RUOCHEN; MU, CAILONG: "NSGA-II Algorithm Flow", pages: 471 - 472, XP009538020 *
XIA CHUN-YAN: "Test Case Prioritization Based on Multi-objective Optimization", COMPUTER SCIENCE, vol. 47, no. 6, 15 June 2020 (2020-06-15), pages 38 - 43, XP055945027 *
ZHIHONG XU ; MYRA B. COHEN ; GREGG ROTHERMEL: "Factors affecting the use of genetic algorithms in test suite augmentation", GENETIC AND EVOLUTIONARY COMPUTATION, 7 July 2010 (2010-07-07) - 11 July 2010 (2010-07-11), 2 Penn Plaza, Suite 701 New York NY 10121-0701 USA , pages 1365 - 1372, XP058118097, ISBN: 978-1-4503-0072-8, DOI: 10.1145/1830483.1830734 *

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115442087A (en) * 2022-08-19 2022-12-06 中国人民解放军国防科技大学 Intelligent attack detection method and system based on DNA calculation
CN117522090A (en) * 2024-01-08 2024-02-06 佛山市达衍数据科技有限公司 Dynamic scheduling method, system and storage medium for clothing production
CN117632770B (en) * 2024-01-25 2024-04-19 江西财经大学 Multipath coverage test case generation method and system

Also Published As

Publication number Publication date
CN112559374A (en) 2021-03-26

Similar Documents

Publication Publication Date Title
WO2022134581A1 (en) Test case sorting method and related device
US11704586B2 (en) Systems and methods for analog processing of problem graphs having arbitrary size and/or connectivity
Shrikumar et al. Technical note on transcription factor motif discovery from importance scores (TF-MoDISco) version 0.5. 6.5
WO2020151129A1 (en) Quantum machine learning framework construction method and apparatus, and quantum computer and computer storage medium
WO2020253466A1 (en) Method and device for generating test case of user interface
US10885439B1 (en) Automated neural network generation using fitness estimation
CN112037912A (en) Triage model training method, device and equipment based on medical knowledge map
US20210150412A1 (en) Systems and methods for automated machine learning
CN110633786A (en) Techniques for determining artificial neural network topology
CN109783213B (en) Workflow fault tolerance scheduling method for reliability in edge computing environment
WO2021238563A1 (en) Enterprise operation data analysis method and apparatus based on configuration algorithm, and electronic device and medium
US20150170052A1 (en) Method of reducing resource fluctuations in resource leveling
Statnikov et al. Ultra-scalable and efficient methods for hybrid observational and experimental local causal pathway discovery
WO2021139432A1 (en) Artificial intelligence-based user rating prediction method and apparatus, terminal, and medium
Wang et al. An order-based estimation of distribution algorithm for stochastic hybrid flow-shop scheduling problem
Mishra et al. A review of random test case generation using genetic algorithm
CN112598089B (en) Image sample screening method, device, equipment and medium
Jeng et al. Efficient signal inclusion with genomic applications
Santander‐Jiménez et al. A hybrid approach to parallelize a fast non‐dominated sorting genetic algorithm for phylogenetic inference
Andalon-Garcia et al. Performance comparison of three topologies of the island model of a parallel genetic algorithm implementation on a cluster platform
WO2021212753A1 (en) Computer performance data determining method and apparatus, computer device, and storage medium
Adi et al. Parallel evolutionary algorithms for feature selection in high dimensional datasets
Anunciação et al. Using information interaction to discover epistatic effects in complex diseases
US20210287131A1 (en) Machine learning model accuracy fairness
CN112668788A (en) User scoring model training method based on deep learning and related equipment

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21908586

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 30.10.2023)