31 lines
929 B
Kotlin
31 lines
929 B
Kotlin
package com.example.hpostesting
|
|
|
|
import io.mockk.every
|
|
import io.mockk.mockk
|
|
import io.mockk.verify
|
|
import junit.framework.TestCase.assertEquals
|
|
import org.junit.Test
|
|
|
|
class MathApplicationTest {
|
|
|
|
@Test
|
|
fun testAddNumbers() {
|
|
// Create a mock of the Calculator class using Mockito-Kotlin
|
|
val calculatorMock = mockk<Calculator>()
|
|
|
|
// Define the behavior of the add method on the mock
|
|
every { calculatorMock.add(2, 3) } returns 5
|
|
|
|
// Create an instance of MathApplication with the mock Calculator
|
|
val mathApplication = MathApplication(calculatorMock)
|
|
|
|
// Perform the test using the MathApplication
|
|
val result = mathApplication.addNumbers(2, 3)
|
|
|
|
// Verify that the add method of the mock was called with the correct parameters
|
|
verify { calculatorMock.add(2, 3) }
|
|
|
|
// Verify the result of the test
|
|
assertEquals(5, result)
|
|
}
|
|
} |