Guice & ITestContext

38 views
Skip to first unread message

Vinoth Selvaraj

unread,
May 7, 2018, 6:32:42 PM5/7/18
to testng-users
I use TestNG and Guice and love it so far!

I would like to know at which phase it actually injects. Is it before the @BeforeClass? I would like to inject instances depends on certain conditions/parameters of my test. 

@Inject
private Car car;

My test parameter from suite xml will have different parameters like Audi,BMW,Honda.

So, it depends on the value i would like to inject the specific instance.

Car car = new Audi();
Car car = new BMW();

In my guiceModule, I would like to access ITestContext instance somehow so that I could inject specific instance of Car implementation in my test.

Is there any clean way to do this?

Cédric Beust ♔

unread,
May 7, 2018, 7:14:03 PM5/7/18
to testng...@googlegroups.com
The injection is performed by Guice, so just after instantiation.

I think what you are trying to do is not really injection and probably better addressed with a data provider.


-- 
Cédric


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users+unsubscribe@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

Vinoth Selvaraj

unread,
May 7, 2018, 10:54:09 PM5/7/18
to testng-users
Thanks. That was a simple example to show that I would like to inject different instance depends on a condition.

I think I should inject the Factory Provider instead of trying inject the actual instance




On Monday, May 7, 2018 at 6:14:03 PM UTC-5, Cédric Beust ♔ wrote:
The injection is performed by Guice, so just after instantiation.

I think what you are trying to do is not really injection and probably better addressed with a data provider.


-- 
Cédric


On Mon, May 7, 2018 at 3:32 PM, Vinoth Selvaraj <vino...@gmail.com> wrote:
I use TestNG and Guice and love it so far!

I would like to know at which phase it actually injects. Is it before the @BeforeClass? I would like to inject instances depends on certain conditions/parameters of my test. 

@Inject
private Car car;

My test parameter from suite xml will have different parameters like Audi,BMW,Honda.

So, it depends on the value i would like to inject the specific instance.

Car car = new Audi();
Car car = new BMW();

In my guiceModule, I would like to access ITestContext instance somehow so that I could inject specific instance of Car implementation in my test.

Is there any clean way to do this?

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages