cant get @beforegroups to work

View: New views
6 Messages — Rating Filter:   Alert me  

cant get @beforegroups to work

by Shay Matasaro :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi All,

before groups always runs after the test method

here is my code:

@Test(groups={"NewUser"})
public class RegisterCommandTest {

        Logger l = LoggerFactory.getLogger(this.getClass());

        @BeforeClass
        public void beforeClass(ITestContext itc)
        {
                l.debug("getting injector from context");
                m_inj =  (Injector) itc.getAttribute("injector");
                m_inj.injectMembers(this);

        }
        public void testExecute(ITestContext itc) throws Exception {

                l.debug("do somthing");
        }
}

public class BeforeGroupTest {

        Logger l = LoggerFactory.getLogger(this.getClass());

        @BeforeGroups(groups = { "NewUser"},value={ "NewUser"})
        public void preNewUser(ITestContext itc) {
                l.debug("perfroming pre groups init");
                m_inj = Guice.createInjector(new JUnitModule(), new RequestModule(),
                                new GenericModule(), new SecurityModule());
                itc.setAttribute("injector", m_inj);
        }
}

I am using Maven.


any advice,
Shay

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


Re: cant get @beforegroups to work

by Cédric Beust ♔ :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I tried your code and it behaves as expected for me:

BEFORECLASS getting injector from context
BEFOREGROUPS perfroming pre groups init
TESTEXECUTE do somthing

===============================================
Single
Total tests run: 1, Failures: 0, Skips: 0
===============================================

Note that I ran it directly (without Maven).  Can you try without Maven as well?

--
Cédric




On Fri, Oct 30, 2009 at 6:59 PM, shay <matasaro@...> wrote:

Hi All,

before groups always runs after the test method

here is my code:

@Test(groups={"NewUser"})
public class RegisterCommandTest {

       Logger l = LoggerFactory.getLogger(this.getClass());

       @BeforeClass
       public void beforeClass(ITestContext itc)
       {
               l.debug("getting injector from context");
               m_inj =  (Injector) itc.getAttribute("injector");
               m_inj.injectMembers(this);

       }
       public void testExecute(ITestContext itc) throws Exception {

               l.debug("do somthing");
       }
}

public class BeforeGroupTest {

       Logger l = LoggerFactory.getLogger(this.getClass());

       @BeforeGroups(groups = { "NewUser"},value={ "NewUser"})
       public void preNewUser(ITestContext itc) {
               l.debug("perfroming pre groups init");
               m_inj = Guice.createInjector(new JUnitModule(), new RequestModule(),
                               new GenericModule(), new SecurityModule());
               itc.setAttribute("injector", m_inj);
       }
}

I am using Maven.


any advice,
Shay






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


Re: cant get @beforegroups to work

by Shay Matasaro :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi Cedric,

Thank you for you time.

Shouldn't  BEFOREGROUPS run before BEFORECLASS , as all methods of the
class belong to the group?

if @beforeclass is executed before @beforegroup  , how do you
recommend that i initiate the injector?

Thanks,
Shay


On Oct 31, 7:41 pm, Cédric Beust ♔ <cbe...@...> wrote:

> Hi,
>
> I tried your code and it behaves as expected for me:
>
> BEFORECLASS getting injector from context
> BEFOREGROUPS perfroming pre groups init
> TESTEXECUTE do somthing
>
> ===============================================
> Single
> Total tests run: 1, Failures: 0, Skips: 0
> ===============================================
>
> Note that I ran it directly (without Maven).  Can you try without Maven as
> well?
>
> --
> Cédric
>
> On Fri, Oct 30, 2009 at 6:59 PM, shay <matas...@...> wrote:
>
> > Hi All,
>
> > before groups always runs after the test method
>
> > here is my code:
>
> > @Test(groups={"NewUser"})
> > public class RegisterCommandTest {
>
> >        Logger l = LoggerFactory.getLogger(this.getClass());
>
> >        @BeforeClass
> >        public void beforeClass(ITestContext itc)
> >        {
> >                l.debug("getting injector from context");
> >                m_inj =  (Injector) itc.getAttribute("injector");
> >                m_inj.injectMembers(this);
>
> >        }
> >        public void testExecute(ITestContext itc) throws Exception {
>
> >                l.debug("do somthing");
> >        }
> > }
>
> > public class BeforeGroupTest {
>
> >        Logger l = LoggerFactory.getLogger(this.getClass());
>
> >        @BeforeGroups(groups = { "NewUser"},value={ "NewUser"})
> >        public void preNewUser(ITestContext itc) {
> >                l.debug("perfroming pre groups init");
> >                m_inj = Guice.createInjector(new JUnitModule(), new
> > RequestModule(),
> >                                new GenericModule(), new SecurityModule());
> >                itc.setAttribute("injector", m_inj);
> >        }
> > }
>
> > I am using Maven.
>
> > any advice,
> > Shay
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng-users@...
To unsubscribe from this group, send email to testng-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: cant get @beforegroups to work

by Cédric Beust ♔ :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Shay,

There is no particular reason why @BeforeClass should run before @BeforeGroups or the other way around, so you should not rely on this.  I understand it would make sense in your situation but in other scenarios, @BeforeClass methods have to run before @BeforeGroups.

For example, consider:

class A
  f (group "aa")
  i (group "bb")

class B
  h (group "aa")

If I run group "bb" and "aa", you would see the following order:

beforeClass A
beforeGroups bb
A.i
beforeGroups aa
A.f
beforeClass B
B.h

Back to your problem.

I don't see your m_inj field defined in any of your classes, so I'm guessing it's static or inherited from some base class?

This field looks global enough that you might want to initialize it in a @BeforeSuite method.  Would this solve your problem?

--
Cédric




On Sat, Oct 31, 2009 at 4:47 PM, shay <matasaro@...> wrote:

Hi Cedric,

Thank you for you time.

Shouldn't  BEFOREGROUPS run before BEFORECLASS , as all methods of the
class belong to the group?

if @beforeclass is executed before @beforegroup  , how do you
recommend that i initiate the injector?

Thanks,
Shay


On Oct 31, 7:41 pm, Cédric Beust ♔ <cbe...@...> wrote:
> Hi,
>
> I tried your code and it behaves as expected for me:
>
> BEFORECLASS getting injector from context
> BEFOREGROUPS perfroming pre groups init
> TESTEXECUTE do somthing
>
> ===============================================
> Single
> Total tests run: 1, Failures: 0, Skips: 0
> ===============================================
>
> Note that I ran it directly (without Maven).  Can you try without Maven as
> well?
>
> --
> Cédric
>
> On Fri, Oct 30, 2009 at 6:59 PM, shay <matas...@...> wrote:
>
> > Hi All,
>
> > before groups always runs after the test method
>
> > here is my code:
>
> > @Test(groups={"NewUser"})
> > public class RegisterCommandTest {
>
> >        Logger l = LoggerFactory.getLogger(this.getClass());
>
> >        @BeforeClass
> >        public void beforeClass(ITestContext itc)
> >        {
> >                l.debug("getting injector from context");
> >                m_inj =  (Injector) itc.getAttribute("injector");
> >                m_inj.injectMembers(this);
>
> >        }
> >        public void testExecute(ITestContext itc) throws Exception {
>
> >                l.debug("do somthing");
> >        }
> > }
>
> > public class BeforeGroupTest {
>
> >        Logger l = LoggerFactory.getLogger(this.getClass());
>
> >        @BeforeGroups(groups = { "NewUser"},value={ "NewUser"})
> >        public void preNewUser(ITestContext itc) {
> >                l.debug("perfroming pre groups init");
> >                m_inj = Guice.createInjector(new JUnitModule(), new
> > RequestModule(),
> >                                new GenericModule(), new SecurityModule());
> >                itc.setAttribute("injector", m_inj);
> >        }
> > }
>
> > I am using Maven.
>
> > any advice,
> > Shay





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


Re: cant get @beforegroups to work

by Shay Matasaro :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi Cedric,

thanks that makes sense.

up until i have been avoiding an XML config , by using only
annotations . is there a way to use suites without an xml?

Thanks,
Shay

On Nov 1, 10:51 am, Cédric Beust ♔ <cbe...@...> wrote:

> Hi Shay,
>
> There is no particular reason why @BeforeClass should run before
> @BeforeGroups or the other way around, so you should not rely on this.  I
> understand it would make sense in your situation but in other scenarios,
> @BeforeClass methods have to run before @BeforeGroups.
>
> For example, consider:
>
> class A
>   f (group "aa")
>   i (group "bb")
>
> class B
>   h (group "aa")
>
> If I run group "bb" and "aa", you would see the following order:
>
> beforeClass A
> beforeGroups bb
> A.i
> beforeGroups aa
> A.f
> beforeClass B
> B.h
>
> Back to your problem.
>
> I don't see your m_inj field defined in any of your classes, so I'm guessing
> it's static or inherited from some base class?
>
> This field looks global enough that you might want to initialize it in a
> @BeforeSuite method.  Would this solve your problem?
>
> --
> Cédric
>
> On Sat, Oct 31, 2009 at 4:47 PM, shay <matas...@...> wrote:
>
> > Hi Cedric,
>
> > Thank you for you time.
>
> > Shouldn't  BEFOREGROUPS run before BEFORECLASS , as all methods of the
> > class belong to the group?
>
> > if @beforeclass is executed before @beforegroup  , how do you
> > recommend that i initiate the injector?
>
> > Thanks,
> > Shay
>
> > On Oct 31, 7:41 pm, Cédric Beust ♔ <cbe...@...> wrote:
> > > Hi,
>
> > > I tried your code and it behaves as expected for me:
>
> > > BEFORECLASS getting injector from context
> > > BEFOREGROUPS perfroming pre groups init
> > > TESTEXECUTE do somthing
>
> > > ===============================================
> > > Single
> > > Total tests run: 1, Failures: 0, Skips: 0
> > > ===============================================
>
> > > Note that I ran it directly (without Maven).  Can you try without Maven
> > as
> > > well?
>
> > > --
> > > Cédric
>
> > > On Fri, Oct 30, 2009 at 6:59 PM, shay <matas...@...> wrote:
>
> > > > Hi All,
>
> > > > before groups always runs after the test method
>
> > > > here is my code:
>
> > > > @Test(groups={"NewUser"})
> > > > public class RegisterCommandTest {
>
> > > >        Logger l = LoggerFactory.getLogger(this.getClass());
>
> > > >        @BeforeClass
> > > >        public void beforeClass(ITestContext itc)
> > > >        {
> > > >                l.debug("getting injector from context");
> > > >                m_inj =  (Injector) itc.getAttribute("injector");
> > > >                m_inj.injectMembers(this);
>
> > > >        }
> > > >        public void testExecute(ITestContext itc) throws Exception {
>
> > > >                l.debug("do somthing");
> > > >        }
> > > > }
>
> > > > public class BeforeGroupTest {
>
> > > >        Logger l = LoggerFactory.getLogger(this.getClass());
>
> > > >        @BeforeGroups(groups = { "NewUser"},value={ "NewUser"})
> > > >        public void preNewUser(ITestContext itc) {
> > > >                l.debug("perfroming pre groups init");
> > > >                m_inj = Guice.createInjector(new JUnitModule(), new
> > > > RequestModule(),
> > > >                                new GenericModule(), new
> > SecurityModule());
> > > >                itc.setAttribute("injector", m_inj);
> > > >        }
> > > > }
>
> > > > I am using Maven.
>
> > > > any advice,
> > > > Shay
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng-users@...
To unsubscribe from this group, send email to testng-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: cant get @beforegroups to work

by Cédric Beust ♔ :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Shay,

If you don't use an XML file, TestNG will create its own suite to wrap your tests, so @BeforeSuite should work for you anyway.

I'm betting that you will end up having to use an XML file as your tests grow, though...

--
Cédric



On Tue, Nov 3, 2009 at 7:13 PM, shay <matasaro@...> wrote:

Hi Cedric,

thanks that makes sense.

up until i have been avoiding an XML config , by using only
annotations . is there a way to use suites without an xml?

Thanks,
Shay

On Nov 1, 10:51 am, Cédric Beust ♔ <cbe...@...> wrote:
> Hi Shay,
>
> There is no particular reason why @BeforeClass should run before
> @BeforeGroups or the other way around, so you should not rely on this.  I
> understand it would make sense in your situation but in other scenarios,
> @BeforeClass methods have to run before @BeforeGroups.
>
> For example, consider:
>
> class A
>   f (group "aa")
>   i (group "bb")
>
> class B
>   h (group "aa")
>
> If I run group "bb" and "aa", you would see the following order:
>
> beforeClass A
> beforeGroups bb
> A.i
> beforeGroups aa
> A.f
> beforeClass B
> B.h
>
> Back to your problem.
>
> I don't see your m_inj field defined in any of your classes, so I'm guessing
> it's static or inherited from some base class?
>
> This field looks global enough that you might want to initialize it in a
> @BeforeSuite method.  Would this solve your problem?
>
> --
> Cédric
>
> On Sat, Oct 31, 2009 at 4:47 PM, shay <matas...@...> wrote:
>
> > Hi Cedric,
>
> > Thank you for you time.
>
> > Shouldn't  BEFOREGROUPS run before BEFORECLASS , as all methods of the
> > class belong to the group?
>
> > if @beforeclass is executed before @beforegroup  , how do you
> > recommend that i initiate the injector?
>
> > Thanks,
> > Shay
>
> > On Oct 31, 7:41 pm, Cédric Beust ♔ <cbe...@...> wrote:
> > > Hi,
>
> > > I tried your code and it behaves as expected for me:
>
> > > BEFORECLASS getting injector from context
> > > BEFOREGROUPS perfroming pre groups init
> > > TESTEXECUTE do somthing
>
> > > ===============================================
> > > Single
> > > Total tests run: 1, Failures: 0, Skips: 0
> > > ===============================================
>
> > > Note that I ran it directly (without Maven).  Can you try without Maven
> > as
> > > well?
>
> > > --
> > > Cédric
>
> > > On Fri, Oct 30, 2009 at 6:59 PM, shay <matas...@...> wrote:
>
> > > > Hi All,
>
> > > > before groups always runs after the test method
>
> > > > here is my code:
>
> > > > @Test(groups={"NewUser"})
> > > > public class RegisterCommandTest {
>
> > > >        Logger l = LoggerFactory.getLogger(this.getClass());
>
> > > >        @BeforeClass
> > > >        public void beforeClass(ITestContext itc)
> > > >        {
> > > >                l.debug("getting injector from context");
> > > >                m_inj =  (Injector) itc.getAttribute("injector");
> > > >                m_inj.injectMembers(this);
>
> > > >        }
> > > >        public void testExecute(ITestContext itc) throws Exception {
>
> > > >                l.debug("do somthing");
> > > >        }
> > > > }
>
> > > > public class BeforeGroupTest {
>
> > > >        Logger l = LoggerFactory.getLogger(this.getClass());
>
> > > >        @BeforeGroups(groups = { "NewUser"},value={ "NewUser"})
> > > >        public void preNewUser(ITestContext itc) {
> > > >                l.debug("perfroming pre groups init");
> > > >                m_inj = Guice.createInjector(new JUnitModule(), new
> > > > RequestModule(),
> > > >                                new GenericModule(), new
> > SecurityModule());
> > > >                itc.setAttribute("injector", m_inj);
> > > >        }
> > > > }
>
> > > > I am using Maven.
>
> > > > any advice,
> > > > Shay





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