This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GradeCalculatorActivity : AppCompatActivity() { | |
companion object { | |
private const val TOTAL_MARKS = 100 | |
} | |
private val gradeCalculator = GradeCalculator() | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") { | |
val grade = calculator.getGrade(93, total) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.agoda.kakao.edit.KEditText | |
import com.agoda.kakao.screen.Screen | |
import com.agoda.kakao.text.KButton | |
import com.agoda.kakao.text.KTextView | |
import com.zuhaibahmad.kaspressotestingdemo.R | |
class GradeCalculatorScreen: Screen<GradeCalculatorScreen>() { | |
val inputMarks = KEditText { withId(R.id.etMarks) } | |
val buttonSubmit = KButton { withId(R.id.btSubmit) } | |
val labelGrade = KTextView { withId(R.id.tvGrade) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.test.rule.ActivityTestRule | |
import com.kaspersky.kaspresso.testcases.api.testcase.TestCase | |
import com.zuhaibahmad.kaspressotestingdemo.screens.GradeCalculatorScreen | |
import org.junit.Rule | |
import org.junit.Test | |
class GradeCalculatorUiTest : TestCase() { | |
@Rule | |
@JvmField |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
testImplementation 'junit:junit:4.13' | |
implementation 'androidx.test:core:1.2.0' | |
androidTestImplementation 'androidx.test.ext:junit:1.1.1' | |
testImplementation 'io.kotlintest:kotlintest-runner-junit5:3.1.7' | |
testImplementation 'io.mockk:mockk:1.9.3' | |
androidTestImplementation 'com.kaspersky.android-components:kaspresso:1.1.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
onScreen<FormScreen> { | |
phone { | |
hasText("971201771") | |
} | |
button { | |
click() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.constraintlayout.widget.ConstraintLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<androidx.appcompat.widget.AppCompatEditText | |
android:id="@+id/etMarks" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) } | |
} |
NewerOlder