Exactly what makes it possible in kotlin to write ...
# spring
p
Exactly what makes it possible in kotlin to write a Test with
@Autowired val
parameters? So one can write this
Copy code
class MyRepositoryTests(@Autowired val entityManager: TestEntityManager, @Autowired val repository: UserRepository)
while in java you should have an Autowired field (seen at https://docs.spring.io/spring-boot/reference/testing/spring-boot-applications.html#testing.spring-boot-applications.autoconfigured-spring-data-jpa)
d
Spring is smart enough to wire up the constructor arguments. Works in Java as well.
s
you can even configure spring to autowire fields to the test class constructor by default, letting you omit
@Autowired
, the same way as you can in the main source sets: furthermore, you can set that globally for your tests by setting junit config parameter: https://docs.spring.io/spring-framework/reference/languages/kotlin/spring-projects-in.html#constructor-injection