```class Temp1 { @Test fun someTest() { ...
# mockk
s
Copy code
class Temp1 {
    @Test
    fun someTest() {
        val timestamp = Instant.now().toEpochMilli()
        println(timestamp) //real value
    }

    @Test
    fun someOtherTest() {
        mockkStatic(Instant::class)
        every { Instant.now().toEpochMilli() } returns 123
        val timestamp = Instant.now().toEpochMilli()
        println(timestamp) //123
        unmockStatic(Instant::class)
    }
}
Copy code
class Temp1 {
    @BeforeAll
    fun setup() {
        mockkStatic(Instant::class)
    }

    @BeforeEach
    fun beforeEach() {
        clearStaticMocks(Instant::class)
    }

    @Test
    fun someTest() {
        every { Instant.now().toEpochMilli() } returns 123
        val timestamp = Instant.now().toEpochMilli()
        println(timestamp) //123
    }

    @Test
    fun someOtherTest() {
        every { Instant.now().toEpochMilli() } returns 456
        val timestamp = Instant.now().toEpochMilli() //456
    }
}