https://kotlinlang.org logo
#mockk
Title
# mockk
s

samir

06/25/2018, 10:54 AM
@oleksiyp I am getting fails when using mockStatic(Instant::class). Some tests in other test classes need to use it as a mock and some test classes need to use the real Instant class.
Copy code
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class Temp1 {
	@Test
	fun someTest() {
		val timestamp = Instant.now().toEpochMilli()
		println(timestamp) //123
	}

	@Test
	fun someOtherTest() {
		mockkStatic(Instant::class)
		every { Instant.now().toEpochMilli() } returns 123
		val timestamp = Instant.now().toEpochMilli()
		println(timestamp) //123
	}
}
Copy code
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class Temp2 {
	@Test
	fun someTest() {
		val timestamp = Instant.now().toEpochMilli()
		println(timestamp) //123
	}
}