I have very briefly tried to get this up and running (using JUnit 4), but I am 
not sure what to make of the example, although the instructions seem simple 
enough, could there be a naming problem in the constructor, shouldn't it read:

import com.formos.tapestry.testify.core.TapestryTester;
import com.formos.tapestry.testify.junit4.TapestryTest;

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

    public *AbstractMyApplicationTest()* {  //and not TestifyTest() ?
        super(SHARED_TESTER);
    }
    
    @Override
    protected void setUpForAllTestClasses() throws Exception {
        MockitoAnnotations.initMocks(this);
    }    
}

Cheers,
Peter

----- Original Message -----
From: "Paul Field" <paul.fi...@db.com>
To: "Tapestry users" <users@tapestry.apache.org>
Sent: Friday, 19 June, 2009 11:53:24 GMT +02:00 Athens, Beirut, Bucharest, 
Istanbul
Subject: Re: [Announce] Tapestry Testify project

> 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.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to