Streamlining unit testing through hot code swapping
First Claim
Patent Images
1. A method of testing functions using mock functions, the method comprising:
- receiving information at a function tester specified using a declarative syntax that defines a test case definition for a target function to be tested by the function tester, the test case definition including an expected number of arguments to one or more external functions to be called in the target function and expected argument values for the expected number of arguments to be sent in a call to each of the one or more external functions from the target function;
creating, using a processor operatively coupled to a memory, a mock function for an external function to be called in the target function based on the received test case definition for the target function;
replacing the external function to be called in the target function with the mock function created based on the received test case definition for the target function;
calling the mock function in response to calling the target function;
determining whether the mock function was called with an expected number of arguments to the external function and expected argument values for the expected number of arguments defined according to the received test case definition for the target function; and
generating information indicative of a failure or success based on the determination whether the mock function was called with the expected number of arguments to the external function and the expected argument values for the expected number of arguments defined according to the received test case definition for the target function.
1 Assignment
0 Petitions
Accused Products
Abstract
Methods and systems are described for testing methods and other functions by swapping external functions for mock functions. A test case definition is entered by a programmer, which can specify the expected number of arguments and argument values of external function or method calls, the context state, the return value, and any expected error conditions. The test case definition is used by a function tester to automatically create mock functions, modify the target function so that it calls the mock functions, execute the target function with specified arguments and a test context, and then compare the results to expected results.
-
Citations
20 Claims
-
1. A method of testing functions using mock functions, the method comprising:
-
receiving information at a function tester specified using a declarative syntax that defines a test case definition for a target function to be tested by the function tester, the test case definition including an expected number of arguments to one or more external functions to be called in the target function and expected argument values for the expected number of arguments to be sent in a call to each of the one or more external functions from the target function; creating, using a processor operatively coupled to a memory, a mock function for an external function to be called in the target function based on the received test case definition for the target function; replacing the external function to be called in the target function with the mock function created based on the received test case definition for the target function; calling the mock function in response to calling the target function; determining whether the mock function was called with an expected number of arguments to the external function and expected argument values for the expected number of arguments defined according to the received test case definition for the target function; and generating information indicative of a failure or success based on the determination whether the mock function was called with the expected number of arguments to the external function and the expected argument values for the expected number of arguments defined according to the received test case definition for the target function. - View Dependent Claims (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18)
-
-
19. A non-transitory machine-readable medium embodying information indicative of instructions for causing one or more machines to test functions using mock functions, the non-transitory machine-readable medium comprising:
-
code for receiving information specified using a declarative syntax that defines a test case definition for a target function to be tested, the test case definition including an expected number of arguments to one or more external functions to be called in the target function and expected argument values for the expected number of arguments to be sent in a call to each of the one or more external functions from the target function; code for creating a mock function for an external function to be called in the target function based on the received test case definition for the target function; code for replacing the external function to be called in the target function with the mock function created based on the received test case definition for the target function; code for calling the target function, the target function calling the mock function; code for determining whether the target function called the mock function with the expected number of arguments and the expected argument values for the expected number of arguments defined according to the received test case definition for the target function; and code for generating information indicative of a failure or success report based on the determination whether the target function called the mock function with the expected number of arguments to the external function and the expected argument values for the expected number of arguments defined according to the received test case definition for the target function.
-
-
20. A computer system comprising:
-
at least one processor; and a memory operatively coupled to the at least one processor and configured to store program code that configures the at least one processor to; receive information specified using a declarative syntax that defines a test case definition for a target function to be tested by the function tester, the test case definition including an expected number of arguments to one or more external functions to be called in the target function and expected argument values for the expected number of arguments to be sent in a call to each of the one or more external functions from the target function; create a mock function for an external function to be called in the target function based on the received test case definition for the target function; replace the external function to be called in the target function with the mock function created based on the received test case definition for the target function; determine whether a call to the target function called the mock function with an expected number of arguments to the external function and expected argument values for the expected number of arguments defined according to the received test case definition for the target function; and generate information indicative of a failure or success report based on the determination whether the call to the target function called the mock function with the expected number of arguments to the external function and the expected argument values for the expected number of arguments defined according to the received test case definition for the target function.
-
Specification