Mockito (http://mockito.org/) is a very elegant stubbing and mocking framework.
Mockito can create mocks for fields that are annotated with the @Mock annotation and this works really well with Testify's @ForComponent annotation. In the following example, Mockito creates the mocks and Testify injects them into the pages/components.
public class MyTest extends AbstractMyApplicationTest { @ForComponents @Mock MyService service; @ForComponents("serviceId") @Mock MyNamedService namedService; public void testElementIsOnPage() { when(service.shouldShowElement()).thenReturn(true); Document page = tester.renderPage("mypage"); assertNotNull(page.getElementById("myid")); }
To integrate Mockito simply implement the method setUpForAllTestMethods in your standard test super-class, like this (JUnit 3 example):
import com.formos.tapestry.testify.core.TapestryTester; import com.formos.tapestry.testify.junit3.TapestryTest; public abstract class AbstractMyApplicationTest extends TapestryTest { private static final TapestryTester SHARED_TESTER = new TapestryTester("demo", MyCoreModule.class); public TestifyTest() { super(SHARED_TESTER); } @Override protected void setUpForAllTestMethods() throws Exception { MockitoAnnotations.initMocks(this); } }