Test we can enter "1" into the textfield and get the value 1 out

  1. Extend ComponentFixture

  2. Get a tester for the component we're testing.

  3. Show the component in a frame.

  4. "Type" text in the component with actionKeyString


package com.elharo.swing.test;

import com.elharo.swing.WholeNumberField;

import abbot.tester.ComponentTester;
import junit.extensions.abbot.ComponentTestFixture;

public class WholeNumberFieldTestCase extends ComponentTestFixture {

    private ComponentTester tester;
    private WholeNumberField field;
    
    protected void setUp() {
        tester = ComponentTester.getTester(WholeNumberField.class);
        field = new WholeNumberField();
        showFrame(field);
    }
    
    public void testOne() {
        tester.actionKeyString(field, "1");
        int result = field.getNumberValue();
        assertEquals(1, result);
    }
    
}

Previous | Next | Top | Cafe con Leche

Copyright 2005, 2006 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified September 28, 2005