· Home

 · Download

 · Internals

 · Howto

 · People

 · Javadoc

 · Mailing List

Conduits for Special Test Setup

Conduits allow you to perform special setup or construction for a component before testing it. For example, you may want to add some test data or build some other objects that cannot be retrieved from the GUI component. When you enter an implementation of ComponentConduit as the test class, the getComponent() method will be called and the returned Component will be used for testing.

import com.mtp.pounder.ComponentConduit;

public class SomeConduit implements ComponentConduit {

  public SomeModel model;
  public SomeComponent theComponent;

  public SomeConduit() {
    this.model = new SomeModel();
    //perform some special setup
    this.theComponent = new SomeComponent(model);
  }

  public Component getComponent() {
    return theComponent;
  }

}

When I'm writing a JUnit test that needs a conduit, I often just write the conduit as a static class inside the test:

import junit.framework.TestCase;
import junit.framework.Test;
import junit.framework.TestSuite;

import com.mtp.pounder.Player;
import com.mtp.pounder.ComponentConduit;

public class TestSomething extends TestCase {

  public TestSomething(String name) {
    super(name);
  }

  public static Test suite() {
    return new TestSuite(TestSomething.class);
  }

  public static class SomeConduit implements ComponentConduit {
    public SomeModel model;
    public SomeComponent theComponent;

    public SomeConduit() {
        this.model = new SomeModel();
        //perform some special setup
        this.theComponent = new SomeComponent(model);
    }
    public Component getComponent() {
        return theComponent;
    }
  }

  /** Test something. **/
  public void testThatFeature() throws Exception {
    Player player = new Player("scripts/myScript.pnd");
    SomeConduit sc = (SomeConduit)player.play();

    assertEquals(1, sc.model.someMethod());
  }

}

The class name would be entered like this into Pounder: TestSomething$SomeConduit. Note that the conduit is returned from a call to play(), not the component it creates.





Many thanks to SourceForge for hosting this project.
SourceForge



Copyright 2002 Matthew Pekar  All rights reserved.