Where should the Guice createInjector go in a Testng driven automation framework

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

Where should the Guice createInjector go in a Testng driven automation framework

deepng
Hi

I am building a Automation framework which needs quite a few Api's to be used to execute every test scenario. I would like to use Guice for dependency injection of these API's. I have been unsuccessful till now. The dependency is not being injected into the field in my testClass. I am getting a NullPointerException when trying to use the API.

My sample code is like this:

@Guice(modules = {GuiceTestModules.class})
public class BasicAcceptanceTest() {

@Inject
Api1 api;

@Factory(dataProviderClass="abc", dataProvider="xyz")
public BasicAcceptanceTest(String data) {
}

@Test
public void test1() {
  api.doSomething();
}

}

public class GuiceTestModule extends AbstractModule {
  @Override
protected void configure() { bind(Api1.class); }
}

public class Api1 {

public Api1() {}

public void doSomething() {}

// Supporting methods.

}


--
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: Where should the Guice createInjector go in a Testng driven automation framework

Krishnan Mahadevan
Can you please create a reproducible sample that can be executed to reproduce the problem ?

Also please ensure that you are working with the latest released version of TestNG [ 6.14.2 as of today ]

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

On Wed, Feb 7, 2018 at 3:01 PM, deepng <[hidden email]> wrote:
Hi

I am building a Automation framework which needs quite a few Api's to be used to execute every test scenario. I would like to use Guice for dependency injection of these API's. I have been unsuccessful till now. The dependency is not being injected into the field in my testClass. I am getting a NullPointerException when trying to use the API.

My sample code is like this:

@Guice(modules = {GuiceTestModules.class})
public class BasicAcceptanceTest() {

@Inject
Api1 api;

@Factory(dataProviderClass="abc", dataProvider="xyz")
public BasicAcceptanceTest(String data) {
}

@Test
public void test1() {
  api.doSomething();
}

}

public class GuiceTestModule extends AbstractModule {
  @Override
protected void configure() { bind(Api1.class); }
}

public class Api1 {

public Api1() {}

public void doSomething() {}

// Supporting methods.

}


--
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: Where should the Guice createInjector go in a Testng driven automation framework

deepng
Hi Krishnan

Sorry, I forgot to update and close the thread.
I am creatingInstances of classes that have things being injected in them and this is working fine. I am using an abstraction layer where I am doing this.


On Thursday, February 8, 2018 at 8:03:11 PM UTC+5:30, Krishnan Mahadevan wrote:
Can you please create a reproducible sample that can be executed to reproduce the problem ?

Also please ensure that you are working with the latest released version of TestNG [ 6.14.2 as of today ]

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ <a href="http://wakened-cognition.blogspot.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;">http://wakened-cognition.blogspot.com/
My Technical Scribbings @ <a href="http://rationaleemotions.wordpress.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;">http://rationaleemotions.wordpress.com/

On Wed, Feb 7, 2018 at 3:01 PM, deepng <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="QoGD5_h7BwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">dee...@...> wrote:
Hi

I am building a Automation framework which needs quite a few Api's to be used to execute every test scenario. I would like to use Guice for dependency injection of these API's. I have been unsuccessful till now. The dependency is not being injected into the field in my testClass. I am getting a NullPointerException when trying to use the API.

My sample code is like this:

@Guice(modules = {GuiceTestModules.class})
public class BasicAcceptanceTest() {

@Inject
Api1 api;

@Factory(dataProviderClass="abc", dataProvider="xyz")
public BasicAcceptanceTest(String data) {
}

@Test
public void test1() {
  api.doSomething();
}

}

public class GuiceTestModule extends AbstractModule {
  @Override
protected void configure() { bind(Api1.class); }
}

public class Api1 {

public Api1() {}

public void doSomething() {}

// Supporting methods.

}


--
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="QoGD5_h7BwAJ" 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="QoGD5_h7BwAJ" 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.
Reply | Threaded
Open this post in threaded view
|

Re: Where should the Guice createInjector go in a Testng driven automation framework

Krishnan Mahadevan
That still doesn't tell anything in terms of where the problem could be.

Please create a sample that can be used to reproduce the issue using the latest released version of TestNG viz., 6.14.2

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

On Mon, Feb 19, 2018 at 2:11 PM, deepng <[hidden email]> wrote:
Hi Krishnan

Sorry, I forgot to update and close the thread.
I am creatingInstances of classes that have things being injected in them and this is working fine. I am using an abstraction layer where I am doing this.


On Thursday, February 8, 2018 at 8:03:11 PM UTC+5:30, Krishnan Mahadevan wrote:
Can you please create a reproducible sample that can be executed to reproduce the problem ?

Also please ensure that you are working with the latest released version of TestNG [ 6.14.2 as of today ]

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

On Wed, Feb 7, 2018 at 3:01 PM, deepng <[hidden email]> wrote:
Hi

I am building a Automation framework which needs quite a few Api's to be used to execute every test scenario. I would like to use Guice for dependency injection of these API's. I have been unsuccessful till now. The dependency is not being injected into the field in my testClass. I am getting a NullPointerException when trying to use the API.

My sample code is like this:

@Guice(modules = {GuiceTestModules.class})
public class BasicAcceptanceTest() {

@Inject
Api1 api;

@Factory(dataProviderClass="abc", dataProvider="xyz")
public BasicAcceptanceTest(String data) {
}

@Test
public void test1() {
  api.doSomething();
}

}

public class GuiceTestModule extends AbstractModule {
  @Override
protected void configure() { bind(Api1.class); }
}

public class Api1 {

public Api1() {}

public void doSomething() {}

// Supporting methods.

}


--
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.
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.

--
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.