6
私はKotlin、Spring、Spekを使用して簡単なマイクロサービスを実装しています。リポジトリをテストしたいのですが、spekテストケースにどのようにレポを注入できるのでしょうか?私はこのようなSTHをしたいいけないsummupするにSpekテストでdependency injectionを使用する方法
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)
}
}
})
:このような新しい参照を作成上のすべての例やチュートリアルベース
val calculator = SampleCalculator()
私はこの
@Autowired
val calculator: SampleCalculator
を達成したいが、私はローカル変数にオートワイヤーサービスを行うことはできませんので、私はそれを傾ける..任意のソリューション?私はkotlinとspekで新しいです。
私はすぐにしようと提案することができます回避策はローカル[ 'object'式](https://kotlinlang.org/docs/reference/object-ですdeclarations.html#object-expressions)を '@ Autowired'プロパティで置き換えます。それは動作しますか? – hotkey