A
system for generating a unit test based on
source code is disclosed having a computer, a
source code file, an
abstract syntax tree, and at least one unit test. The
source code file contains a source code having a plurality of constructs each belonging to a type including functions, return statements, attribute assignments, function calls, and branches. An
abstract syntax tree is generated by a
computer based on a source code and a plurality of constructions, the
abstract syntax tree having a plurality of nodes, where each of the plurality of constructions in the source code has a corresponding node. At least one unit test is generated by a
computer based on nodes of the
abstract syntax tree and predefined rules, the unit test comprising at least one packet function corresponding to a function configuration or a
branch configuration, and the unit test comprising at least one trial function corresponding to a
return statement configuration, an attribute assignment configuration, or a function call configuration.