Introduction to Android Unit Testing using Kotlin and JUnit

class Calculator {
fun sum(a: Double, b: Double): Double {
return 0.0
}

fun subtract(a: Double, b: Double): Double {
return a-b
}

fun divide(a: Double, b: Double): Double {
return a/b
}

fun multiply(a: Double, b: Double): Double {
return a*b
}
}
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test

class CalculatorTest {
private lateinit var mCalculator: Calculator

@Before
fun setUp() {
mCalculator = Calculator()
}

@Test
fun sum() {
assertEquals(6.0, mCalculator.sum(1.0, 5.0),0.0)
}

@Test
fun subtract() {
assertEquals(6.0, mCalculator.subtract(10.0, 4.0),0.0)
}

@Test
fun divide() {
assertEquals(2.0, mCalculator.divide(10.0, 5.0),0.0)
}

@Test
fun multiply() {
assertEquals(20.0,mCalculator.multiply(2.0,10.0),0.0)
}
}
assertEquals(6.0, mCalculator.sum(1.0, 5.0),0.0)
fun sum(a: Double, b: Double): Double {
return a+b
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store