commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: [Logging] Error using logging with Unit Tests
Date Mon, 17 Feb 2003 17:06:02 GMT

On Mon, 17 Feb 2003, Maher Martin wrote:

> Date: Mon, 17 Feb 2003 15:59:51 +0100
> From: Maher Martin <>
> Reply-To: Jakarta Commons Users List <>
> To: 'Jakarta Commons Users List' <>
> Subject: [Logging] Error using logging with Unit Tests
> Hi,
> I'm having problems with the logging component in conjunction with Unit
> Tests (JUnit). Within a testCase I cannot use the logging component. I keep
> getting the error:
> Class org.apache.commons.logging.impl.Log4JCategoryLog does not implement
> Log
> I looked at the class Log4JCategoryLog and it clearly does implement the
> class Log.
> Below you can find the full stack trace as well as a sample Unit Test Class.
> Note:
> - The Main method within the test class does not throw any exception,
> however the testCase does.
> - I have not explicitly specified which Log Implementation to use, however
> Log4J is available within the classpath.

This sounds like a case of having commons-logging in multiple class
loaders at the same time -- if the Log interface is loaded from class
loader A, but the Log4JCategoryLog class is loaded from class loader B
that is a parent of A, then Log4JCategoryLog will load B's copy of the Log
interface -- and the JVM does not consider the two log interfaces to be
assignment-compatible or castable (even though the signatures might all be

If you run your JUnit tests from Ant, I have found it most effective to
use fork="yes" so that everything runs in a separate JVM, where you can
set up precisely the class path you need (instead of having it run in the
same class path that Ant is using).  Successful examples of doing this
(including the use of logging in the test code) can be found in most of
the commons package source distributions - the ones' I'm most familiar
with are for beanutils and digester.

> thanks,
> Martin Maher


View raw message