Advertisements

General Musing

blaze your trail

Posts Tagged ‘tdd

Google Events Cracks Showing #tdd

leave a comment »

Google Events Cracks Showing
As with most beta products there are many wrinkles which need to be ironed out. So it is to be expected that issues such as Kevin Marks iterates below will ocurre.

From a developer perspective the first thing to do is note these issues down, the second thing to do is see whether they can be reproduced. Most developer/test teams would test manually whether they can be reproduced, I would tell them that they should be writing automated integration tests.

In team which is already test driven the unit tests will probably already cover this feature, so this means that when this error would be occurring that there is an issue with the unit tests which cover the code. For a team that isn’t already unit testing this is not great place to start their automated testing, and there is never really great place to start once you reach the beta version.

Why not test manually? you may ask. For one simple reason, if an issue such as is being described below is not already in your automated tests that’s the actual bug. Had there been a test for it, it wouldn’t have happened, and by writing a test you are ensuring it never happens (again) without knowing about it.

Kevin Marks
I tried inviting a non-gmail account to an Event. The email invite looks nice, and contains event details. Ok so far. 
I then try to respond to the event without creating a G+ account, or logging in. 
I get a web form with Yes/No/Maybe (Good) and 2 unlabelled fields. This is where the lunacy steps in.

What you put in these 2 unlabelled slots has to follow G+’s Names Policy (you know, the one that accepts ‘panel heater’ but rejects many real names. http://epeus.blogspot.com/2012/01/google-plus-admits…

View or comment on Daniël Crompton’s post »

Advertisements

Written by Daniël W. Crompton (webhat)

June 29, 2012 at 10:41 pm

Posted in Uncategorized

Tagged with , , ,

Mocking up your objects with EasyMock #test #junit #xp #tdd

leave a comment »

I’ve recently been using EasyMock to create mock objects to pass in my JUnit tests, and I often find that I often mock up objects for private members which are auto-wired or injected by the platform, and in some cases are unrelated to the code I unit testing. Usually it is too expensive to run a full environment of middleware for testing, and it is also necessary to test the exception handling code which will most likely not be called unless it is specifically mocked.

So I wrote the following function to insert a mock object into a private member:

public <T> T insertPrivateField(Object instance, Class<?> targetClass,
        String targetFieldName,
        Class<T> mockedClass) {
    T mockedObject = null;
     try {
        Class<?> clazz = Class.forName(targetClass.getCanonicalName());
        Field field = clazz.getDeclaredField(targetFieldName);
        field.setAccessible(true);

        mockedObject = EasyMock.createMock(mockedClass);
        field.set(instance, mockedObject);
        } catch (Exception e) {
         log.error(e.getMessage(), e); // logs exception with log4j
        fail(e.getMessage()); // junit failure generated
    }
     return mockedObject;
}

Have fun with it.

    

Written by Daniël W. Crompton (webhat)

August 15, 2011 at 1:41 pm

Posted in programming

Tagged with , , , , , , ,

%d bloggers like this: