> The beforeSuite() problem is more tricky, and we
> dicussed it here not long
> ago (last 2-3 weeks I believe).
>
> If you have a beforeSuite() in a base class and two
> subclasses A and B, it
> will appear in both A and B, so TestNG will see it
> twice and therefore,
> register it twice.
>
> We were discussing the possibility to make exceptions
> to this rule for
> beforeSuite (and possibly, beforeTest and
> beforeClass), but I'm a bit
> reluctant to the idea because it breaks consistency
> and it makes the feature
> harder to describe (usually a design smell in my
> opinion).
I don't think this is the case at all. It runs before the suite. Period. It doesn't matter if 100 classes extend the exact same class. It should only ever run once. I just don't see any reason for it to run more than once in any circumstance. As far as I'm concerned, I don't EVER expect anything to run twice unless I ask it to. If I ask for beforeMethod I realize that it will be run before the method. But should I add checks to see that I doesn't run 3 times before the method? Or 10 for that matter?
It's an unexpected behavior, which in my opinion means it's a bug. I just can't seem to think of a reason why I would want a test or before* method to run an un-obvious number of times, ever.
>
> The workaround is to move these methods you only want
> TestNG to see once in
> a separate class. Unfortunately, it's not always
> possible or easy (these
> methods may want to share state with the others), so
> I'm still left on the
> fence on what the best way to solve this problem is.
>
> Here is a new idea: how about adding a unique
> attribute to @Test and
> @Configuration? If it is set to true, TestNG
> guarantees that this method
> will only be invoked once during the suite run...
>
> Just thinking out loud, haven't thought about the
> consequences yet...
>
> What do you think?
>
> --
> Cedric
As I said above, I just don't think that adding an attribute makes design sense. I've moved to your suggested fix and yes, it does work fine. But that seems to be a workaround to a deeper problem with TestNG's inspection of the test classes.
I'm finally getting back to using TestNG after a long hiatus because of severe problems I had with the inspection and the detection of test methods and the running order of the methods. It seems like TestNG has come a long way, but IIRC this was one of the most annoying problems.
As a user my impression was that I should just be able to mark a method beforeSuite and it would be run before the suite once and only once. As a developer I understand the reasoning behind why it's doing what it's doing. But I think that you can certainly agree that running a method more than once without, at the very least, erroring or warning the user about is a bad thing.
I hope I didn't come off as angry or arrogant here, if I did you have my sincerest apologies. TestNG is a tool that I see as something that will really really help me in my work and so I have a vested interest in seeing it be all that it can be and to be designed as well as it can be.
The next step after this, of course, is getting the Eclipse plugin to read the console data and provide the graphical feedback even for more... exotic testing setups. :)
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=7207&messageID=16190#16190