Instead of a `@Before` I've been initing my tests ...
# codereview
g
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
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
@ghosalmartin Not sure what you mean by
values are whats important not whats being injected
g
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
Do you mean ~ slide 30?
g
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