IP Library › Granted Patent US 11,893,363
Granted Patent B2
US 11,893,363 · App. 17/080,843 · Granted Feb 6, 2024

Unit test case generation with transformers

Inventors: Dawn Drain (Bellevue, WA); Neelakantan Sundaresan (Bellevue, WA); Alexey Svyatkovskiy (Bellevue, WA); Michele Tufano (Bellevue, WA)
Assignee: MICROSOFT TECHNOLOGY LICENSING, LLC.
G06F8/35G06F17/18G06N3/084G06N3/088G06N5/046
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,893,363
App. No.
17/080,843
Filed
Oct 27, 2020
Granted
Feb 6, 2024
Kind
B2
Examiner
KANG, INSUN
Art Unit
2193
USPC
717/106
Abstract

A unit test generation system employs a neural transformer model with attention to generate candidate unit test sequences given a focal method of a programming language. The neural transformer model is pre-trained with source code programs and natural language text and fine-tuned with mapped test case pairs. A mapped test case pair includes a focal method and a unit test case for the focal method. 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 a unit test case.

Claims (34)

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 first neural transformer model with attention with a first unsupervised training dataset to learn semantic relationships of a natural language, the first unsupervised training dataset comprising a plurality of sequences of the natural language;

pre-train the first neural transformer model with attention with a second unsupervised training dataset to learn syntax of a programming language and se mantic relationships of code elements of the programming language, the second unsupervised training dataset comprising a plurality of sequences of source code from source code methods of the programming language;

fine-tune the first neural transformer model with attention with a supervised training dataset to learn to generate a unit test case fora given focal method written in the programming language, wherein the supervised dataset comprises mapped unit test case pairs, wherein a mapped unit test case pair of the mapped unit test case pairs includes a focal method and an associated unit test case written in the programming language, wherein fine-tuning the first neural transformer model with attention with the supervised training dataset is a translation task with a training objective that learns a mapping of a focal method to a unit test case, fm i →tc i , as a conditional probability P(tc i , fm i ); and

deploy the first neural transformer model with attention in a unit test case generation system to predict a unit test case fora target method of a source code program.

2. The system of claim 1 , wherein the first neural transformer model with attention is pre-trained with the first unsupervised training dataset before being pre-trained with the second unsupervised training dataset.

3. 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 unit test classes, wherein a unit test class includes a unit test case;

find a focal class for each test class, wherein a focal class represents a class of the test class under test;

identify a corresponding focal method within the focal class; and

match a unit test case name with a name of the corresponding focal method within the focal class to generate a mapped unit test case pair.

4. The system of claim 1 , wherein the one or more programs include further instructions to perform actions that: apply a span mask to the sequences of the first unsupervised training dataset; and wherein the pre-trained first neural transformer model with attention is trained to learn the semantic relationships of the natural language by replacing the span mask in a sequence with appropriate words of the natural language.

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

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

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

6. The system of claim 1 , wherein the natural language is English and the source code is written in Java programming language.

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

pre-training a neural transformer model with attention with a first unsupervised training dataset comprising a plurality of sequences of natural language text to learn semantic relationships of a natural language;

pre-training the neural transformer model with attention with a second unsupervised training dataset comprising a plurality of sequences of source code to learn syntax of a programming language and semantic relationships of code elements of the programming language;

fine-tuning the neural transformer model with attention with a supervised training dataset to learn to generate a unit test case fora given focal method written in the programming language, wherein the supervised dataset comprises mapped unit test case pairs, wherein a mapped unit test case pair of the mapped unit test case pairs comprises a first focal method and an associated unit test case written in the programming language, wherein fine-tuning the neural transformer model with attention with the supervised training dataset is a translation task with a training objective that learns a mapping of a focal method to a unit test case, fm i →tc i , as a conditional probability P(tc i , fm i ); and

deploying the neural transformer model with attention to automatically predict a unit test case fora given target method of a source code program.

8. The method of claim 7 , further comprising:

mining a source code repository for a plurality of unit test classes, wherein a unit test class includes a unit test case;

finding a focal class for each unit test class, wherein a focal class represents a class of the unit test class;

identifying a corresponding focal method within the focal class; and

matching a unit test case name with a name of the corresponding focal method within the focal class.

9. The method of claim 8 , further comprising: generating a mapped unit test case pair as the corresponding focal method and the matched unit test case name.

10. The method of claim 7 , further comprising: applying a span mask to the sequences of the second unsupervised training dataset; and wherein the pre-trained neural transformer model with attention is trained to learn the syntax of the programming language of the source code methods by replacing the span mask of a sequence with appropriate source code.

11. The method of claim 7 , further comprising: applying a span mask to the sequences of the first unsupervised training dataset; and wherein the pre-trained neural transformer model with attention is trained to learn the semantic relationships semantics of the natural language by replacing the span mask in a sequence with appropriate words of the natural language.

12. The method of claim 7 , wherein the neural transformer model with attention includes at least one encoder block having a Gaussian Error Linear Unit activation function (GELU) and at least one decoder block having a GELU.

13. The method of claim 7 , wherein the mapped unit test case pair further includes a focal method context, wherein the focal method context comprises a class constructor, class attributes or focal class methods' signatures of a focal class of the first focal method.

14. The method of claim 7 , wherein the natural language is English and the source code is written in Java programming language.

Assignments (2)
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Jun 27, 2022
From: DRAIN, DAWN
To: MICROSOFT TECHNOLOGY LICENSING, LLC.
Reel/Frame 060323/0449 →
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/0233 →
Continuity (2)
Provisional Application 63071335 · Aug 27, 2020
Related Publication 20220066747A1 · Mar 3, 2022
Cited By (3)
US 12,443,515 US 12,579,050 US 12,724,699