0

I understand how to specify extraInterface using the @Mock annotation, but how can I create a mock and add the extraInterfaces inline?

@SmallTest
@RunWith(MockitoJUnitRunner::class)
class MyTestClass {
    
    @Mock(extraInterfaces = [MyCallback::class])
    lateinit var callbackFragment: Fragment
    ...
}

But how can I do this on the fly?

// this doesn't compile
val callbackFragment = mock<Fragment>(extraInterfaces = [MyCallback::class])

What is the correct syntax for adding extraInterfaces to a Mockito mock in Kotlin?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
VIN
  • 6,385
  • 7
  • 38
  • 77

2 Answers2

4

This should work:

 val mock = mock<Fragment>(extraInterfaces = arrayOf(MyCallback::class))
Luciano Ferruzzi
  • 1,042
  • 9
  • 20
0

This also works:

@Mock(extraInterfaces = [MyCallback::class])
lateinit var fragment: Fragment
VIN
  • 6,385
  • 7
  • 38
  • 77