Grails 3.2.8とSpockフレームワークをテストに使用し、次のコントローラー クラスを指定します。
class SomeController {
def doSomething() {
// do a few things, then:
someOtherMethod()
}
protected void someOtherMethod() {
// do something here, but I don't care
}
}
doSomething()メソッドをテストして、someOtherMethod()
正確に 1 回呼び出されることを確認するにはどうすればよいですか?
これは失敗した私の試みです:
@TestFor(SomeController)
class SomeControllerSpec extends Specification {
void "Test that someOtherMethod() is called once inside doSomething()"() {
when:
controller.doSomething()
then:
1 * controller.someOtherMethod(_)
}
}
エラーメッセージ:
Too few invocations for:
1 * controller.someOtherMethod(_) (0 invocations)
注: 当面の問題に焦点を当てるために、インポートは省略されています