Software test data generation method and system

Through the mutual adversarial mechanism of the generator and discriminator of the adversarial network, the real data distribution is automatically learned and simulated, which solves the problem that traditional software testing methods are difficult to generate high-quality test data, and realizes efficient and diversified test data generation.

CN119166503APending Publication Date: 2024-12-20SHENZHEN WEIYAN TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411180727.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-26
Publication Date
2024-12-20

AI Technical Summary

Technical Problem

Traditional software testing methods rely on manual writing of test cases, making it difficult to fully cover all possible scenarios and boundary conditions, resulting in inefficient test data and difficult to simulate real data distribution.

Method used

Adversarial network is adopted to automatically learn and simulate the distribution of real data through the mutual adversarial mechanism of the generator and the discriminator, and finely regulate the characteristics of the generated data using multiple loss functions to generate high-quality and diverse test data samples.

Benefits of technology

It realizes the generation of high-quality test data closer to the real data distribution, improves the accuracy and diversity of test data, and meets the needs of software testing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119166503A_ABST
    Figure CN119166503A_ABST
Patent Text Reader

Abstract

The invention discloses a software test data generation method and system, and belongs to the technical field of computers. According to the method, a mutual confrontation mechanism of the generator and the discriminator is constructed, the complex distribution of real data is automatically learned and simulated, the discriminator provides feedback by distinguishing the real data and the generated data, the generator is helped to continuously optimize the output of the discriminator, and therefore high-quality test data closer to the real data distribution is generated; and accurate and diversified test data samples are generated in real time. Meanwhile, the generator objective function constructed by the method integrates various loss functions to finely regulate and control the characteristics of the generated data, and it is ensured that the test requirements can be met in the aspects of accuracy, similarity, diversity and the like. According to the method, the capability of quickly generating the high-quality test data from the test data feature vector and the random noise vector which are acquired in real time is realized, and a flexible, efficient and reliable solution is provided for the field of software testing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and more particularly to a method and system for generating software test data. Background Art

[0002] As software systems become increasingly complex and functionally diverse, software testing plays a vital role in ensuring software quality and reliability. At the same time, with the rapid development of big data and artificial intelligence technologies, the amount of data that software systems need to process has increased dramatically, and the diversity and complexity of data have also increased significantly, which has posed higher challenges to software testing.

[0003] In software testing, the generation of test data is a key link. High-quality test data can simulate various situations in the real world and help discover potential defects and errors. However, traditional software testing methods mainly rely on manually written test cases, which are often based on the experience and intuition of testers and are difficult to fully cover all possible scenarios and boundary conditions. The software test data obtained based on this method has many limitations, such as difficulty in simulating the distribution of real data and low efficiency.

[0004] Therefore, how to propose a software test data generation method and system to ensure the quality of software test data is a problem that technical personnel in this field need to solve urgently. Summary of the invention

[0005] In view of this, the present invention provides a software test data generation method and system, which realizes a more intelligent, efficient and flexible test data generation strategy.

[0006] In order to achieve the above object, the present invention adopts the following technical solution:

[0007] In one aspect, the present invention provides a method for generating software test data, comprising the following steps:

[0008] Constructing an adversarial network, the adversarial network comprising a generator and a discriminator; using a test data feature vector and a random noise vector as inputs of the generator, and outputting a test data sample; using the test data sample and a real data sample as inputs of the discriminator;

[0009] Construct the generator objective function and the discriminator objective function, and construct the adversarial network objective function based on the generator objective function and the discriminator objective function;

[0010] Training the adversarial network according to the adversarial network objective function to obtain an optimized model;

[0011] The test data feature vector and random noise vector collected in real time are input into the optimization model, and the software test data is output.

[0012] Preferably, the generator objective function L G as follows:

[0013] L G =-E z~p(z) [logD(G(z,c))]+R(G(z,c));

[0014] Where D(·) is the discriminator; z is the noise vector sampled from the random noise distribution p(z); c is the test data feature vector; G(z,c) is the test data sample output by the generator; R(G(z,c)) is the loss term; and E is the expected value.

[0015] Preferably, the discriminator objective function L D as follows:

[0016]

[0017] In the formula, x is the distribution of real data p data The real data samples are sampled from .

[0018] Preferably, the adversarial network objective function L total as follows:

[0019]

[0020] In the formula, λ is a constant coefficient.

[0021] Preferably, the loss term R(G(z,c)) consists of reconstruction loss, diversity loss and feature loss.

[0022] Preferably, the formula of the loss term R(G(z,c)) is as follows:

[0023] R(G(z,c))=λ1L rec +λ2L div +λ3L con

[0024] Where, L rec To rebuild the losses; L div is the diversity loss; L feat is the feature loss; λ1, λ2, and λ3 are the weight parameters of reconstruction loss, diversity loss, and feature loss, respectively;

[0025] The reconstruction loss L rec The calculation formula is as follows:

[0026]

[0027] In the formula, x is the distribution of real data p dataReal data samples sampled in ;

[0028] The diversity loss L div The calculation formula is as follows:

[0029]

[0030] In the formula, z i ,z j represents different random noise vectors;

[0031] The feature loss L feat The calculation formula is as follows:

[0032]

[0033] Where f(·) is the feature extraction function and N is the dimension of the feature vector of the test data.

[0034] In another aspect, the present invention provides a software test data generation system, comprising:

[0035] An adversarial network construction module is used to construct an adversarial network, wherein the adversarial network includes a generator and a discriminator; the generator uses a test data feature vector and a random noise vector as inputs, and outputs a test data sample; and the test data sample and a real data sample are used as inputs of the discriminator;

[0036] An objective function construction module is used to construct a generator objective function and a discriminator objective function, and to construct an adversarial network objective function based on the generator objective function and the discriminator objective function;

[0037] A training module, used for training the adversarial network according to the adversarial network objective function to obtain an optimized model;

[0038] The data output module is used to input the test data feature vector and random noise vector collected in real time into the optimization model and output software test data.

[0039] Through the above technical solutions, it can be known that compared with the prior art, the present invention discloses a method and system for generating software test data, which automatically learns and simulates the complex distribution of real data by constructing a mutual confrontation mechanism between the generator and the discriminator. The discriminator provides feedback by distinguishing between real data and generated data, helping the generator to continuously optimize its output, thereby generating high-quality test data that is closer to the distribution of real data, and generating accurate and diverse test data samples in real time. At the same time, the generator objective function constructed by the present invention integrates multiple loss functions to finely control the characteristics of the generated data, ensuring that it can meet the test requirements in terms of accuracy, similarity and diversity. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0041] Figure 1 A flow chart of the method provided by the present invention;

[0042] Figure 2 This is a system architecture diagram provided by the present invention. DETAILED DESCRIPTION

[0043] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0044] On the one hand, the embodiment of the present invention provides a method for generating software test data, referring to Figure 1 , the method comprises the following steps:

[0045] S1. Construct an adversarial network, which includes a generator and a discriminator. The generator uses the test data feature vector and the random noise vector as input and outputs the test data sample. The discriminator uses the test data sample and the real data sample as input.

[0046] The adversarial network consists of two parts: the generator and the discriminator. The generator and the discriminator can be regarded as the two sides of the game. The test data feature vector combined with the random noise vector is used as input. The generator randomly generates a test data sample. The discriminator distinguishes between real real data samples and fake test data samples, and uses the judgment results of fake test data samples to adjust the generator, thereby improving the quality of the test data samples generated by the generator. In other words, the generator continuously generates more realistic test data samples, making it difficult for the discriminator to distinguish whether it is a real data sample or a fake test data sample.

[0047] In this embodiment, the test data feature vector is a vector composed of a set of feature values ​​extracted from samples in the collected test data set. These features can be numerical, categorical or other types of data, used to describe the attributes or characteristics of data points.

[0048] S2. Construct the generator objective function and the discriminator objective function, and construct the adversarial network objective function based on the generator objective function and the discriminator objective function.

[0049] Specifically, the generator objective function L G as follows:

[0050] L G =-E z~p(z) [logD(G(z,c))]+R(G(z,c));

[0051] Where D(·) is the discriminator; z is the noise vector sampled from the random noise distribution p(z); c is the test data feature vector; G(z,c) is the test data sample output by the generator; R(G(z,c)) is the loss term; and E is the expected value.

[0052] Furthermore, the loss term R(G(z,c)) is composed of reconstruction loss, diversity loss and feature loss. The formula of the loss term R(G(z,c)) is as follows:

[0053] R(G(z,c))=λ1L rec +λ2L div +λ3L con ;

[0054] Where, L rec To rebuild the losses; L div is the diversity loss; L feat is the feature loss; λ1, λ2, and λ3 are the weight parameters of reconstruction loss, diversity loss, and feature loss, respectively;

[0055] Reconstruction loss L rec The calculation formula is as follows:

[0056]

[0057] In the formula, x is the distribution of real data p data Real data samples sampled in ;

[0058] Diversity loss L div The calculation formula is as follows:

[0059]

[0060] In the formula, z i ,z j represents different random noise vectors;

[0061] Feature loss L feat The calculation formula is as follows:

[0062]

[0063] Where f(·) is the feature extraction function, which can be any function that can map the input to the feature space (for example, part of a pre-trained neural network); N is the dimension of the test data feature vector.

[0064] In addition, the discriminator objective function L D as follows:

[0065]

[0066] In the formula, x is the distribution of real data p data The real data samples are sampled from .

[0067] The generator G tries to minimize the objective function, and the discriminator D tries to maximize the objective function. This is a maximum-minimum optimization problem. D(G(z,c)) and D(x) represent the probabilities of the generated test data samples and the real data samples judged by the discriminator, respectively. The Adam optimization algorithm is used to optimize D first and then G, which is

[0068] Construct the adversarial network objective function L according to the generator objective function and the discriminator objective function total as follows:

[0069]

[0070] In the formula, λ is a constant coefficient.

[0071] S3. Train the adversarial network according to the adversarial network objective function to obtain an optimized model. The specific process is as follows:

[0072] First, train the discriminator:

[0073] After the generator is built, since the generator has not yet completed training, based on the input test data feature vector and random noise vector, a bunch of test data sample sets that can be easily identified as false by the discriminator will be obtained.

[0074] According to the fake test data sample set and the collected real data sample set, labels of the real and fake sample sets are artificially defined. In this embodiment, the class label of the real data sample set is 1 by default, while the class label of the fake test data sample set is 0.

[0075] Now we have the real data sample set and its class labels (all 1), the fake test data sample set and its class labels (all 0). At this point, for the discriminator alone, the problem becomes a supervised binary classification problem, which can be directly put into the convolutional neural network for training.

[0076] For training the generator:

[0077] The purpose of training the generator is to generate test data samples that are as realistic as possible. The authenticity of the samples generated by the original generator can only be known through the discriminator, so when training the generator, the discriminator network needs to be combined to achieve the purpose of training.

[0078] After generating fake test data samples (fake samples) through the test data feature vector and the random noise vector, the class labels of these fake test data samples are all set to 1, that is, these fake test data samples are considered to be true samples (real data samples) when the generator is trained. Because the error is generated by the discriminator at this time, and the purpose of error feedback is to make the fake test data samples generated by the generator gradually approach the real data samples (when the fake sample is not real, but the class label is 1, the error given by the discriminator will be very large, which forces the generator to make a lot of adjustments; conversely, when the fake sample is real enough and the class label is 1, the error given by the discriminator will decrease, which completes the process of the fake sample gradually approaching the real sample), which serves the purpose of confusing the discriminator.

[0079] The generator is trained based on the sample set (only fake test data sample set, no real data sample set), the corresponding class label (all 1) and the error.

[0080] During training, the parameters of the discriminator are fixed, and the discriminator is simply allowed to pass the error to the generator to update the parameters of the generator.

[0081] After the generator is trained, new test data samples can be generated based on the updated generator. If nothing unexpected happens, the test data samples generated this time will be more realistic. With a new set of test data samples, the above process can be repeated, training the generator and the discriminator alternately. Set a certain number of iterations, and stop the alternating iterations when a certain number of iterations are reached. At this time, the test data corresponding to a certain test data feature vector will be very realistic.

[0082] The training process in this step is implemented based on the various objective functions constructed in S2.

[0083] S4. Input the test data feature vector and random noise vector collected in real time into the optimization model and output the software test data.

[0084] On the other hand, the embodiment of the present invention also provides a software test data generation system, such as Figure 2 As shown, the system includes:

[0085] The adversarial network building module is used to build an adversarial network, which includes a generator and a discriminator. The generator uses a test data feature vector and a random noise vector as inputs and outputs a test data sample. The discriminator uses a test data sample and a real data sample as inputs.

[0086] An objective function construction module is used to construct a generator objective function and a discriminator objective function, and to construct an adversarial network objective function based on the generator objective function and the discriminator objective function;

[0087] A training module is used to train the adversarial network according to the adversarial network objective function to obtain an optimized model;

[0088] The data output module is used to input the test data feature vector and random noise vector collected in real time into the optimization model and output the software test data.

[0089] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.

[0090] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for generating software test data, It is characterized in that The following steps are involved: Constructing an adversarial network, the adversarial network comprising a generator and a discriminator; using a test data feature vector and a random noise vector as inputs of the generator, and outputting a test data sample; using the test data sample and a real data sample as inputs of the discriminator; Construct the generator objective function and the discriminator objective function, and construct the adversarial network objective function based on the generator objective function and the discriminator objective function; Training the adversarial network according to the adversarial network objective function to obtain an optimized model; The test data feature vector and random noise vector collected in real time are input into the optimization model, and the software test data is output.

2. A method for generating software test data according to claim 1, It is characterized in that The generator objective function L G as follows: L G =-E z~p(z) [logD(G(z,c))]+R(G(z,c)); Where D(·) is the discriminator; z is the noise vector sampled from the random noise distribution p(z); c is the test data feature vector; G(z,c) is the test data sample output by the generator; R(G(z,c)) is the loss term; and E is the expected value.

3. A method for generating software test data according to claim 2, It is characterized in that The discriminator objective function L D as follows: In the formula, x is the distribution of real data p data The real data samples are sampled from .

4. A method for generating software test data according to claim 3, It is characterized in that The adversarial network objective function L total as follows: In the formula, λ is a constant coefficient.

5. A method for generating software test data according to claim 2, It is characterized in that The loss term R(G(z,c)) consists of reconstruction loss, diversity loss and feature loss.

6. A method for generating software test data according to claim 5, It is characterized in that The formula of the loss term R(G(z,c)) is as follows: R(G(z,c))=λ 1 L rec +λ 2 L div +λ 3 L con Where, L rec To rebuild the losses; L div is the diversity loss; L feat is the feature loss; 1 , 2 , 3 are the weight parameters of reconstruction loss, diversity loss and feature loss respectively; The reconstruction loss L rec The calculation formula is as follows: In the formula, x is the distribution of real data p data Real data samples sampled in ; The diversity loss L div The calculation formula is as follows: In the formula, z i ,z j represents different random noise vectors; The feature loss L feat The calculation formula is as follows: Where f(·) is the feature extraction function and N is the dimension of the feature vector of the test data.

7. A software test data generation system, It is characterized in that include: An adversarial network building module, used to build an adversarial network, wherein the adversarial network includes a generator and a discriminator; Using a test data feature vector and a random noise vector as inputs of a generator, and outputting a test data sample; using the test data sample and a real data sample as inputs of a discriminator; An objective function construction module is used to construct a generator objective function and a discriminator objective function, and to construct an adversarial network objective function based on the generator objective function and the discriminator objective function; A training module, used for training the adversarial network according to the adversarial network objective function to obtain an optimized model; The data output module is used to input the test data feature vector and random noise vector collected in real time into the optimization model and output software test data.

Citation Information

Cited By

  • Large model construction method and device for basic software testing

    CN121029628A