@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);
}
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?
> 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...@gmail.com> 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...@google.com> 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
On Tue, Nov 3, 2009 at 7:13 PM, shay <matas...@gmail.com> 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...@google.com> 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...@gmail.com> 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...@google.com> 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