Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [riena-dev] Test friendly LOGGER pattern

How about something like this:

    private final static Logger LOGGER = LoggerUtil.getLogger(Activator.getDefault(), ImageStore.class);

Looks much nicer to me. ;-)

Tschüß,
Stefan

Elias Volanakis wrote:
Just a quick tip:

If you use static LOGGER fields, I recommend using the pattern (b) below. It avoids a NPE exception when calling Activator.getDefault().getLogger(), which usually happens when running test suites as "plain" junit tests.

(a) Problematic with Junit:

public final class MyClass {

private static final Logger LOGGER = Activator.getDefault().getLogger(ImageStore.class);

(b) Works well with Junit:

public final class MyClass {

private static final Logger LOGGER;

static {
if (Activator.getDefault() != null) {
LOGGER = Activator.getDefault().getLogger(MyClass.class);
} else {
LOGGER = new ConsoleLogger(MyClass.class.getName());
}
}

I know that some test cases must be run as "plug-in" tests, but I usually run individual test cases for stuff I'm working on as "regular" unit-tests, because they start much faster :-)

Viele Gruesse,
Elias.


Back to the top