TestNG lifecycle listeners

612 views
Skip to first unread message

Jaikiran

unread,
Nov 27, 2009, 1:16:53 AM11/27/09
to testng-users
I am new to TestNG and have been using JUnit for years now. Infact,
although i had heard about TestNG, i started looking at it seriously,
only this week. One of the reasons for looking at some other test
framework is the absence of lifecycle listeners within JUnit. The
details about what i am talking are explained in a forum post here
http://www.coderanch.com/t/472680/Testing/JUnit-lifecycle-listeners (i
would have re-written that entire discussion here, but i think it
makes sense to avoid duplicating it).

After reading some of the docs on TestNG, i did find a section where
it talks about being able to use listeners. Looking at the javadocs i
do see that there's a ISuiteListener which gets invoked at the start
and end of a test "suite". Assuming my 1 run of TestNG has 5 suites,
then i guess there will be 5 such start/stop notifications? Is that
correct? Also, is there anything more related to this, which i should
be looking at? I haven't yet figured out how to specify a listener
from within a test class - maybe through annotation? But i think i'll
have to read some more docs to understand that.

On a unrelated note, i find the "group" feature for tests a good one.
And i think i'll be switching to TestNG in one of my projects to give
it a try.

Cédric Beust ♔

unread,
Nov 27, 2009, 11:20:44 AM11/27/09
to testng...@googlegroups.com
Hi,

On Thu, Nov 26, 2009 at 10:16 PM, Jaikiran <jaikir...@gmail.com> wrote:
I am new to TestNG and have been using JUnit for years now. Infact,
although i had heard about TestNG, i started looking at it seriously,
only this week. One of the reasons for looking at some other test
framework is the absence of lifecycle listeners within JUnit. The
details about what i am talking are explained in a forum post here
http://www.coderanch.com/t/472680/Testing/JUnit-lifecycle-listeners (i
would have re-written that entire discussion here, but i think it
makes sense to avoid duplicating it).

After reading some of the docs on TestNG, i did find a section where
it talks about being able to use listeners. Looking at the javadocs i
do see that there's a ISuiteListener which gets invoked at the start
and end of a test "suite". Assuming my 1 run of TestNG has 5 suites,
then i guess there will be 5 such start/stop notifications? Is that
correct?

Correct.  There are two kinds of listeners you can use TestNG:  one that gets invoked at the end of the run with all the results and one that gets invoked every time something "interesting" happens (test started, test passed, test failed, etc...).
 
Also, is there anything more related to this, which i should
be looking at?

The documentation contains a few examples.  You can also look at the misc section, which has links to quite a few articles.  Finally, there is also our book, if you want to become an expert in testing :-)


 
I haven't yet figured out how to specify a listener
from within a test class - maybe through annotation? But i think i'll
have to read some more docs to understand that.

You can't specify a listener from a test class.  If you are only interested in such events for one class, you can always use a regular reporter or listener and only display the results for that particular class.

On a unrelated note, i find the "group" feature for tests a good one.
And i think i'll be switching to TestNG in one of my projects to give
it a try.

Feel free to ask here if you have more questions!

--
Cédric


Reply all
Reply to author
Forward
0 new messages