I think you can achieve something like that by ann...
# mockk
m
I think you can achieve something like that by annotating your mocks with
@MockK
and using
MockkAnnotations.init(this, relaxed = true)
m
The project I’m working on uses JUnit 5, so according to the docs I needed to use
@ExtendWith(MockKExtension::class)
which apparently doesn’t allow setting common properties. Then I had to annotate every field with
@RelaxedMockK
and make it
lateinit var
. Not very fond of this solution… I think I’ll revert back to the no annotations form.
m
not really sure you need to use
@ExtendWith
with JUnit 5 though, i’ve been using annotations and
MockKAnnotations.init()
in my JUnit 5 projects 🙂
m
Oh didn’t know that, I’ll give a try to the manual initialization and let you know. — fact is that properties still need to be
lateinit var
, I’m afraid it would look too noisy for my taste… let’s see 😄
Final result is not too bad, I think I’ll keep it. It works under JUnit 5, thanks; I just had to put the MockkAnnotations call inside an
init {}
otherwise in order to use a @BeforeAll function I’d have to put that in a companion object or add another annotation to the class.
m
I usually put it in a @BeforeEach function
m
got it thanks!