Device and method for testing based on code injection mode

The invention provides a method for testing based on a code injection mode. The method includes the steps: compiling a driving module and a stud module to form a dynamic link library; after operation of a tested unit, using an injection tool to load the dynamic link library into the test unit; using the injection tool to appoint functions, replaced by the driving module and the stud module, in the tested unit; and testing the tested unit.