-
Notifications
You must be signed in to change notification settings - Fork 0
Test Double β Dummy
Devrath edited this page Oct 24, 2023
·
1 revision
- What we do here is extend the class and we override the functions and just keep it empty.
- By doing this we can ensure the class uses the the implementation will not fail since this
dummy
essentially does not perform anything. - By doing so we can test other functionalities of the code.
LoginService.kt
--> This is our service class
interface LoginService {
fun connectToServer()
fun makeConnection() : Boolean
fun disconnectFromServer()
}
LoginServiceImpl.kt
--> This is the implementation for the service
open class LoginServiceImpl : LoginService {
override fun connectToServer() { }
override fun makeConnection(): Boolean {
if(someCustomImplementation()){ return true }
else{ return false }
}
override fun disconnectFromServer() { }
private fun someCustomImplementation(): Boolean {
// Some implementation logic
return true;
}
}
LoginServiceImplDummy.kt
--> This is the implementation for the service
class LoginServiceImplDummy : LoginServiceImpl() {
override fun connectToServer() {
super.connectToServer()
}
override fun makeConnection(): Boolean {
super.makeConnection()
return false
}
override fun disconnectFromServer() {
super.disconnectFromServer()
}
}