@Test(groups = " foo") at class scope causes @BeforeClass to fire twice

classic Classic list List threaded Threaded
30 messages Options
12
Reply | Threaded
Open this post in threaded view
|

@Test(groups = " foo") at class scope causes @BeforeClass to fire twice

tarun3kumar

When I run this class

@Test( groups = "foo" )
public class TestTest {
    @BeforeGroups( "foo" )
    public void beforeGroups() {
        System.out.println( "beforeGroups" );
    }

    @Test()
    public void test() {
        System.out.println( "test" );
    }

}

whether with "-testclass TestTest" or "-testclass TestTest -groups foo", I get

beforeGroups
beforeGroups
test

If I declare the group on the test method rather than on the class, beforeGroups only runs once, but this is very tedious on real test classes. The behavior when the group is declared on the class doesn't seem useful -- is it a bug?

Thanks!
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=59312&messageID=116077#116077


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

Reply | Threaded
Open this post in threaded view
|

Re: @Test(groups = " foo") at class scope causes @BeforeClass to fire twice

tarun3kumar

Should have said that I see this with both 5.4 and the current source from svn (which builds a jar versioned 5.5 beta.)
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=59312&messageID=116080#116080


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

Reply | Threaded
Open this post in threaded view
|

Re: @Test(groups = " foo") at class scope causes @BeforeClass to fire twice

Cédric Beust ♔
In reply to this post by tarun3kumar
Hi Dave, and thanks for the report.

I just fixed the bug, please try:

http://testng.org/testng-5.5beta-jdk15.jar

and let me know how it works for you!

--
Cedric



On 1/17/07, Dave Schweisguth <[hidden email]> wrote:

When I run this class

@Test( groups = "foo" )
public class TestTest {
    @BeforeGroups( "foo" )
    public void beforeGroups() {
        System.out.println( "beforeGroups" );
    }

    @Test()
    public void test() {
        System.out.println ( "test" );
    }

}

whether with "-testclass TestTest" or "-testclass TestTest -groups foo", I get

beforeGroups
beforeGroups
test

If I declare the group on the test method rather than on the class, beforeGroups only runs once, but this is very tedious on real test classes. The behavior when the group is declared on the class doesn't seem useful -- is it a bug?

Thanks!
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=59312&messageID=116077#116077


--
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 [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: @Test(groups = " foo") at class scope causes @BeforeClass to fire twice

Alexandru Popescu ☀
In reply to this post by tarun3kumar

On 1/18/07, Dave Schweisguth <[hidden email]> wrote:
>
> Should have said that I see this with both 5.4 and the current source from svn (which builds a jar versioned 5.5 beta.)

Thanks for the report. Looking into it now.

./alex
--
.w( the_mindstorm )p.
  TestNG co-founder
EclipseTestNG Creator

> ---------------------------------------------------------------------
> Posted via Jive Forums
> http://forums.opensymphony.com/thread.jspa?threadID=59312&messageID=116080#116080
>
>
> >
>

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

Reply | Threaded
Open this post in threaded view
|

Re: @Test(groups = " foo") at class scope causes

tarun3kumar
In reply to this post by Cédric Beust ♔

That did it. Thanks!

There is a related problem with the Idea test runner; I'll follow up there.
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=59312&messageID=116117#116117


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

Reply | Threaded
Open this post in threaded view
|

Re: @Test(groups = " foo") at class scope causes

Mark Derricutt
You've hit another issue with the plugin then?

Mark

On 1/18/07, Dave Schweisguth <[hidden email]> wrote:

There is a related problem with the Idea test runner; I'll follow up there.


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

Reply | Threaded
Open this post in threaded view
|

Re: @Test(groups = " foo") at class scope causes

tarun3kumar

I think so -- I'll log a bug or post or something as soon as I can describe it clearly.
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=59312&messageID=116271#116271


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

Reply | Threaded
Open this post in threaded view
|

Re: @Test(groups = " foo") at class scope causes

tarun3kumar

After upgrading the pluging to the newest testng, @BeforeGroups still runs twice before a test when one runs a group. Let's take this to http://code.google.com/p/testng-idea/issues/detail?id=12&can=2&q=
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=59312&messageID=116296#116296


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

Reply | Threaded
Open this post in threaded view
|

Re: @Test(groups = " foo") at class scope causes

Mark Derricutt
On 1/19/07, Dave Schweisguth <[hidden email]> wrote:

After upgrading the pluging to the newest testng, @BeforeGroups still runs twice before a test when one runs a group. Let's take this to http://code.google.com/p/testng-idea/issues/detail?id=12&can=2&q=


Interesting - I'll update my TestNG build and see if I see this.  If you create a suite.xml file that runs a group and run that from the command line (as opposed to -groups) do you still the correct or duplicate behaviour?

Mark


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

Reply | Threaded
Open this post in threaded view
|

Re: @Test(groups = " foo") at class scope causes

Cédric Beust ♔
In reply to this post by tarun3kumar
Dave, can you make sure you are using the right jar file?  (invoke your test from the command line)

--
Cedric


On 1/18/07, Dave Schweisguth <[hidden email]> wrote:

After upgrading the pluging to the newest testng, @BeforeGroups still runs twice before a test when one runs a group. Let's take this to http://code.google.com/p/testng-idea/issues/detail?id=12&can=2&q=
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=59312&messageID=116296#116296







--
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 [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: @Test(groups = " foo") at class scope causes

tarun3kumar

Sorry for clouding the issue, Cedric -- yes, running on the command line shows that the bug in TestNG is fixed. That's what I did before I said "That did it. Thanks!". Subsequent comments in this thread are about a bug in the Idea plugin which has symptoms similar to the one you fixed in TestNG. Check http://code.google.com/p/testng-idea/issues/detail?id=12&can=2&q= for details -- as you can see there, the command line baseline is working great. Thanks again!
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=59312&messageID=116324#116324


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

Reply | Threaded
Open this post in threaded view
|

Re: @Test(groups = " foo") at class scope causes

Cédric Beust ♔
Ok, you got me confused there for a minute :-)

It's probably just a matter of getting the IDEA plug-in to recognize the new jar, I'm sure Mark knows what to do.

--
Cedric


On 1/18/07, Dave Schweisguth <[hidden email]> wrote:

Sorry for clouding the issue, Cedric -- yes, running on the command line shows that the bug in TestNG is fixed. That's what I did before I said "That did it. Thanks!". Subsequent comments in this thread are about a bug in the Idea plugin which has symptoms similar to the one you fixed in TestNG. Check http://code.google.com/p/testng-idea/issues/detail?id=12&can=2&q= for details -- as you can see there, the command line baseline is working great. Thanks again!
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=59312&messageID=116324#116324


--
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 [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: @Test(groups = " foo") at class scope causes

Mark Derricutt
In reply to this post by tarun3kumar
Whats in the suite.xml that the IDEA plugin generates?

You'll fine the file in ~/.IntelliJIdea60/system (and mentioned at the end of the command line in the IDEA run window).

I'll take a look at the problem later tonight when I get home from work...

On 1/19/07, Dave Schweisguth <[hidden email]> wrote:

Sorry for clouding the issue, Cedric -- yes, running on the command line shows that the bug in TestNG is fixed. That's what I did before I said "That did it. Thanks!". Subsequent comments in this thread are about a bug in the Idea plugin which has symptoms similar to the one you fixed in TestNG. Check http://code.google.com/p/testng-idea/issues/detail?id=12&can=2&q= for details -- as you can see there, the command line baseline is working


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

Reply | Threaded
Open this post in threaded view
|

Re: @Test(groups = " foo") at class scope causes

Mark Derricutt
I just tested this here, the problem is that the IDEA plugin scans the project for all test classes in the classpath, which include both BaseTest and TestTest.  The @BeforeGroups annotation on the BaseTest is inherited in TestTest - so theres in effect TWO copies of @BeforeGroups, hence you see it printed twice.

This is known/common problem of using such methods on superclasses - its not really a bug, but unexpected behaviour.

Cedric - would a work around to this problem (which has been mentioned before a few times) be adding an optional parameter to the annotation which tells TestNG to ignore it if its found in a sub-class?

Something like:

  @BeforeGroups(groups="foo", allowInherited = false)

I'm not really sure what you'd call the parameter, allowInherited comes to mind but doesn't really sit well.  I'm more inclined to just say "Put your @BeforeGroups in its own class and live with it..." rather than add this new hack..

Mark

On 1/19/07, Mark Derricutt <[hidden email]> wrote:
Whats in the suite.xml that the IDEA plugin generates?

You'll fine the file in ~/.IntelliJIdea60/system (and mentioned at the end of the command line in the IDEA run window).

I'll take a look at the problem later tonight when I get home from work...


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

Reply | Threaded
Open this post in threaded view
|

Re: @Test(groups = " foo") at class scope causes

Cédric Beust ♔
Hi Mark,

On 1/19/07, Mark Derricutt <[hidden email]> wrote:
I just tested this here, the problem is that the IDEA plugin scans the project for all test classes in the classpath, which include both BaseTest and TestTest.  The @BeforeGroups annotation on the BaseTest is inherited in TestTest - so theres in effect TWO copies of @BeforeGroups, hence you see it printed twice.

This is known/common problem of using such methods on superclasses - its not really a bug, but unexpected behaviour.

Cedric - would a work around to this problem (which has been mentioned before a few times) be adding an optional parameter to the annotation which tells TestNG to ignore it if its found in a sub-class?

Something like:

  @BeforeGroups(groups="foo", allowInherited = false)

I'm not really sure what you'd call the parameter, allowInherited comes to mind but doesn't really sit well.  I'm more inclined to just say "Put your @BeforeGroups in its own class and live with it..." rather than add this new hack..

I don't think I like the idea of adding  an annotation to TestNG just for an IDE workaround...

Couldn't you exclude these classes yourself?  Do a first pass that collects all the classes in the project and then a second one to eliminate all the classes that are bases of test classes?

--
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 [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: @Test(groups = " foo") at class scope causes

tarun3kumar
In reply to this post by Mark Derricutt

> Whats in the suite.xml that the IDEA plugin generates?

Looks like you beat me to it ... but let me know if you need any more info.
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=59312&messageID=116537#116537


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

Reply | Threaded
Open this post in threaded view
|

Re: @Test(groups = " foo") at class scope causes

Mark Derricutt
In reply to this post by Cédric Beust ♔
On 1/20/07, C�dric Beust <[hidden email]> wrote:
I don't think I like the idea of adding  an annotation to TestNG just for an IDE workaround...

Yep - like I said, the idea was a somewhat hack thought late at night.

Couldn't you exclude these classes yourself?  Do a first pass that collects all the classes in the project and then a second one to eliminate all the classes that are bases of test classes?

I suppose so, I wonder if theres any cases were you'd actually want this behavior thou.  I seem to recall in one of the earlier threads that related to this the solution was to make the BaseTest class abstract?

Mark


--
It was not the presence of God that formed me, but his absence which broke me.

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

Reply | Threaded
Open this post in threaded view
|

Re: @Test(groups = " foo") at class scope causes

tarun3kumar

Making BaseTest abstract does fix the test case, but doesn't fix the real tests that I'm trying to get to work in TestNG. Actually the real base class has always been abstract; BaseTest was concrete only by mistake. I'll have to see if I can sort out what else is different between the real and toy tests. Stay tuned ...
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=59312&messageID=117324#117324


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

Reply | Threaded
Open this post in threaded view
|

Re: @Test(groups = " foo") at class scope causes

Mark Derricutt
Interestingly, I tried running it with a suite.xml:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Custom suite">
  <test verbose="1" name="untitled" annotations="JDK">
    <groups>
      <run>
        <include name="foo"/>
      </run>
    </groups>
    <classes>
      <class name="TestTest"/>
    </classes>
  </test>
</suite>

This still gave me two runs of the @BeforeGroup - so changing the plugin to not include BaseTest wouldn't really change much.  Mmmm, unless I'm still missing something.

On 1/23/07, Dave Schweisguth <[hidden email]> wrote:

Making BaseTest abstract does fix the test case, but doesn't fix the real tests that I'm trying to get to work in TestNG. Actually the real base class has always been abstract; BaseTest was concrete only by mistake. I'll have to see if I can sort out what else is different between the real and toy tests. Stay tuned ...


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

Reply | Threaded
Open this post in threaded view
|

Re: @Test(groups = " foo") at class scope causes

tarun3kumar
In reply to this post by tarun3kumar

Ah, my real tests still have the problem because even though the real base class is abstract, it has more than one concrete subclass. Would you expect an @BeforeGroups method to run once for each concrete subclass? If it did I don't see how else one could initialize a field once per group. (My real @BeforeGroups initializes a protected static field; an @AfterGroups cleans it up.) Surely this must be an important use case for @Before/AfterGroups. What do you think?

(Incidentally, I'm not averse to pitching in -- but it seems like we need to agree on the correct behavior first.)

I updated http://code.google.com/p/testng-idea/issues/detail?id=12&can=2&q= for good measure.
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=59312&messageID=117346#117346


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

12