• Flexibility to choose what is shared and what not • Shared code lowers the e ff ort, cost per feature • Shared code ensures consistency amongst platforms
Keep your shared API simple • Think like a library developer • Implementation should not impact API • Minimise accessibility of everything • Coexist peacefully with (both) platforms
class NewYearTest { @Test fun `From Jan 1 2022 to Jan 1 2023`() { val startDate = LocalDate( year = 2022, monthNumber = 1, dayOfMonth = 1 ) assertEquals( expected = 365, actual = daysUntilNewYear(startDate), "There are x days until New Year 2023" ) } }
} //androidMain actual class Platform actual constructor() { actual val osName = "Android" } //iosMain actual class Platform actual constructor() { actual val osName = UIDevice.currentDevice.systemName() }
= Platform() @Test actual fun testOSName() { assertEquals( expected = "Android", actual = platform.osName, message = "The OS name should be Android." ) } }
= Platform() @Test actual fun testOSName() { assertTrue( actual = platform.osName.equals("iOS", ignoreCase = true) message = "The OS name should be iOS." ) } }
: TestsWithMocks() { override fun setUpMocks() = injectMocks(mocker) @Mock lateinit var view: View @Fake lateinit var model: Model val controller by withMocks { Controller( view = view, firstModel = model ) } ... }