Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Guice Constructor Injection with TestNG
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jeff  
View profile  
 More options Oct 6 2011, 12:29 pm
From: Jeff <predato...@gmail.com>
Date: Thu, 6 Oct 2011 10:29:36 -0600
Local: Thurs, Oct 6 2011 12:29 pm
Subject: Re: [testng-users] Guice Constructor Injection with TestNG

...not trying to be too big of a pain, but any thoughts/discussion on
possible ways to handle this?

One specific question that I still don't know ... if my class is
singleThreaded=true, is there a guarantee that the @BeforeClass method will
be called on the same thread as all the other @Test methods in the class?

If so, I think I just need to inject the resouces in the @BeforeClass method
with a custom Guice Module that handles detecting/retrieving the resource
based on thread.

Has anyone else wrestled with this?  I'm curious how you handle
thread-specific resources.

On Wed, Oct 5, 2011 at 11:38 AM, Jeff <predato...@gmail.com> wrote:
> The resource in question is a Selenium2 WebDriver object.

> The @Tests in my test class(es) represent a sequence of steps in a
> workflow/use case that must be executed in a pre-determined order using the
> same WebDriver object (browser window).  I've set each class to run
> 'singleThreaded=true' and use the dependsOnMethods to chain the @Test
> methods *(sidenote: is there a less maintenance heavy way to chain
> dependent test cases --- say alphabetically by name?)*.

> In the past, I've used two approaches:

>    1. Each class creates it's own WebDriver object, where the class was
>    responsible for the setup/teardown of the driver (which launches a web
>    browser).  This process is fairly expensive to do for each class.
>    2. Implement a custom WebDriver factory that would return the driver
>    for the current thread Id (called in @BeforeClass).  This seemed to work
>    okay for the limited time I used it.

> I'm looking to learn/try Guice/DI to inject the correct WebDriver object
> into to each class based on test thread and *only* the test threads (rules
> out constructor injection?).  When a class runs, I'd like to inject the
> correct WebDriver based on the test thread (somehow).  This is what I'm
> still learning/trying to work out.

> Hopefully that made sense.

> 2011/10/5 Cédric Beust ♔ <ced...@beust.com>

>> Hi Jeff,

>> I'm not sure I see the problem with injecting in a multithreaded context
>> as long as you pay attention to how you access the injected resource...

>> But maybe I'm missing something?

>> --
>> Cédric

>> On Tue, Oct 4, 2011 at 3:53 PM, Jeff <predato...@gmail.com> wrote:

>>> Guice "Best Practices" recommends using constructor injection to create
>>> "immutable" objects.  This is great until the test class needs resources
>>> that are tied to TestNG test threads (unless I'm missing something).

>>> If I create a custom Guice Module/Provider to handle injecting
>>> MyPerThreadResource, I could use @Test method injection:

>>> @Test
>>> @Inject
>>> public void test1(MyPerThreadResource resource) {
>>>    // use resource
>>> }

>>> Or, similarly @BeforeClass method injection (assumes the class is marked
>>> as @Test(singleThreaded=true) ):

>>> @BeforeClass
>>> @Inject
>>> public void beforeClass(MyThreadResource resource) {
>>>    this.resource = resource;
>>> }

>>> I considered Field Injection at the test class level, but I don't
>>> think the Test Classes are being instantiated on the same thread used to run
>>> them.

>>> Is there a better way to tie resources to the test threads (particularly
>>> using DI)?

>>> --

>>> Jeff Vincent
>>> predato...@gmail.com
>>> See my LinkedIn profile at:
>>> http://www.linkedin.com/in/rjeffreyvincent
>>> I ♥ DropBox <http://db.tt/9O6LfBX> !!

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

> --
> Jeff Vincent
> predato...@gmail.com
> See my LinkedIn profile at:
> http://www.linkedin.com/in/rjeffreyvincent
> I ♥ DropBox <http://db.tt/9O6LfBX> !!

--
Jeff Vincent
predato...@gmail.com
See my LinkedIn profile at:
http://www.linkedin.com/in/rjeffreyvincent
I ♥ DropBox <http://db.tt/9O6LfBX> !!

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.