Guice & ITestContext

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

Guice & ITestContext

Vinoth Selvaraj
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Guice & ITestContext

Cédric Beust ♔-2
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 <[hidden email]> 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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Guice & ITestContext

Vinoth Selvaraj
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

https://google.github.io/guice/api-docs/3.0/javadoc/com/google/inject/assistedinject/FactoryProvider.html



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 <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="mqOPL7UPCwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">vino...@...> 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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="mqOPL7UPCwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="mqOPL7UPCwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@....
Visit this group at <a href="https://groups.google.com/group/testng-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;">https://groups.google.com/group/testng-users.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.