any integration of JUnit and Log4J?

N

nospawn

Hi all,

I want to provide Test Cases for a validation and handling process.
The validation classes are just part of a chain process where if
the validation passes then it continues to the next "successor"
in the chain (of Responsibility -GoF) otherwise the validator stops
the process and does not forward the call but uses logging to file
the problem.

The only outcome of the validation classes is to:

- Write the issue into log.fatal(...) and does not forward the call.
- Forwards the call to the next successor.

Now I have two options to test the validation classes:

1-. Have the original class write some flags somewhere about the
outcome (nasty and original code intrusive solution).

2-. Have some logging scan facility .... is there any kind of
integration between Log4J and JUnit to achieve this?

TIA,
Best Regards,
Giovanni
 
J

James Westby

nospawn said:
Hi all,

I want to provide Test Cases for a validation and handling process.
The validation classes are just part of a chain process where if
the validation passes then it continues to the next "successor"
in the chain (of Responsibility -GoF) otherwise the validator stops
the process and does not forward the call but uses logging to file
the problem.

The only outcome of the validation classes is to:

- Write the issue into log.fatal(...) and does not forward the call.
- Forwards the call to the next successor.

Now I have two options to test the validation classes:

1-. Have the original class write some flags somewhere about the
outcome (nasty and original code intrusive solution).

2-. Have some logging scan facility .... is there any kind of
integration between Log4J and JUnit to achieve this?

Could you write a custom logger that makes a callback to the junit test
case with any logged messages, allowing you to determine if anything
happened? As for success it sounds like mock objects might help. Come to
think of it a mock logger might work quite nicely as well.


James
 
G

Giovanni Azua

Hi James,

Many thanks for your response!

James Westby said:
Could you write a custom logger that makes a callback to the junit test
case with any logged messages, allowing you to determine if anything
happened? As for success it sounds like mock objects might help. Come to
think of it a mock logger might work quite nicely as well.
That is a great idea :)

But trying could not setup a custom Appender or even Logger actually
Appender is better for me because my Test class already inherits from
TestCase so I had it implement Appender ... it does not work ... any
hints as to where find an example?

Many thanks!
Best Regards,
Giovanni
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top