今はグリフォンで遊んでいます。テストを除いて、すべてが非常にスムーズに機能します。
Griffon アプリケーション全体を起動せずに、個別のコントローラー メソッドをテストするのが好きです。これを行うには、コントローラーで使用されるビューとモデルをモックする必要があるように思えます。Expando オブジェクトのモック化により、easyb を使用したコントローラー メソッドとアクションのテストが長くなりすぎています。
簡単な例を次に示します。
MyProjectView.groovy
application(title: 'MyProject',
pack: true,
locationByPlatform: true,
iconImage: imageIcon('/griffon-icon-48x48.png').image,
iconImages: [imageIcon('/griffon-icon-48x48.png').image,
imageIcon('/griffon-icon-32x32.png').image,
imageIcon('/griffon-icon-16x16.png').image]
) {
tableLayout {
tr {
td(align: "CENTER") {
textField(id: 'textfield',
text: "Hello")
}
}
tr {
td(align: "CENTER") {
button(text: "check",
actionPerformed: controller.checkForGreeting
)
}
}
}
}
MyProjectController.groovy
class MyProjectController {
def model
def view
void mvcGroupInit(Map args) {
}
def checkForGreeting = { evt = null ->
return view.textfield.text == "Hello"
}
MyProjectModel.groovy
class MyProjectModel {}
easyb テスト: MyProjectStory.story
scenario "Hello Check", {
def view
MyProjectController controller = new MyProjectController()
given "A view with 'Hello' in the textfield", {
view = new Expando()
def textfield = new Expando()
textfield.text = "Hello"
view.textfield = textfield
controller.view = view
}
then "checkForGreeting should return true", {
controller.checkForGreeting().shouldBe(true)
}
}
Griffon コントローラーのメソッドをテストする簡単な方法はありますか? おそらく、ビューをモックするためのより良いソリューションを使用することでしょうか?