--
You received this message because you are subscribed to the Google Groups "testng-dev" group.
To post to this group, send email to testn...@googlegroups.com.
To unsubscribe from this group, send email to testng-dev+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-dev?hl=en.
Hi all,
I'm not so sure listeners are the best solution here, at least with the
current implementation. I tried to do 'interception' using listeners and
finally ended up implementing IHookable as interception mechanism for
these reasons:
- listeners have to be configured in your IDE and your maven/ant/...
project files to work at all whereas extending a (lean) common
superclass which does the "magic" of intercepting the test method call
is far easier for the average developer.
- I found error reporting/logging from within a TestNG test listener to
be failure-prone (swallowed exceptions, lack of knowledge how to use
TestNG logging)
- debugging listener code from within an IDE is harder than debugging an
IHookable (at least with my setup using Jetbrains IDEA; the TestNG
version included with the IDEA distro must exactly match the version
used to develop the listener, otherwise the debugger will show wrong
source code when stepping through the listener code).
Nevertheless, I'm looking forward to seeing an elaborate interception
mechanism in TestNG. If I may (partly) repeat my most intimate wishes
regarding this topic ;-)
- make TestNG capable of interpreting "Meta-Annotations", make @Test a
meta-annotation
- allow definition of custom annotations to mark a test class as a test
of a certain kind, using @Test meta annotation to tell TestNG the
annotation carrying this meta annotation will make a java class a TestNG
test class with special roles, e. g. @SeleniumTest
- associate this custom annotation with some custom java code, say
@InterceptorImpl(SeleniumSuiteInterceptor.class), which is called at
defined points in time (e. g. if custom annotation carries @BeforeMethod
meta annotation, the associated code will be called before each test
method; @BeforeSuite could be made a meta-annotation to call the
relevant code before the beginning of a suite and so on).
Best regards
Ansgar
I added a README to the project with a small example. More examples
how to use this rules are in the src/test folder.
About scoping of rules: If you need a higher level like group or
suite, then fields are not suited very well to do this.
I think in
this case the good old TestNG listeners would work directly. For
fields you can basically add discovery of all already present TestNG
Listeners. The main advantage of these rules is that they can have
state associated with the class under test, so in my opinion they are
not so interesting on a group or suite level.
Apologies for digging up an old thread. I would like to follow up where TestNG is planned to go with @Rule and RuleChain.