Complete the code to create a simple unit test function in Kotlin.
fun testAddition() {
val result = 2 + 2
assertEquals([1], result)
}The test checks if 2 + 2 equals 4, which is the correct result.
Complete the code to launch an activity in an Android instrumented test.
val scenario = ActivityScenario.launch([1]::class.java)
ActivityScenario.launch requires the activity class to launch, here MainActivity.
Fix the error in the test assertion to check if a list contains a value.
assertTrue(myList.[1](5))
The correct Kotlin function to check if a list contains an element is contains().
Fill both blanks to create a test that checks if a function throws an exception.
assertThrows<[1]> { myFunction([2]) }
The test expects an IllegalArgumentException when myFunction is called with 0.
Fill all three blanks to create a test that verifies a LiveData value changes correctly.
val liveData = MutableLiveData<Int>() liveData.value = [1] liveData.observeForever { value -> assertEquals([2], value) } liveData.value = [3]
The LiveData starts at 0, then changes to 1, and the observer checks for 1.