May 2022
Intermediate to advanced
688 pages
20h 12m
English
Let’s look at a JVM test to see how it is structured. When Android Studio generated GeoQuiz’s project files, it also generated some unit tests for you. In com.bignerdranch.android.geoquiz (test), find and open ExampleUnitTest.kt:
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}
Both JVM and instrumented tests are executed using the JUnit testing framework. JUnit is the most popular way of unit testing code in Java and Kotlin and is widely supported on Android.
JUnit tests are encapsulated by classes. Within these classes, individual tests are functions marked by the @Test annotation, which you can see in the example. When running your tests, JUnit finds and executes the annotated ...
Read now
Unlock full access