JVM Tests
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 ...
Get Android Programming: The Big Nerd Ranch Guide, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.