Programmatically Running TestNG and Generating SureFire Reports

997 views
Skip to first unread message

Mark Hansen

unread,
Dec 10, 2010, 7:28:46 PM12/10/10
to testng-users
Does anyone know how I can run TestNG classes inside a Java program
and generated the sure-fire reports that you get when using Maven with
TestNG?

I know that the basic code for running a test within Java is like
this:

TestListenerAdapter tla = new TestListenerAdapter();
TestNG testng = new TestNG();
testng.setTestClasses(new Class[] { testClass });
testng.addListener(tla);
testng.run();

So, I'm wondering if there is a TestListenerAdapter within the
SureFire plugin that I can use for generating the reports.

-- Mark

Cédric Beust ♔

unread,
Dec 10, 2010, 8:04:01 PM12/10/10
to testng...@googlegroups.com
Hi Mark,

These Surefire reports are actually context sensitive: if you use Surefire to run JUnit tests, you'll get JUnit reports, and the same with TestNG.

In other words, your code below should have generated these reports already, check your test-output/ directory.

-- 
Cédric



--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.




--
Cédric


Mark Hansen

unread,
Dec 10, 2010, 8:37:14 PM12/10/10
to testng-users
Oh, cool. So I guess my next question, is:

How do I run surefire outside of Maven, i.e., programmatically? I
want to implement an API like this:

public void runTestNG(Class[] testNGClasses, File outputDir);

so the reports will be written to outpuDir. This is for a GUI-driven
test harness that lets a user select tests, run then, and then click
on links to read the reports.
> > testng-users...@googlegroups.com<testng-users%2Bunsu...@googlegroups.com>
> > .

Mark Hansen

unread,
Dec 11, 2010, 5:36:11 PM12/11/10
to testng-users
Nevermind - I see these reports get generated by TestNG. I thought
Surefire was generating the reports. But, I don't need to call
Surefire at all to get reports.
Reply all
Reply to author
Forward
0 new messages