October 2019
Intermediate to advanced
434 pages
11h 54m
English
To begin exploring how testing can improve the integration and interop experience of our Kotlin code base, we'll start by writing a basic test using Kotlin.
For this example, we'll imagine we're testing how a view model is formatting data so that it can be presented in our UI. We'll test the following function, which takes in String as name and returns that name prepended with Hello:
fun formatGreeting(name: String) : String { return "Hello $name"}
We can then write a simple JUnit4 test with Kotlin to test the behavior of our new function:
import org.junit.Assert.*class UtilitiesKtTest { @org.junit.Test fun test_formatGreeting() { val formattedName = formatGreeting("Nate") assertEquals("Hello Nate", formattedName) ...
Read now
Unlock full access