« Return to Thread: [Announce] Tapestry Testify project

Re: [Announce] Tapestry Testify project

by Paul Field-4 :: Rate this Message:

Reply to Author | View in Thread

> This looks really promising Paul, thanks!
>
> One question, can Easymock be used for mocks, I am not familiar with
Mockito?

Absolutely - Testify doesn't depend on Mockito.

BTW, do look at Mockito (http://mockito.org/) - it's a very clean way to
write stubs and mocks - I used to be an EasyMock user and I've been
converted :-)


So, some more information (which I will put into the documentation at some
point) ....

My aim was just made sure that Testify would work well with Mockito's
@Mock annotation so, if you use Mockito, it's *really* simple to create a
mock and inject it into a component:

public class MyTest extends AbstractMyApplicationTest {
    @ForComponents @Mock MyService service;
 
    public void testElementIsOnPage() {
        when(service.shouldShowElement()).thenReturn(true);
        Document page = tester.renderPage("mypage");
        assertNotNull(page.getElementById("myid"));
    }

In this example, @ForComponents is a Testify annotation; @Mock is a
Mockito annotation and AbstractMyApplicationTest is your own abstract test
class that does standard setup:

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 setUpForAllTestClasses() throws Exception {
        MockitoAnnotations.initMocks(this);
    }
}

Because this is *your* standard superclass, it's your choice to include
other frameworks such as Mockito (or you could write your own equivalent
of @Mock but for EasyMock and wire it in here).

-------------------------

However, if you wanted to use EasyMock, you'd setup the mocks yourself in
your test. Something like this:

public class MyTest extends AbstractMyApplicationTest {
    @ForComponents MyService service;
 
    public void doSetUp() {
        service = EasyMock.createMock(MyService.class);
    }

    public void testElementIsOnPage() {
        expect(service.shouldShowElement()).andReturn(true);
        replay(service);
        Document page = tester.renderPage("mypage");
        assertNotNull(page.getElementById("myid"));
    }


And your standard superclass, obviously, doesn't set up Mockito:

public abstract class AbstractMyApplicationTest extends TapestryTest {
    private static final TapestryTester SHARED_TESTER
        = new TapestryTester("demo", MyCoreModule.class);

    public TestifyTest() {
        super(SHARED_TESTER);
    }
}

------------------
Paul Field
Research IT
Deutsche Bank




---

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.

Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures.

 « Return to Thread: [Announce] Tapestry Testify project