Skip to content

Instantly share code, notes, and snippets.

View stoichoandreev's full-sized avatar

Stoycho Andreev stoichoandreev

View GitHub Profile
@stoichoandreev
stoichoandreev / AndroidRobot.kt
Last active March 18, 2020 09:43
Gist 1 A - None Android Example
class AndroidRobot: BaseLifeCycle() {
fun onCreate() {
start()
}
fun onResume() {
resume()
}
@stoichoandreev
stoichoandreev / AndroidLifeCycleComponent.kt
Last active March 18, 2020 09:42
Gist 1 B None Android Example
class AndroidLifeCycleComponent {
fun start() {
System.out.println("Robot Start")
}
fun resume() {
System.out.println("Robot Resume")
}
@stoichoandreev
stoichoandreev / ApiService.kt
Last active March 18, 2020 09:42
Gist 2 - Android example
class ApiService {
fun requestDataFromBackend(): Observable<MyRawDataModel> {
return BackendAPI().returnSomeDummyData()
}
fun readCachedUserName(rawDataModel: MyRawDataModel) : Observable<Pair<MyRawDataModel, String>> {
val cachedUserName = PreferenceManager.getDefaultSharedPreferences(MyApplication.INSTANCE).getString("USER_NAME", "") ?: ""
return Observable.just(Pair(rawDataModel, cachedUserName))
}
@stoichoandreev
stoichoandreev / DataApiService.kt
Created March 18, 2020 09:45
Gist 3 - Android Example
object DataApiService {
fun loadData(): Observable<DataModel> {
return Observable.just(DataModel("data_model"))
}
fun loadAnoteherData(): Observable<AnotherDataModel> {
return Observable.just(AnotherDataModel("another_data_model"))
}
}
@stoichoandreev
stoichoandreev / Ad.kt
Created March 18, 2020 09:51
Gist 4 - Android Example
data class Ad(val id: String)
import com.sniper.bdd.robo.BaseRobot
/**
* Use the method to setup GIVEN step for any test (Unit and Instrumentation)
* @param block - the block of code which needs to be executed in the GIVEN step
* @return - robot instance of the test robot, it allows us to call robot methods directly
*/
fun <T: BaseRobot>TestRun<T>.GIVEN(
block: T.() -> Unit
import com.sniper.bdd.robo.BaseRobot
import java.util.concurrent.TimeUnit
/**
* Use the method to run single unit test
* @param robot - Set your test robot (should extend BaseRobot)
* @param block - the block of code which needs to be executed in our test. Usually we need to place inside all steps for the test
* @return - TestRun data class instance, which includes the test name and the robot instance
import com.sniper.bdd.robo.BaseRobot
import java.util.concurrent.TimeUnit
/**
* Use the method to run single UI test
* @param robot - Set your test robot (should extend BaseRobot)
* @param block - the block of code which needs to be executed in our test. Usually we need to place inside all steps for the test
* @return - TestRun data class instance, which includes the test name and the robot instance
/**
* Each test Robot in our application (UI test Robot or Unit test Robot) should extend BaseRobot
*/
open class BaseRobot {
/**
* Use the method to setup stuff in your Robot class before each test run
*/
open fun setup() {
//no base implementation
}
import com.sniper.bdd.robo.BaseRobot
import com.sniper.bdd.robo.LoginPresenter
import com.sniper.bdd.robo.LoginValidator
import com.sniper.bdd.robo.data.DataFactory
import com.sniper.bdd.robo.dsl.GIVEN
import com.sniper.bdd.robo.dsl.RUN_UNIT_TEST
import com.sniper.bdd.robo.dsl.THEN
import com.sniper.bdd.robo.dsl.WHEN
import io.mockk.MockKAnnotations
import io.mockk.every