I currently try to test a class as a spy object that normally initialize a database connection in the constructor. The a simplified version of the class looks like this.
class classToTest(){
val connection:Connection
init {
connection = DatabaseConnection(url="127.0.0.1")
}
fun methodA():Int{
return 3
}
}
Now i try to test the methods of my classToTest in the following way (simplified).
class TestClass(){
var connection = mockk<DatabaseConnection>()
var dbh = spyk(ClassToTest())
@Test
fun testMethodA(){
assertEquals(dbh.methodA,3)
}
}
The problem is now that my test can not start because i don't know how to overwrite the init function that may connection mock is used instead of initialize a connection object. Thanks for help.