Mocking static methods with Mockito

后端 未结 15 1090
Happy的楠姐
Happy的楠姐 2020-11-21 06:51

I\'ve written a factory to produce java.sql.Connection objects:

public class MySQLDatabaseConnectionFactory implements DatabaseConnectionFactory         


        
15条回答
  •  爱一瞬间的悲伤
    2020-11-21 07:44

    As mentioned before you can not mock static methods with mockito.

    If changing your testing framework is not an option you can do the following:

    Create an interface for DriverManager, mock this interface, inject it via some kind of dependency injection and verify on that mock.

提交回复
热议问题