Training and/or using machine learning model(s) for automatic generation of test case(s) for source code
AssigneeGoogle Inc.
InventorsRishabh Singh, David Andre
Life of this patent
Estimating the term…
Abstract
Training and/or utilization of machine learning model(s) (e.g., neural network model(s)) in automatically generating test case(s) for source code. Techniques disclosed herein can be utilized in generating test case(s) for unit test testing (or other white-box testing) and/or for functional testing (or other black-box testing). In some implementations, the machine learning model(s) can be trained on source code, unit test pairs. In some additional or alternative implementations, reinforcement learning techniques can be utilized to check for correctness of base source code, target source code pairs (e.g., by matching program execution of different branches).
Claims19
A method implemented by one or more processors, the method comprising:
- identifying a plurality of ground truth source code, unit test pairs each including a corresponding ground truth source code unit, and a corresponding ground truth unit test for the ground truth source code unit;
- for each of the ground truth source code, unit test pairs:
- processing the corresponding ground truth source code unit, using a code-to-embedding machine learning model, to generate one or more corresponding code unit embeddings;
- processing the corresponding ground truth unit test, using the code-to-embedding machine learning model, to generate one or more corresponding unit test embeddings;
- and
- generating a corresponding positive training instance that includes:
- the one or more corresponding code unit embeddings as input, and
- the one or more corresponding unit test embeddings as output;
- for each of the corresponding positive training instances:
- processing the corresponding one or more code unit embeddings of the input, using a code embedding-to-test embedding machine learning model, to generate one or more predicted unit test embeddings;
- and
- generating a corresponding error based on comparing the one or more predicted unit test embeddings to the one or more corresponding unit test embeddings of the output;
- and
- training the code embedding-to-test embedding machine learning model based on the corresponding errors.
A method implemented by one or more processors, the method comprising:
- identifying base source code that is programmed in a base programming language;
- identifying target source code that is in a target programming language and that is generated based on automatically translating the base source code;
- processing the base source code, using a code-to-embedding machine learning model, to generate a base source code embedding in a latent space;
- processing the target source code, using the code-to-embedding machine learning model, to generate a target source code embedding in the latent space;
- processing, using a policy network, the base source code embedding and the target source code embedding, to generate a predicted test input;
- executing the base source code using the predicted test input to generate a base output;
- executing the target source code using the predicted test input to generate a target output;
- generating a reward based on comparing the base output to the target output,
- wherein the reward is more positive when the comparing indicates the base output and the target output are not equal than when the comparing indicates the base output and the target output are equal;
- and
- updating the policy network based on the reward.
Dependencies are inferred from the claim text.