Skip to content

Instantly share code, notes, and snippets.

View stoichoandreev's full-sized avatar

Stoycho Andreev stoichoandreev

View GitHub Profile
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
testImplementation 'junit:junit:4.13.2'
testImplementation 'io.mockk:mockk:1.11.0'
testImplementation 'org.robolectric:robolectric:4.5.1'
@RunWith(AndroidJUnit4::class)//Be careful with the import here, do not import androidx.test.runner.AndroidJUnit4! You will need androidx.test.ext.junit.runners.AndroidJUnit4
@Config(sdk = [24], application = MyTestApplication::class)
@LooperMode(LooperMode.Mode.PAUSED)
class LoginActivityTest {
private val robot = Robot()
@Before
fun setup() {
robot.setup()
import com.sniper.bdd.robo.LoginPresenter
import com.sniper.bdd.robo.LoginValidator
import com.sniper.bdd.robo.data.DataFactory
import io.mockk.MockKAnnotations
import io.mockk.every
import io.mockk.impl.annotations.RelaxedMockK
import io.mockk.verify
import org.junit.Before
import org.junit.Test
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
/**
* 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 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
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
/**
* 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
@stoichoandreev
stoichoandreev / Ad.kt
Created March 18, 2020 09:51
Gist 4 - Android Example
data class Ad(val id: String)
@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"))
}
}