https://kotlinlang.org logo
Title
g

ghosalmartin

08/09/2019, 1:17 PM
Instead of a
@Before
I've been initing my tests as such. Since the subject is inited with mocks and their values are whats important not whats being injected. Can the @Before be foregoed? Or is there anyway I can have an
@Before
work on a variable since I don't want to
lateinit
the subject
g

gergo

08/09/2019, 1:35 PM
This way your subject will be the same between tests methods which means it's state will be the same as left from previous test, i wouldn't recommend this. I use lateinits with before, it's tests not production code, so even if it's a bit uglier at least im sure no state is shared between the tests
👆 2
c

Can Orhan

08/09/2019, 3:23 PM
@ghosalmartin Not sure what you mean by
values are whats important not whats being injected
g

ghosalmartin

08/09/2019, 3:24 PM
The mocks determine the state not the object itself
Anyone who was wondering, Junit 5 seems to solve this issue with suggestions from here https://resources.jetbrains.com/storage/products/kotlinconf2018/slides/4_Best%20Practices%20for%20Unit%20Testing%20in%20Kotlin.pdf
c

Can Orhan

08/13/2019, 8:08 AM
Do you mean ~ slide 30?
g

ghosalmartin

08/13/2019, 8:10 AM
Yano what am being an idiot
Slide 10 states that every
@test
will make a new instance of the class, meaning it will always reset the state
😎 1