IP Library Granted Patent US 12,625,794
Granted Patent B1
US 12,625,794 · App. 18/424,569 · Granted May 12, 2026

Training and/or using machine learning model(s) for automatic generation of test case(s) for source code

Inventors: Rishabh Singh (San Jose, CA); David Andre (San Francisco, CA)
Assignee: GOOGLE LLC
G06F11/3684G06F11/3688G06N5/04G06N20/00
View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 12,625,794
App. No.
18/424,569
Granted
May 12, 2026
Kind
B1
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).

Claims (61)

1 . A method implemented by one or more processors, the method comprising:

identifying a source code unit that is programmed in a programming language; processing the source code unit, using a code-to-embedding machine learning model, to generate one or more code unit embeddings in a latent space;

processing the one or more code unit embeddings, using a code embedding-to-test embedding machine learning model, to generate one or more predicted unit test embeddings in the latent space;

using the one or more predicted unit test embeddings to identify a unit test for the source code unit; and

evaluating the source code unit using at least the unit test, wherein evaluating the source code unit using at least the unit test comprises:

executing the source code unit, using test inputs of the unit test, to generate source code unit output, and

evaluating the source code unit based on the source code unit output.

2 . The method of claim 1 , wherein using the one or more predicted unit test embeddings to identify the unit test for the source code unit comprises:

processing the one or more predicted unit test embeddings, using an embedding-to-code machine learning model, to generate the unit test for the source code unit.

3 . The method of claim 2 , wherein processing the one or more predicted unit test embeddings, using the embedding-to-code machine learning model, to generate the unit test for the source code unit comprises:

generating a sequence of outputs based on processing the one or more predicted unit test embeddings using the embedding-to-code machine learning model, wherein the outputs of the sequence each comprise a corresponding probability distribution; and

generating the unit test based on highest probabilities in the corresponding probability distributions of the sequence of outputs.

4 . The method of claim 1 , wherein using the one or more predicted unit test embeddings to identify the unit test for the source code unit comprises:

determining that the one or more predicted unit test embeddings satisfy a distance threshold relative to one or more pre-generated unit test embeddings for the unit test, wherein the one or more pre-generated unit test embeddings are generated by processing the unit test using the code-to-embedding machine learning model; and

responsive to determining that the one or more predicted unit test embeddings satisfy the distance threshold relative to the one or more pre-generated unit test embeddings for the unit test:

identifying the unit test.

5 . The method of claim 1 , further comprising:

determining, based on the evaluating, to deploy the source code unit in production.

6 . The method of claim 1 , further comprising:

causing rendering, in a development application, of one or more metrics that are based on the evaluating.

7 . The method of claim 1 , wherein the source code unit is in a second programming language and is an automated translation of a corresponding source code unit in a first programming language that is different from the second programming language, and further comprising:

determining, based on the evaluating, whether to render the source code unit in a development application as a suggested translation of the corresponding source code unit.

8 . The method of claim 1 , wherein the source code unit is one of multiple candidate automated translations of the corresponding source code unit and wherein determining, based on the evaluating, whether to render the source code unit in the development application as the suggested translation comprises:

determining, based on the evaluating, whether to render the source code unit, or an alternate one of the automated translations, as a suggested translation of the corresponding source code unit.

9 . The method of claim 1 , wherein the code embedding-to-test embedding machine learning model is a transformer neural network model or an encoder-decoder neural network model.

10 . 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; and

determining, based on comparing the base output and the target output, whether one or more branches of the target source code are a valid translation of the base source code.

11 . The method of claim 10 , wherein determining, based on comparing the base output and the target output, whether one or more branches of the target source code are a valid translation of the base source code, comprises:

determining, based on the base output and the target output not being equal, that at least a given branch, involved in executing the target source code, is not a valid translation.

12 . The method of claim 11 , further comprising:

responsive to determining that at least the given branch, involved in executing the target source code, is not a valid translation:

causing the given branch to be rendered, in a development application, with a particular demarcation.

13 . The method of claim 10 , wherein the policy network is trained, through reinforcement learning, to reward predictions of test inputs that result in differing outputs when used in testing a base source code, target source code pair.

14 . The method of claim 10 , further comprising:

automatically translating the base source code to generate the target source code, wherein identifying the target source code is responsive to automatically translating the base source code to generate the target source code.

15 . A system, comprising:

memory storing instructions;

one or more processors operable to execute the instructions to:

identify a source code unit that is programmed in a programming language;

process the source code unit, using a code-to-embedding machine learning model, to generate one or more code unit embeddings in a latent space;

process the one or more code unit embeddings, using a code embedding-to-test embedding machine learning model, to generate one or more predicted unit test embeddings in the latent space;

use the one or more predicted unit test embeddings to identify a unit test for the source code unit; and

evaluate the source code unit using at least the unit test, wherein in evaluating the source code unit using at least the unit test one or more of the processors are to:

execute the source code unit, using test inputs of the unit test, to generate source code unit output, and

evaluate the source code unit based on the source code unit output.

16 . The system of claim 15 , wherein in using the one or more predicted unit test embeddings to identify the unit test for the source code unit one or more of the processors are to:

process the one or more predicted unit test embeddings, using an embedding-to-code machine learning model, to generate the unit test for the source code unit.

17 . The system of claim 16 , wherein in processing the one or more predicted unit test embeddings, using the embedding-to-code machine learning model, to generate the unit test for the source code unit one or more of the processors are to:

generate a sequence of outputs based on processing the one or more predicted unit test embeddings using the embedding-to-code machine learning model, wherein the outputs of the sequence each comprise a corresponding probability distribution; and

generate the unit test based on highest probabilities in the corresponding probability distributions of the sequence of outputs.

18 . The system of claim 15 , wherein one or more of the processors are further operable to execute the instructions to:

determine, based on the evaluating, to deploy the source code unit in production.

19 . The system of claim 15 , wherein one or more of the processors are further operable to execute the instructions to:

cause rendering, in a development application, of one or more metrics that are based on the evaluating.

Assignments (2)
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded May 10, 2024
From: SINGH, RISHABH; ANDRE, DAVID
To: X DEVELOPMENT LLC
Reel/Frame 067376/0742 →
NUNC PRO TUNC ASSIGNMENT Recorded Mar 6, 2024
From: X DEVELOPMENT LLC
To: GOOGLE LLC
Reel/Frame 066669/0491 →
Continuity (2)
Continuation 17318436 · May 12, 2021
Provisional Application 62704572 · May 15, 2020
References Cited (47)
US 4449189A · Feix et al. · 1984 [cited by applicant]
US 6111517A · Atick et al. · 2000 [cited by applicant]
US 9286899B1 · Narayanan · 2016 [cited by applicant]
US 20060261931A1 · Cheng · 2006 [cited by applicant]
US 20070172099A1 · Park et al. · 2007 [cited by applicant]
US 20130286161A1 · Lv et al. · 2013 [cited by applicant]
US 20140016835A1 · Song et al. · 2014 [cited by applicant]
US 20150095895A1 · Taneja · 2015 [cited by applicant]
US 20150162006A1 · Kummer · 2015 [cited by applicant]
US 20150242396A1 · Su · 2015 [cited by applicant]
US 20160179659A1 · Champlin-Scharff · 2016 [cited by examiner]
US 20160248768A1 · McLaren et al. · 2016 [cited by applicant]
US 20170110144A1 · Sharifi et al. · 2017 [cited by applicant]
US 20170169354A1 · Diamanti · 2017 [cited by examiner]
US 20170199998A1 · Bruno et al. · 2017 [cited by applicant]
US 20180357145A1 · Sarangapani · 2018 [cited by examiner]
US 20190004932A1 · Misra · 2019 [cited by examiner]
US 20190087311A1 · Donaldson · 2019 [cited by applicant]
US 20190108443A1 · Dwarakanath · 2019 [cited by examiner]
US 20190278894A1 · Andalo et al. · 2019 [cited by applicant]
US 20190342339A1 · Nanda et al. · 2019 [cited by applicant]
US 20190377736A1 · Balasubramanian · 2019 [cited by examiner]
US 20200019493A1 · Ramakrishna · 2020 [cited by examiner]
US 20200133662A1 · Smith · 2020 [cited by examiner]
US 20200183816A1 · Copty · 2020 [cited by examiner]
US 20200364507A1 · Berry · 2020 [cited by applicant]
US 20210283505A1 · Bansal · 2021 [cited by examiner]
US 20210303448A1 · Subramanian Rajalakshmi · 2021 [cited by examiner]
US 20220044119A1 · Wang · 2022 [cited by examiner]
US 20220276628A1 · Canedo · 2022 [cited by examiner]
Fischbach, Jannik, et al. “Automated generation of test models from semi-structured requirements.” 2019 IEEE 27th International Requirements Engineering Conference Workshops (REW). IEEE, 2019. (Year: 2019). [cited by examiner]
Saes, Laurence. “Unit test generation using machine learning.” Universiteit van Amsterdamg (2018). (Year: 2018). [cited by examiner]
Zhang, Mengshi, et al. “Deeproad: Gan-based metamorphic testing and input validation framework for autonomous driving systems.” Proceedings of the 33rd ACM/IEEE international conference on automated software engineering… [cited by examiner]
Wang, Song; Leveraging Machine Learning to Improve Software Reliability; dated 2019. [cited by applicant]
Holmes, J. et al.; Using mutants to help developers distinguish and debug (compiler) faults; Software Testing, Verification and Reliability; 30.2 (2020); e1727; dated 2020. [cited by applicant]
Piech et al., “Human Languages in Source Code: Auto-Translation for Localized Instruction” arXiv:1909.04556v1 [cs. CL] dated Sep. 10, 2019. 7 pages. 2019. [cited by applicant]
Blasi et al., “Translating Code Comments to Procedure Specifications” Proceedings of 27th ACM SIG-SOFT International Symposium on Software Testing and Analysis (ISSTA' 18) ACM, New York, NY. 12 pages. https://doi.org/10… [cited by applicant]
Rabin et al., “Testing Neural Program Analyzers” arXiv:1908.10711v2 [cs.LG] dated Sep. 25, 2019. 3 pages. 2019. [cited by applicant]
Aggarwal et al., “Using Machine Translation for Converting Python 2 Python 3 Code” PeerJ PrePrints. https://dx.doi.org/10.7287/peerj.preprints.1459v1. CC-BY 4.0 Open Acess dated Oct. 29, 2015. 4 pages. 2015. [cited by applicant]
Barone et al., “A parallel corpus of Python functions and documentation strings for automated code documentation and code generation” arXiv:1707.02275v1 [cs.CL] dated Jul. 7, 2017. 5 pages. 2017. [cited by applicant]
Saez et al., “Towards the detection of cross-language source code reuse” En Natural Language Processing and Information Systems. Springer Verlag (Germany). 6716:250-253. doi:10.1007/978-3-642-22327-3_31. 5 pages. 2011. [cited by applicant]
Bui “Towards Zero Knowledge Learning for Cross Language API Mappings” 2019 IEEE/ACM 41st International Conference on Software Engineering: Companion Proceedings (ICSE-Companion) 3 pages. 2019. [cited by applicant]
Akrouf et al., “A Multi-Modal Recognition System Using Face and Speech” IJCSI International Journal of Computer Sciences Issues, vol. 8, Issue 3, No. 1, May 2011 ISSN (Online): 1694-0814. 7 pages. 2011. [cited by applicant]
Albiol et al., “A fully automatic face recognition system using a combined audio-visual approach” 22 pages. [cited by applicant]
Beunder “Design of Continuous Authentication using Face Recognition” 20th Twente Student Conference on IT. Jan. 24, 2014, Enschede, The Netherlands. 8 pages. 2014. [cited by applicant]
Sundstrom, Alex; Investigation into Predicting Unit Test Failure Using Syntactic Source Code Features; 60 pages; dated 2018. [cited by applicant]
Berner, C. et al: Dota 2 with large scale deep reinforcement learning; arXiv preprint arXiv:1912.06680; dated 2019. [cited by applicant]