We have a class that performs mathematical actions:
class MathUtil {
fun add(a: Int, b: Int): Int = a + b
fun multiply(a: Int, b: Int): Int = a * b
fun divide(a: Int, b: Int): Int = a / b
}We wrote tests to check the performance of the class:
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
internal class MathUtilTest {
private var result = 5
private val mathUtil = MathUtil()
@AfterEach
fun afterEach(){
// required code
}
@Test
fun test_Add() {
result = mathUtil.add(result, 5)
println("test_Add(5,5) => $result")
assertEquals(10, result)
}
@Test
fun test_Multiply() {
result = mathUtil.multiple(result, 5)
println("test_Multiply(5,5) => $result")
assertEquals(25, result)
}
@Test
fun test_Divide() {
result = mathUtil.divide(result, 5)
println("test_Divide(5,5) => $result")
assertEquals(1, result)
}
}An error was made when writing the test class, and the tests do not work.
The correct conclusion after passing the tests is:
test_Divide(5,5) => 1
test_Add(5,5) => 10
test_Multiply(5,5) => 25Specify the missing code in the tests.