Run test factories after @BeforeTest callback

150 views
Skip to first unread message

Wujek Srujek

unread,
Feb 18, 2010, 3:24:57 PM2/18/10
to testng...@googlegroups.com
Hi Cedric,

I have a class that has a @BeforeTest and it initializes some stuff for all tests in the test set. Then, I have another class that contains the @Factory annotation. What I noticed is that the factory method is invoked before the @BeforeTest method, and even though it supports injecting ITestContext, the context is not initialized, as the initialization method is invoked later. Is there a way to make sure that the @BeforeTest method is called before all factory methods?

Regards,
Wujek

Cédric Beust ♔

unread,
Feb 18, 2010, 3:39:53 PM2/18/10
to testng...@googlegroups.com
On Thu, Feb 18, 2010 at 12:24 PM, Wujek Srujek <wujek....@googlemail.com> wrote:
Hi Cedric,

I have a class that has a @BeforeTest and it initializes some stuff for all tests in the test set. Then, I have another class that contains the @Factory annotation. What I noticed is that the factory method is invoked before the @BeforeTest method, and even though it supports injecting ITestContext, the context is not initialized, as the initialization method is invoked later. Is there a way to make sure that the @BeforeTest method is called before all factory methods?

No:  TestNG needs to run all the factories first in order to get the complete list of the test methods to run.  And then it runs these test methods.

--
Cédric


Wujek Srujek

unread,
Feb 18, 2010, 4:04:01 PM2/18/10
to testng...@googlegroups.com
Hi Cedric,

thanks.
That's fine, I found another way of doing what I need to do. Actually, I am creating the class that has the @BeforeTest callback in a factory, and the test themselves are plain TestNG created tests. This is possible as the custom stuff that I need injected (via CDI with Weld SE) will be shared by all tests, so I can initialize it in @BeforeTest, set as parameter and look up in the tests.
Thanks for your answers.

Regards,
Wujek

2010/2/18 Cédric Beust ♔ <cbe...@google.com>
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

Cédric Beust ♔

unread,
Feb 18, 2010, 4:10:53 PM2/18/10
to testng...@googlegroups.com
Wujek,

That's good to hear, although not surprising :-)

You had a catch-22 problem here:  you want to run tests but in order for these tests to be initialized, you need to... run tests.

There had to be a solution out of this, glad you found it.

--
Cedric


On Thu, Feb 18, 2010 at 1:04 PM, Wujek Srujek <wujek....@googlemail.com> wrote:
Hi Cedric,

thanks.
That's fine, I found another way of doing what I need to do. Actually, I am creating the class that has the @BeforeTest callback in a factory, and the test themselves are plain TestNG created tests. This is possible as the custom stuff that I need injected (via CDI with Weld SE) will be shared by all tests, so I can initialize it in @BeforeTest, set as parameter and look up in the tests.
Thanks for your answers.

Regards,
Wujek

2010/2/18 Cédric Beust ♔ <cbe...@google.com>


On Thu, Feb 18, 2010 at 12:24 PM, Wujek Srujek <wujek....@googlemail.com> wrote:
Hi Cedric,

I have a class that has a @BeforeTest and it initializes some stuff for all tests in the test set. Then, I have another class that contains the @Factory annotation. What I noticed is that the factory method is invoked before the @BeforeTest method, and even though it supports injecting ITestContext, the context is not initialized, as the initialization method is invoked later. Is there a way to make sure that the @BeforeTest method is called before all factory methods?

No:  TestNG needs to run all the factories first in order to get the complete list of the test methods to run.  And then it runs these test methods.

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

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



--
Cédric


Reply all
Reply to author
Forward
0 new messages