IP Library Granted Patent US 9,535,823
Granted Patent B2
US 9,535,823 · App. 13/366,411 · Granted Jan 3, 2017

Method and apparatus for detecting software bugs

Inventors: Doron Peretz (Pardesia, IL); Eli Shalom (Petach-Tikva, IL)
Assignee: TYPEMOCK LTD.
G06F11/3684G06F11/3688
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 9,535,823
App. No.
13/366,411
Granted
Jan 3, 2017
Kind
B2
Abstract

A computer-implemented method and apparatus for unit testing, the method comprising: intercepting user interactions when a user is testing a function implemented by user code; recording execution data for the function execution; generating one or more tests based on the execution data, wherein each test is generated in accordance with a heuristic applicable for the function; detecting a code change in the function; and automatically executing the tests function to test the user code as changed.

Claims (50)

1. A computer-implemented method for unit testing of code under test performed by a computerized device, said method comprising:

identifying a first function, of the code under test, being manually tested by the user;

intercepting code interactions of the first function with a second function and generating a shadow call stack of an execution of the first function;

recording execution objects, including arguments and return values, passed between the first and second functions during the execution of the first function and

automatically generating, from the intercepted code interactions and recorded execution objects, a new unit test for testing a unit of the code under test including the first function, the unit test being comprised of code statements including:

(1) a call to the first function;

(2) an assertion for the first function result or side effect; and

(3) one or more code statements designed to recreate a unit state at a time the first function was called during said intercepting of code interactions of the first function,

wherein generating the one or more code statements designed to recreate a unit state at a time the first function was called comprises:

i. analyzing the shadow call stack to identify frames which use one or more variables of a unit state of the code under test;

ii. for each given identified frame, identifying mutating frames preceding the given frame containing methods mutating the one or more variables; and

iii. adding the identified mutating methods to a setup of the new unit test.

2. The computer-implemented method of claim 1 , wherein the execution objects comprises one or more call stacks recorded during the execution of the second function.

3. The computer-implemented method of claim 1 , further comprising:

detecting a code change in the first function; and

automatically executing the new unit test to test the code as changed.

4. The computer-implemented method of claim 1 , further comprising:

starting a debug session;

executing at least one test function within the debug session; and

stopping execution at the first function.

5. The computer-implemented method of claim 1 , wherein the new unit test is generated in accordance with at least one heuristic applicable for the first function and the at least one heuristic is selected from the group consisting of: the first function returns a primitive type; the first function has a return value of a non-primitive type and the return value is later used by a function that returns a primitive value; the first function under test is a member of an object for which another method which returns a primitive value, is called; and a non-primitive argument to the first function is interacted from within the first function.

6. The computer-implemented method of claim 5 , wherein at least two heuristics are checked for applicability at a descending priority order, and the new unit test is generated in accordance with a first applicable heuristic.

7. The computer-implemented method of claim 1 , wherein generating code for the new unit test comprises isolating testing of a function called from within the first function.

8. The computer-implemented method of claim 1 , wherein generating code for the new unit test comprises validating that the new unit test passes for the first function as created.

9. The computer-implemented method of claim 1 , further comprising selecting a new unit test function for execution from a multiplicity of tests.

10. An apparatus for unit testing of code under test, said apparatus comprising:

an integrated development environment (IDE) communication component, comprising processing circuitry configured to provide unit testing capabilities as an addin to an IDE used for developing user code;

a runtime interception component, comprising processing circuitry configured to: (a) identify a first function, of the code under test, being manually tested by the user; (b) intercept code interactions of the first function with a second function; (c) generate a shadow call stack of an execution of the first function, and (d) record execution objects, including arguments and return values, passed between the first and second functions during the execution of the first function; and

a test generation component, comprising processing circuitry configured to automatically generate, from the intercepted code interactions and recorded execution objects, a new unit test for testing a unit of the code under test including the first function, the unit test being comprised of code statements including:

(1) a call to the first function;

(2) an assertion for the first function result or side effect; and

(3) one or more code statements designed to recreate a unit state at a time the first function was called during said intercepting of code interactions of the first function wherein generating the one or more code statements designed to recreate a unit state at a time the first function was called comprises:

i. analyzing the shadow call stack to identify frames which use one or more variables of a unit state of the code under test;

ii. for each given identified frame, identifying mutating frames preceding the given frame containing methods mutating the one or more variables; and

iii. adding the identified mutating methods to a setup of the new unit test.

11. The apparatus of claim 10 , wherein the execution data comprises one or more call stacks recorded during execution of the second function.

12. The apparatus of claim 10 , wherein the new unit test is generated in accordance with at least one heuristic applicable for the second function and the at least one heuristic is selected from the group consisting of: the second function returns a primitive type; the second function has a return value of a non-primitive type and the return value is later used by a function that returns a primitive value; the first function under test is a member of an object for which another method which returns a primitive value, is called; and a non-primitive argument to the first function is interacted from within the first function.

13. The apparatus of claim 10 , further comprising a user interface configured to display data to a user and receive information from a user.

14. A computer program product for generating unit testing for a code under test, said product comprising:

a non-transitory computer readable medium;

a first program instruction for identifying a first function, of the code under test, being manually tested by the user, intercepting code interactions of the first function with a second function and generating a shadow call stack of the execution of the first function;

a second program instruction for recording execution objects, including arguments and return values, passed between the first and second functions during the execution of the first function; and

a third program instruction for automatically generating, from the intercepted code interactions and recorded execution objects, a new unit test for testing a unit of the code under test including the first function, the unit test being comprised of code statements including:

(1) a call to the first function;

(2) an assertion for the first function result or side effect; and

(3) one or more code statements designed to recreate a unit state at a time the first function was called during said intercepting of code interactions of the first function;

wherein generating the one or more code statements designed to recreate a unit state at a time the first function was called comprises:

i. analyzing the shadow call stack to identify frames which use one or more variables of a unit state of the code under test;

ii. for each given identified frame, identifying mutating frames preceding the given frame containing methods mutating the one or more variables; and

iii. adding the identified mutating methods to a setup of the new unit test and wherein said first, second and third program instructions are stored on said non-transitory computer readable medium.

Assignments (1)
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Dec 30, 2015
From: PERETZ, DORON; SHALOM, ELI
To: TYPEMOCK LTD.
Reel/Frame 037380/0702 →
Continuity (2)
Provisional Application 61447431 · Feb 28, 2011
Related Publication 20120222014A1 · Aug 30, 2012