[hibernate-dev] Tests asserting warnings get logged

Sanne Grinovero sanne at hibernate.org
Fri Mar 28 09:10:15 EDT 2014


On 28 March 2014 12:35, Hardy Ferentschik <hardy at hibernate.org> wrote:
>
> On 28 Jan 2014, at 13:21, Sanne Grinovero <sanne at hibernate.org> wrote:
>
>> On 28 March 2014 12:15, Hardy Ferentschik <hardy at hibernate.org> wrote:
>>>
>>> On 28 Jan 2014, at 13:03, Sanne Grinovero <sanne at hibernate.org> wrote:
>>>
>>>> I'd then remove Log4J from our test dependencies to primarily rely on
>>>> assertions only;
>>>
>>> Why would you do that? I would expect whatever solution we come up with to
>>> just delegate to the underlying logger.
>>
>> Exactly, which doesn't need to be Log4J but could be our testable surrogate.
>
> Except with log4j I already have a lot of built-in functionality which you would have
> to first build in your solution. For example, category configuration or the ability to
> use different appenders.
>
>>>> or for debugging purposes to have it forwards
>>>> messages to System.out too - probably enabled by some environment
>>>> option - would be good enough.
>>>
>>> We have the logging system configurable already. Why complicating things.
>>> All we would be after is a way to verify that a given log message gets called.
>>> Everything else should behave as before.
>>
>> How so "complicating things"? I'm just suggesting to throw away a lot
>> of unnecessary complexity
>
> Which unnecessary complexity?
>
>> and focus on the stuff that matters: assert for specific messages,
>
> The ability to assert log messages is great and wanted, but the overall log
> is important as well. I want to see that it actually works.

But that's not related to our needs in unit tests, if any we should
avoid to test third party libraries which aren't required.

> And just looking at the log
> every now and then helps me to understand what’s happening, detect potential typos,
> find places where logging should be improved, ...

Ok you have a point there on the experience, but I'm focusing on my
needs in unit tests, while you' re talking about end to end
integration tests.
We probably need both, but that complicates things as if you have two
logger implementations I'm not sure we can pick which one JBoss Logger
would bind to. Generally I think we have lots to improve in isolating
our unit test to be quicker and less dependent on stuff which is
unrelated to their test subject; i.e. we should work to get more
"pure" unit tests, and parsing an external log file generated by an
optional library to test for e warn method to be triggered is going in
the opposite direction.

>
>> which is something Log4J doesn't provide
>
> Why would it, it is not a testing framework.
>
> —Hardy
>



More information about the hibernate-dev mailing list