You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Simon Kitching <si...@ecnetwork.co.nz> on 2003/10/01 01:45:14 UTC

[digester] turning off commons-logging for unit tests

Hi,

Currently the Digester unit tests include some tests which deliberately
trigger failures.

This is fine - error handling should also be tested.
Unfortunately, when an error occurs, Digester calls log.warn or
log.error, which gets printed out in the middle of the junit output.
Yecch.

I also want to add some plugins unit tests which test error conditions,
and have the same problem.

Does anyone know of a nice way to temporarily disable logging when
running certain tests, given that we don't know which underlying logging
implementation commons-logging has discovered at runtime?

FYI, the main problem line of code is:
  Digester.java: 1273

Thanks,

Simon


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [digester] turning off commons-logging for unit tests

Posted by Simon Kitching <si...@ecnetwork.co.nz>.
On Wed, 2003-10-01 at 13:06, Simon Kitching wrote:
>  
>  try {
>      Log oldLog = digester.getLogger();
>      digester.setLogger(new NoOpLog());
>      digester.parse(
>         TestAll.getInputStream(this, "test2.xml"));
>      digester.setLogger(oldLog);
>   }
>   catch(Exception e) {
>     // yay - exception was correctly generated
>     // ....
>   }

hmm..try

 Log oldLog = digester.getLogger();
 try {
    digester.setLogger(new NoOpLog());
    digester.parse(
      TestAll.getInputStream(this, "test2.xml"));
 }
 catch(Exception e) {
     // yay ... etc
 }
 finally {
   digester.setLogger(oldLog);
 }

:-)

In fact, it probably doesn't matter a damn about restoring the old
logger, as the test has failed. Still, don't want anyone thinking I
can't handle exceptions properly!


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [digester] turning off commons-logging for unit tests

Posted by Simon Kitching <si...@ecnetwork.co.nz>.
On Wed, 2003-10-01 at 12:24, Craig R. McClanahan wrote:
> __matthewHawthorne wrote:
> 
> > One trick that may work is to call Digester.setLogger() with your own 
> > org.apache.commons.logging.Log implementation that does nothing.
> >
> > Or you can use org.apache.commons.logging.impl.NoOpLog, which does the 
> > same thing.
> 
> Another approach would be to modify the build.xml file so that it 
> deliberately selects the SimpleLog logger implementation, and configures 
> it for error-level output only.  This can easily be done by passing 
> <sysproperty> elements inside the <java> elements that fire each test.
> 
> I'd certainly be interested in a patch to make this sort of behavior 
> permanent; I agree that the deliberately induced messages can be 
> misleading/annoying.

Thanks, Matthew. 

I added this for all the tests where I expect an exception to be thrown.
Works like a charm..
 
 try {
     Log oldLog = digester.getLogger();
     digester.setLogger(new NoOpLog());
     digester.parse(
        TestAll.getInputStream(this, "test2.xml"));
     digester.setLogger(oldLog);
  }
  catch(Exception e) {
    // yay - exception was correctly generated
    // ....
  }

[In fact, restoring the old logger is probably unnecessary].

Pesonally I think this is a better approach than totally disabling all
log output, because when a test which is not expected to throws an
exception actually does so, we *do* get useful logging output.

Disabling all logging below "error" isn't adequate in this case, because
the test is *deliberately* triggering an error, to check that the
digester code correctly handles user misconfiguration by reporting an
error [rather than continuing to run with bad configuration].

If it's ok with everyone, I will submit a patch to existing tests which
deliberately throw exceptions to treat them as above.

Regards,

Simon



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [digester] turning off commons-logging for unit tests

Posted by "Craig R. McClanahan" <cr...@apache.org>.
__matthewHawthorne wrote:

> One trick that may work is to call Digester.setLogger() with your own 
> org.apache.commons.logging.Log implementation that does nothing.
>
> Or you can use org.apache.commons.logging.impl.NoOpLog, which does the 
> same thing.

Another approach would be to modify the build.xml file so that it 
deliberately selects the SimpleLog logger implementation, and configures 
it for error-level output only.  This can easily be done by passing 
<sysproperty> elements inside the <java> elements that fire each test.

I'd certainly be interested in a patch to make this sort of behavior 
permanent; I agree that the deliberately induced messages can be 
misleading/annoying.

Craig

>
>
>
>
> Simon Kitching wrote:
>
>> Hi,
>>
>> Currently the Digester unit tests include some tests which deliberately
>> trigger failures.
>>
>> This is fine - error handling should also be tested.
>> Unfortunately, when an error occurs, Digester calls log.warn or
>> log.error, which gets printed out in the middle of the junit output.
>> Yecch.
>>
>> I also want to add some plugins unit tests which test error conditions,
>> and have the same problem.
>>
>> Does anyone know of a nice way to temporarily disable logging when
>> running certain tests, given that we don't know which underlying logging
>> implementation commons-logging has discovered at runtime?
>>
>> FYI, the main problem line of code is:
>>   Digester.java: 1273
>>
>> Thanks,
>>
>> Simon
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [digester] turning off commons-logging for unit tests

Posted by __matthewHawthorne <ma...@phreaker.net>.
One trick that may work is to call Digester.setLogger() with your own 
org.apache.commons.logging.Log implementation that does nothing.

Or you can use org.apache.commons.logging.impl.NoOpLog, which does the 
same thing.




Simon Kitching wrote:
> Hi,
> 
> Currently the Digester unit tests include some tests which deliberately
> trigger failures.
> 
> This is fine - error handling should also be tested.
> Unfortunately, when an error occurs, Digester calls log.warn or
> log.error, which gets printed out in the middle of the junit output.
> Yecch.
> 
> I also want to add some plugins unit tests which test error conditions,
> and have the same problem.
> 
> Does anyone know of a nice way to temporarily disable logging when
> running certain tests, given that we don't know which underlying logging
> implementation commons-logging has discovered at runtime?
> 
> FYI, the main problem line of code is:
>   Digester.java: 1273
> 
> Thanks,
> 
> Simon



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org