【问题标题】:Griffon integration test or script that displays a griffon View显示 griffon 视图的 Griffon 集成测试或脚本
【发布时间】:2010-10-12 02:43:58
【问题描述】:

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

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

在这之后,我想我也许可以做一个view.setIsVisible(true) or 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");
        }
    }
}

【问题讨论】:

    标签: swing groovy griffon swingbuilder


    【解决方案1】:

    您是否尝试过使用 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 = ""
            }
        }
    }
    

    【讨论】:

    • 感谢您的意见,我会看看 fest 并告诉您进展如何。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-15
    • 1970-01-01
    • 1970-01-01
    • 2015-09-30
    相关资源
    最近更新 更多