如何在Spek测试中使用依赖注入
我正在使用Kotlin,Spring和Spek实现简单的微服务。 我想测试我的存储库,但我不知道如何注入到测试案例的回购。 每个例子或教程基于创建新的参考,如下所示:
object SampleTest : Spek({ describe("a calculator") { val calculator = SampleCalculator() it("should return the result of adding the first number to the second number") { val sum = calculator.sum(2, 4) assertEquals(6, sum) } it("should return the result of subtracting the second number from the first number") { val subtract = calculator.subtract(4, 2) assertEquals(2, subtract) } } })
summup我不想这样做:
val calculator = SampleCalculator()
我想实现这一点
@Autowired val calculator: SampleCalculator
但我不能这样做,因为我不能autowire服务本地变量..任何解决方案? 我是新的kotlin和spek。
- Kotlin&Spring Boot @ConfigurationProperties
- Kotlin测试失败从命令行与ClassNotFoundException但从IntelliJ工作
- Spring&kotlin:构造函数和lateinit注入有什么区别?
- 如何用Spring WebFlux返回404
- 使用Kotlin的Spring Boot 2.0.0.M2应用程序的UnsatisfiedDependencyException
- 如何在Spring Boot应用程序中为Netty配置TLS?
- Kotlin编译器抱怨在属性定义中使用SPeL表达式。 为什么?
- Kotlin – Mockito不能模拟/间谍(Spring REST API)