Logger output not visible in test results

2,155 views
Skip to first unread message

Joan Pujol

unread,
Oct 24, 2009, 11:23:26 AM10/24/09
to testng-users
Hi,

I'm runing my tests with maven surefire and the problem that I've is
that I can't view my logger output in test results.

When I run the tests I can see the logger output in the console where
I run the command but I can't see it in the testng reporter ouptut.
In the reporter output I only can see what I output using System.out.

Someone knows what's happening? And why if my logger outputs to the
console it isn't visible in the testng output?


PD: I've tried to change surefire formMode to 'none' and it doesn't
works. For the rest I have all default values.

Cheers,

Cédric Beust ♔

unread,
Oct 24, 2009, 12:26:25 PM10/24/09
to testng...@googlegroups.com
Hi Joan,

Did you try without Maven at all?  This would help narrow down the suspects...

--
Cedric
--
Cédric


Joan Pujol

unread,
Oct 24, 2009, 2:34:50 PM10/24/09
to testng-users

I tested now and it doesn't works. In fact it's worse because I can't
either see the System.out messages in reorter output.

I tried the web example adding a log4j line (http://testng.org/doc/
documentation-main.html)
And ran it with:
java -classpath .;..\lib\log4j-1.2.15.jar;..\lib\testng-5.10-jdk15.jar
com.beust.testng.TestNG ../testng.xml

I can see the log while running in the command line but I can't see
nothing in the reporter output.

I've never used testng before. I'm missing some parameter?

Cheers,

Cédric Beust ♔

unread,
Oct 24, 2009, 5:49:51 PM10/24/09
to testng...@googlegroups.com
Can you post a short example with your code?  Are you using the Reporter class?

--
Cedric
--
Cédric


Joan Pujol

unread,
Oct 24, 2009, 6:12:36 PM10/24/09
to testng-users
Of course:

//+++++CODE++++++++++
package example1;

import org.testng.annotations.*;

public class SimpleTest {

@BeforeClass
public void setUp() {
// code that will be invoked when this test is instantiated
}

@Test(groups = { "fast" })
public void aFastTest() {
System.out.println("Fast test");
org.apache.log4j.Logger.getLogger(SimpleTest.class).info("This is a
test");
}

@Test(groups = { "slow" })
public void aSlowTest() {
System.out.println("Slow test");
}

}

//testng.xml

<suite name="Package suite">
<test name="test">
<packages>
<classes>
<class name="example1.SimpleTest" />
</classes>
</packages>
</test>
</suite>

//Command to run the test:
java -classpath .;..\lib\log4j-1.2.15.jar;..\lib\testng-5.10-
jdk15.jar
com.beust.testng.TestNG ../testng.xml

A lot of thanks Cédric,

On Oct 24, 11:49 pm, Cédric Beust ♔ <cbe...@google.com> wrote:
> Can you post a short example with your code?  Are you using the Reporter
> class?
>
> --
> Cedric
>
>
>
>
>
> On Sat, Oct 24, 2009 at 11:34 AM, Joan Pujol <joanpu...@gmail.com> wrote:
>
> > I tested now and it doesn't works. In fact it's worse because I can't
> > either see the System.out messages in reorter output.
>
> > I tried the web example adding a log4j line (http://testng.org/doc/
> > documentation-main.html <http://testng.org/doc/%0Adocumentation-main.html>
> > )

Cédric Beust ♔

unread,
Oct 24, 2009, 7:21:05 PM10/24/09
to testng...@googlegroups.com
Joan,

You need to use Reporter.log() if you want your logs to appear in the reports.

--
Cedric
--
Cédric


Joan Pujol

unread,
Oct 25, 2009, 9:16:50 AM10/25/09
to testng...@googlegroups.com
This is the only way?
There's no way to capture standard output messages writted by the code that is being tested?
Or any workarround, because I've no problem in using Reporter in testing code but it's also interesting for me to put output from the code that is being tested.

Cheers,

El 25/10/2009, a les 1:21, Cédric Beust ♔ <cbe...@google.com> va escriure:

Cédric Beust ♔

unread,
Oct 25, 2009, 10:39:32 AM10/25/09
to testng...@googlegroups.com
Yes, it's the only way.  TestNG doesn't capture System.out/err for a couple of reasons:
  • The output would be mangled when you run your tests in parallel.
  • Capturing System.out/err can interfere with other tools, especially when these tools already capture these outputs.
If you want to capture this yourself, it's pretty easy:  just assign out/err to your own writer in a @BeforeSuite.

Does this answer your question?

--
Cédric

Joan Pujol

unread,
Oct 25, 2009, 1:45:20 PM10/25/09
to testng...@googlegroups.com
Yes, now it's clear.

Thanks you Cédric.

2009/10/25 Cédric Beust ♔ <cbe...@google.com>:
--
Joan Jesús Pujol Espinar
http://www.joanpujol.cat
http://lujop.deviantart.com
Reply all
Reply to author
Forward
0 new messages