Re: Junit with log4j

"David Saff" <[email protected]>
Newsgroups gmane.comp.java.junit.devel
Message-ID <[email protected]>
All,

I accidentally took this conversation off-line, but I think the final
answer is valuable for posterity:

If you're using JUnit 4, this should work.  There's a way to do it in
JUnit 3, as well, but it's more complicated.  Good luck,

  David Saff

import junit.framework.Test;
import junit.framework.TestSuite;

import org.junit.runner.JUnitCore;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunListener;

public class RunWithLogging {
       public static void main(String[] args) {
               JUnitCore core = new JUnitCore();
               core.addListener(new RunListener() {
                       @Override
                       public void testFailure(Failure failure) throws
Exception {
                               logSomehow(failure);
                       }
               });
               core.run(suite());
       }

       private static Test suite() {
               return new TestSuite(Sample.class);
       }


       private static void logSomehow(Failure failure) {
               // TODO: Fill in log4j stuff here
       }
}

On 1/12/07, pari krishnan <[email protected]> wrote:
> Hi,
>
> I need help..I want to divert assert message to my own log file with log4j.
> I have referred some link that it is not possible to divert assert message
> to log file with log4j as of version Junit 3.8.2.
> Just want to know whether it will support with new version Junit (above 4
> version)?
> Plz help...
> Ur mail will be helpful for me a lot
>
> Thanks & regards
> pari
>
> hat assertions are not logged via       Log4J
>
>
> ________________________________
> Here's a new way to find what you're looking for - Yahoo! Answers
>
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys - and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
>
> _______________________________________________
> Junit-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/junit-devel
>
>
>

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.