I am writing a Kotlin JVM application that uses the SQLDelight to generate classes that needs to interact with a MySQL database.
How can I write unit tests for classes/services that use the classes that SQLDelight library generated?
For example, SQLDelight generated interfaces like these:
interface SomeDB : Transacter {
val someTableQueries: SomeTableQueries
companion object {
val Schema: SqlDriver.Schema
get() = SomeDB::class.schema
operator fun invoke(driver: SqlDriver): SomeDB = SomeDB::class.newInstance(driver)
}
}
interface SomeTableQueries : Transacter {
fun <T : Any> querySomething(name: String, mapper: (
id: Long,
name: String,
address: String
) -> T): Query<T>
fun querySomething(name: String): Query<SomeTable>
}
And somewhere in my application, I have myService.findAllAddressForName(name: String)
, it will do something like someDB.someTableQueries.querySomething(name)
.
So what is the best way to unit test myService.findAllAddressForName
?
If I need to use libraries like Mockito
or mockito-kotlin
, which classes should I be mocking?
Is there any better way for me to write tests for these? Thanks.