views:

29

answers:

1

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");
        }
    }
}
A: 

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 = ""
        }
    }
}
aalmiray
Thanks for your input, I'll take a look at fest and let you know how it goes.
newcat