Hey guys, it's been probably asked before and I'm ...
# spek
l
Hey guys, it's been probably asked before and I'm sure I've done this before, but I can't really find it anymore :/ how do I write tests where I need to have a @Autowired dependency? Thanks
­čĹÇ 1
r
You probably need to use an
ApplicationContext
directly. I've tried writing a spring extension before but I lost interest (as I don't use spring that much): https://github.com/spekframework/spek-spring-extension
l
I ended up trying Aspen and it works well for my needs. Do you think it is possible to do something related to this in Spek, where the tests are inside a init block? That would solve the problems with Spring. https://github.com/dam5s/aspen/blob/master/libraries/aspen-spring/src/test/kotlin/aspen/spring/examples/SpringApplicationTestExampleUsingInit.kt
r
where the tests are inside a init block?
Not gonna happen, the current way we do things already works - having a class to wrap for your test is an unnecessary ceremony (later on once kotlin scripting matures, we could ditch it and just write tests directly in a
.kts
file). A fix to this is to have a spring extension implemented.
l
The current extension doesn't work anymore with Spek2, since a lot has changed