Griffon 集成测试或显示 Griffon 视图的脚本

发布于 2024-09-27 05:12:27 字数 837 浏览 4 评论 0原文

当我创建平面 java Swing 组件(例如对话框等)时,很容易进行单元测试来显示对话框。基本上,我可以创建对话框的实例并调用 setIsVisible(true)。我很难弄清楚如何使用狮鹫视图来做到这一点。我一直在尝试通过集成测试来做到这一点,但我似乎无法做到。

我尝试了一些方法来显示视图,但似乎没有任何效果。我似乎能够获取视图实例的唯一方法是: AirplaneView view = helper.newInstance(app, griffonpractice.AirplaneView.class, "Airplane")

在此之后我想我也许可以做 view.setIsVisible(true) 或 view.frame .setIsVisible(true) 但没有运气。我猜我以错误的方式思考这个问题,必须有一个相当简单的方法来做到这一点。任何帮助表示赞赏。我的视图如下所示,请注意,没有绑定,因此我不需要模拟任何内容。

package griffonpractice
import javax.swing.JFrame

JFrame frame = application(title: 'GriffonPractice',
  size: [320,480],
  pack: true,
  location: [50,50],
  locationByPlatform:true){
    borderLayout()
    {
        hbox(constraints: BL.NORTH)
        {
            label(text: "shane")
            label(text: "Jack");
        }
    }
}

When I create plane java Swing components like dialog boxes etc, it is very easy to make a unit test to display the Dialog. Basically, I can just create an instance of the dialog and call setIsVisible(true). I'm having a really tough time figuring out how to do this with a griffon View. I've been trying to do this with integration tests but I can't seem to get it.

I've tried a few things to show the view and nothing seems to work. The only way I seem to be able to get an instance of the view is:
AirplaneView view = helper.newInstance(app, griffonpractice.AirplaneView.class, "Airplane")

After this I thought I may be able to do a view.setIsVisible(true) or view.frame.setIsVisible(true) but no luck. I'm guessing I am thinking about this the wrong way, there has to be a fairly simple way to do this. Any help is appreciated. My view looks like the following, note that there are no bindings so I shouldn't need to mock anything.

package griffonpractice
import javax.swing.JFrame

JFrame frame = application(title: 'GriffonPractice',
  size: [320,480],
  pack: true,
  location: [50,50],
  locationByPlatform:true){
    borderLayout()
    {
        hbox(constraints: BL.NORTH)
        {
            label(text: "shane")
            label(text: "Jack");
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不一样的天空 2024-10-04 05:12:27

您尝试过使用 FEST 吗? http://easytesting.org

这本书Griffon in Action有使用 FEST 测试 Griffon 应用程序的详细示例,源代码位于 http://code.google.com/p/griffoninaction/source/browse/trunk/chap09/dictionary

下面是一个简单应用程序的 3 个测试的简短示例

package dictionary

import org.fest.swing.fixture.*
import griffon.fest.FestSwingTestCase

class DictionaryTests extends FestSwingTestCase {
    void testInitialState() {
        window.button('search').requireDisabled()
    }

    void testWordIsFound() {
        window.with {
            textBox('word').enterText('griffon')
            button('search').click()
            textBox('result')
                .requireText('griffon: Grails inspired desktop application development platform.')
        }
    }

    void testWordIsNotFound() {
        window.with {
            textBox('word').enterText('spock')
            button('search').click()
            textBox('result')
                .requireText("spock: Word doesn't exist in dictionary")
        }
    }

    protected void onTearDown() {
        app.models.dictionary.with {
            word = ""
            result = ""
        }
    }
}

Have you tried using FEST? http://easytesting.org

The book Griffon in Action has a detailed example on testing a Griffon application using FEST, the source code is available at http://code.google.com/p/griffoninaction/source/browse/trunk/chap09/dictionary

Here's a short example of 3 tests for a simple application

package dictionary

import org.fest.swing.fixture.*
import griffon.fest.FestSwingTestCase

class DictionaryTests extends FestSwingTestCase {
    void testInitialState() {
        window.button('search').requireDisabled()
    }

    void testWordIsFound() {
        window.with {
            textBox('word').enterText('griffon')
            button('search').click()
            textBox('result')
                .requireText('griffon: Grails inspired desktop application development platform.')
        }
    }

    void testWordIsNotFound() {
        window.with {
            textBox('word').enterText('spock')
            button('search').click()
            textBox('result')
                .requireText("spock: Word doesn't exist in dictionary")
        }
    }

    protected void onTearDown() {
        app.models.dictionary.with {
            word = ""
            result = ""
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文