私がテストしたいクラスがあります。 package com.something;Spockメソッド内でオートワイヤードクラスの関数呼び出しを模擬する方法
import org.springframework.beans.factory.annotation.Autowired;
public class ClassToTest implements InterfaceToTest{
@Autowired
AnotherService serviceA;
@Override
public List<String> methodToTest(List<String> randomVar){
...
String stringA = serviceA.someFunction(randomVar);
...
}
}
スポックをテストするとき、私は私の選択の任意の文字列を返すようにserviceA.someFunction(randomVar)への呼び出しの結果を模擬することができますどのように
?
package com.something;
import spock.lang.Shared
import spock.lang.Specification
class TestClass extends Specification{
@Shared InterfaceToTest classToTest = new ClassToTest()
static doWithSpring = {
serviceA(AnotherService)
}
def "tests-part-1"(){
when: "something"
...
then: "expect this"
...
}
}
ここからどこに行くのかわかりません。私のIDEは、テストクラスに追加したdoWithSpringコードのエラーを表示します。これに対処する方法のアイデア?
これをやってみましたが、groovyはgroovy.land.MissingPropertyExceptionを返します。 "そのようなプロパティはありません:クラスcom.something.ClassToTestのserviceA –