CPC G06F 11/3684 (2013.01) [G06F 11/3688 (2013.01)] | 18 Claims |
1. A method, executed by one or more processors, for creating unit tests for testing a computer program, the method comprising:
receiving, over a computer network, an electronic request that specifies a portion in the computer program to be covered by the unit test;
constructing a Control Flow Graph (CFG) representation for the portion in the computer program, wherein the CFG includes at least an assignment node for assigning a method call executed by a flow analysis software to a given variable and information about the given variable that is being assigned with a value, and a return value node representing an exit point from a method called by the flow analysis software;
parsing the CFG by the flow analysis software to build a plurality of different potential execution paths that may lead to the portion in the computer program and to identify a unique formula for each of the potential execution paths wherein each formula includes a list of pre-conditions and associated variables that represent a simulated execution path;
parsing a source code of the portion in the computer program, by the one or more processors, to generate an abstract syntax tree as representation of a content of the portion in the computer program, by mapping a source code of the portion to a tree according to syntax rules of a programming language;
analyzing the portion in the computer program to determine whether it provides capability to set each of the associated variables in each formula, utilizing the abstract syntax tree;
translating variables, fields, and expressions of the source code represented in the each formula into a plurality of decision variables, using pre-determined categories of constraints;
computing a solution to the list of pre-conditions from the each formula to one of the potential solutions that specifies values for decision variables;
selecting a formula, from the plurality of formulas, with fewest number of associated variables, which has a solution that specifies values for decision variables for given pre-conditions;
creating a unit test, based on the solution and the list of pre-conditions collected and solved; and
executing the unit test to test the computer program.
|