JUnit Rule for Annotations in EasyMock 3.3

In my first contribution for EasyMock 3.3 I have added support for processing the annotations with a JUnit Rule instead of the JUnit Runner.

In 3.2 you could do this:


@RunWith(EasyMockRunner.class)
public class SomethingTest extends EasyMockSupport{

    @Test
    public void shouldDoSomething() throws Exception {

        expect(aThing.aMethod()).andStubReturn(999);
        replayAll();            

        assertThat(thingUser.useThing(), is(999));

        verifyAll();
    }

From 3.3, you will be able to swap the Runner for the Rule like this:



public class SomethingTest extends EasyMockSupport{

    @Rule
    public EasyMockRule mocks = new EasyMockRule(this);

    @Test
    public void shouldDoSomething() throws Exception {

        expect(aThing.aMethod()).andStubReturn(999);
        replayAll();            

        assertThat(thingUser.useThing(), is(999));

        verifyAll();
    }
Advertisements
Posted in EasyMock, JUnit

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: