Question

I'm trying to use FEST swing test suite to write test for different interface responses. In single class situations it works very well. However, now I have a situation where I have am using GMockTestCase. I set up all the mocked method calls with returns and then create my "Play" enclosure, but my asserts fail. If I run the same test without the Mocked class my test passes. Is there an order in which things must be set up?

Here is my test:

@Test
void testsShouldReturnRadioButtonSelectedFromClassGroupButtonGroupKeyPressed(){
    def mockClassMap  = getClassMap()
    mockPG.getAvailibleClass().returns(mockClassMap)
    panel.plyGen = mockPG
    panel.raceValue = 1
    panel.genderValue = 2
    panel.gPane.mainM.setVisible(false)
    panel.gPane.createPlayerStats.setVisible(true)
    //panel.plyGen = new PlayerGenerater()


    play{
        festSetUp(panel.gPane.chooseClass)
        panel.gPane.reRollDice.requestFocusInWindow()


                    // simulate key stroke to change panel view
        robot.keyPress(VK_A)
        robot.keyRelease(VK_A)

        // simulate key stroke to select radio button option
        robot.keyPress(VK_M)
        robot.keyRelease(VK_M)
        assertThat(panel.classValue, is(3))
    }
}

Any help would be appreciated.

Was it helpful?

Solution

Just to answer my own question for the benefit of those who might have a similar question. The answer was limit the test to a single user input interaction. Above I was trying to simulate two things. Interaction to move from one panel screen to a second as well as interaction on the second panel. Limiting the interaction to test just the second half of the user interaction is was allowed FEST to properly recognize the interactions. The resulting code for a passing test in this example was:

def mockClassMap  = getClassMap()

    panel.plyGen = mockPG
    mockPG.getAvailableClass().returns(mockClassMap)
    panel.raceValue = 1
    panel.genderValue = 2
    panel.gPane.mainM.setVisible(false)
    panel.gPane.chooseClass.setVisible(true)
    //panel.plyGen = new PlayerGenerator()


    play{
        festSetUp(panel.gPane.chooseClass)
                          /*additional methods that need to be triggered in order to 
                           *set up the panel for actual test
                          */
            panel.setClassGroup()
            gPane.classGroupPanel.revalidate()
            gPane.chooseClass.setVisible(true)

                     //simulate user interaction
        robot.keyPress(VK_M)
        robot.keyRelease(VK_M)

                       //assert results
            assertThat gPane.selectClass.getSelection(), is(gPane.monk.getModel())

    }

So basic unit testing 101 isolate tests to single actions

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top