This paper proposes a new method for automatic generation of test cases using model based testing. As test model, class and state diagrams are used, and constraints are expressed using OCL. First, the state machine is converted into a mathematical representation in AMPL. Then, using a search algorithm and based upon coverage criteria, the abstract paths are selected from state machine. Second, using symbolic execution, the generated abstract path along with the constraints on this path is converted into the data of generated mathematical model. Third, the generated mathematical problem is solved with solvers that have interface with AMPL, and the test data is produced for each abstract test case. Finally, the generated test data and abstract paths are transformed into executable test cases. All-Transitions and All-States coverage criteria are used for conduct search algorithm, as well as the criteria for evaluate the quality of generated test cases. To validate the work, by utilizing various solvers, the test cases are generated for various problems. The proposed technique is implemented as a tool, named MoBaTeG. The tool shows good result in terms of test case generation execution time, test goals satisfaction rate, source code instructions coverage, and also boundary values generation.