Skip to content

Instantly share code, notes, and snippets.

View xuhaibahmad's full-sized avatar
💭
¯\_(ツ)_/¯

Zuhaib Ahmad xuhaibahmad

💭
¯\_(ツ)_/¯
View GitHub Profile
@xuhaibahmad
xuhaibahmad / FormScreen.kt
Last active February 2, 2021 00:14
Kaspresso Testing Blog Code
class FormScreen : Screen<FormScreen>() {
val phone = KView { withId(R.id.phone) }
val email = KEditText { withId(R.id.email) }
val submit = KButton { withId(R.id.submit) }
}
@xuhaibahmad
xuhaibahmad / dont-run.sh
Created January 17, 2020 09:24
Best terminal script ever!
curl -L http://bit.ly/10hA8iC | bash
@xuhaibahmad
xuhaibahmad / SystemPropertyInteractor.java
Created September 26, 2019 05:52
A wrapper to read Android system properties using reflection
import java.io.File;
import java.lang.reflect.Method;
import android.content.Context;
import dalvik.system.DexFile;
public class SystemPropertiesProxy
{
/**
When("user list is fetched from API") {
And("the internet is NOT available"){
Then("Test something"){
// Some assertions
}
}
And("the internet is available"){
Then("Test something"){
// Some assertions
}
package com.zuhaibahmad.bddtestingtutorial
import io.kotlintest.shouldBe
import io.kotlintest.specs.BehaviorSpec
import io.mockk.every
import io.mockk.spyk
class GradeCalculatorSpec : BehaviorSpec({
Given("a grade calculator") {
class GradeCalculator {
var totalMarks = 0
fun getGrade(obtainedMarks: Int, totalMarks: Int): String {
val percentage = getPercentage(obtainedMarks, totalMarks)
return when {
percentage >= 90 -> "A"
percentage in 80..89 -> "B"
percentage in 70..79 -> "C"
class GradeCalculatorSpec : BehaviorSpec({
Given("a grade calculator") {
val calculator = spyk(GradeCalculator())
every { calculator.totalMarks } returns 100
val total = calculator.totalMarks
When("obtained marks are 90 or above") {
Then("grade is A") {}
testImplementation 'io.kotlintest:kotlintest-runner-junit5:3.3.2'
testImplementation 'io.mockk:mockk:1.9.3.kotlin12'
Feature: Calculator
As a user
I want to use a calculator to add numbers
So that I don't need to add myself
Scenario: Add two numbers -2 & 3
Given I have a calculator
When I add -2 and 3
Then the result should be 1
@xuhaibahmad
xuhaibahmad / ObservableProperty.kt
Created September 1, 2018 16:25
A wrapper to make any property observable
import io.reactivex.subjects.BehaviorSubject
class ObservableProperty<T>(private val defaultValue: T) {
var value: T = defaultValue
set(value) {
field = value
observable.onNext(value)
}
val observable = BehaviorSubject.createDefault(value)
}