0
0
Android Kotlinmobile~10 mins

Why testing ensures app reliability in Android Kotlin - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a simple unit test function in Kotlin.

Android Kotlin
fun testAddition() {
    val result = 2 + 2
    assertEquals([1], result)
}
Drag options to blanks, or click blank then click option'
A5
B6
C4
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong expected value in assertEquals.
Forgetting to use assertEquals for comparison.
2fill in blank
medium

Complete the code to launch an activity in an Android instrumented test.

Android Kotlin
val scenario = ActivityScenario.launch([1]::class.java)
Drag options to blanks, or click blank then click option'
AApplication
BMainActivity
CContext
DView
Attempts:
3 left
💡 Hint
Common Mistakes
Using Application or Context instead of an Activity class.
Using a view class instead of an activity.
3fill in blank
hard

Fix the error in the test assertion to check if a list contains a value.

Android Kotlin
assertTrue(myList.[1](5))
Drag options to blanks, or click blank then click option'
Acontains
Bhas
Cincludes
Dexists
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent functions like has or includes.
Confusing Kotlin with JavaScript syntax.
4fill in blank
hard

Fill both blanks to create a test that checks if a function throws an exception.

Android Kotlin
assertThrows<[1]> {
    myFunction([2])
}
Drag options to blanks, or click blank then click option'
AIllegalArgumentException
B5
C0
DNullPointerException
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong exception type in assertThrows.
Passing a value that does not cause an exception.
5fill in blank
hard

Fill all three blanks to create a test that verifies a LiveData value changes correctly.

Android Kotlin
val liveData = MutableLiveData<Int>()
liveData.value = [1]
liveData.observeForever { value ->
    assertEquals([2], value)
}
liveData.value = [3]
Drag options to blanks, or click blank then click option'
A0
B1
Attempts:
3 left
💡 Hint
Common Mistakes
Not updating LiveData value before observing.
Expecting the wrong value in assertEquals.