IP Library Granted Patent US 11,829,282
Granted Patent B2
US 11,829,282 · App. 17/080,846 · Granted Nov 28, 2023

Automatic generation of assert statements for unit test cases

Inventors: Dawn Drain (Bellevue, WA); Neelakantan Sundaresan (Bellevue, WA); Alexey Svyatkovskiy (Bellevue, WA); Michele Tufano (Bellevue, WA)
Assignee: MICROSOFT TECHNOLOGY LICENSING, LLC.
G06F11/3684G06F11/3688G06N3/088
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 11,829,282
App. No.
17/080,846
Filed
Oct 27, 2020
Granted
Nov 28, 2023
Kind
B2
Art Unit
2193
USPC
717/124
Abstract

An assert statement generator employs a neural transformer model with attention to generate candidate assert statements for a unit test method that tests a focal method. The neural transformer model is pre-trained with source code programs and natural language text and fine-tuned with test-assert triplets. A test-assert triplet includes a source code snippet that includes: (1) a unit test method with an assert placeholder; (2) the focal method; and (3) a corresponding assert statement. In this manner, the neural transformer model is trained to learn the semantics and statistical properties of a natural language, the syntax of a programming language, and the relationships between the code elements of the programming language and the syntax of an assert statement.

Claims (36)

1. A system comprising:

one or more processors; and

a memory that stores one or more programs that are configured to be executed by the one or more processors, the one or more programs including instructions to perform actions that:

pre-train a neural transformer model with attention with a first unsupervised training dataset to learn to predict natural language text, the first unsupervised training dataset including a plurality of sequences of natural language text;

pre-train the neural transformer model with attention with a second unsupervised training dataset to learn to predict a sequence of source code, the second unsupervised training dataset including a plurality of sequences of source code from source code methods of a programming language;

fine-tune the neural transformer model with attention with a supervised training dataset to learn to predict an assert statement for a given test method, the supervised dataset including a plurality of test-assert triplets, wherein a test-assert triplet includes a test method annotated with an asset placeholder, a focal method, and an assert statement, wherein the fine-tuning is a translation task with a training objective that learns to translate a source code snippet, s i , to a corresponding assert statement, a i , as a conditional probability P(a i |tm i ′+fm i ), where tm i ′ is a corresponding test method annotated with an assert placeholder and fm i is a corresponding focal method; and

deploy the neural transformer model with attention in a software development environment to generate a target assert statement given a specified test method and a specified focal method.

2. The system of claim 1 , wherein the one or more programs include further instructions to perform actions that:

mine a source code repository for a plurality of test methods having a single assert statement; and

generate the plurality of test-assert triplets from the plurality of test methods.

3. The system of claim 1 , wherein the one or more programs include further instructions to perform actions that:

apply a span mask to sequences of the second unsupervised training dataset; and

wherein the pre-trained neural transformer model with attention is trained to learn syntax of the programming language of the source code methods by replacing the span mask of a sequence with appropriate source code.

4. The system of claim 1 , wherein the one or more programs include further instructions to perform actions that:

apply a span mask to sequences of the first unsupervised training dataset; and

wherein the pre-trained neural transformer model with attention is trained to learn semantics of the natural language by replacing the span mask in a sequence with appropriate words of the natural language text.

5. The system of claim 1 , wherein the natural language text is English language and the source code of the second unsupervised training dataset and the source code of the supervised training dataset is written in a same programming language.

6. A method performed by one or more computing devices, comprising:

pre-training a neural transformer model with attention with a first unsupervised training dataset, the first unsupervised training dataset including a plurality of sequences of natural language text;

pre-training the neural transformer model with attention with a second unsupervised training dataset, the second unsupervised training dataset including a plurality of sequences of source code;

fine-tuning the neural transformer model with attention with a supervised training dataset, wherein the fine-tuning is a translation task with a training objective where the neural transformer model with attention learns to translate a source code snippet, s i , to an assert statement, a i , as a conditional probability P(a i |tm i ′+fm i ), where tm i ′ is a test method annotated with an assert placeholder, fm i is a corresponding focal method, and a i is a corresponding assert statement; and

deploying the neural transformer model with attention in a software development environment to automatically generate a target assert statement for a test method of a focal method.

7. The method of claim 6 , further comprising:

mining a source code repository for a plurality of test methods having a single assert statement.

8. The method of claim 7 , further comprising:

identifying the focal method subject to a select test method by identifying a latest method call in the select test method.

9. The method of claim 6 , further comprising:

applying a span mask to sequences of the second unsupervised training dataset; and

wherein the pre-trained neural transformer model with attention is trained to learn syntax of a programming language of the source code methods by replacing the span mask of a sequence with appropriate source code.

10. The method of claim 6 , further comprising:

applying a span mask to sequences of the first unsupervised training dataset; and

wherein the pre-trained neural transformer model with attention is trained to learn semantics of the natural language by replacing the span mask in a sequence with appropriate words of the natural language.

11. The method of claim 6 , wherein the neural transformer model with attention includes a plurality of encoder blocks and a plurality of decoder blocks, an encoder block having a multi-head attention layer, a decoder block having a masked multi-head attention layer.

12. The method of claim 11 , wherein at least one of the plurality of encoder blocks includes a gaussian error linear unit activation function.

13. The method of claim 6 , wherein the natural language text is English, and

wherein the source code of the second unsupervised training dataset and the supervised training dataset are written in a same programming language.

Assignments (2)
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Jun 5, 2022
From: DRAIN, DAWN
To: MICROSOFT TECHNOLOGY LICENSING, LLC.
Reel/Frame 060103/0861 →
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Oct 31, 2020
From: DRAIN, JAMES; SUNDARESAN, NEELAKANTAN; SVYATKOVSKIY, ALEXEY; TUFANO, MICHELE
To: MICROSOFT TECHNOLOGY LICENSING, LLC.
Reel/Frame 054233/0248 →
Continuity (2)
Provisional Application 63071337 · Aug 27, 2020
Related Publication 20220066914A1 · Mar 3, 2022