Hi Erland,

You could try this approach: http://stackoverflow.com/questions/8402012/how-to-use-servletscopes-scoperequest-and-servletscopes-continuerequest

Gili

On 08/02/2012 2:05 AM, Erland wrote:
Is there a good way to simulate RequestScoped in a unit test ?

The unit test is not running in a servlet container so when running
the test case I get an error about:
1) No scope is bound to com.google.inject.servlet.RequestScoped.

Ideally I think I'd like RequestScoped to be bound to the scope of the
current test method in the TestNG test case.

Is there a way to do this without implementing my own scope and
remapping it to the RequestScoped when running the test case by
including a module like this in the test case:

     public static class RequestScopeModule extends AbstractModule {
         @Override
         protected void configure() {
             bindScope(RequestScoped.class, new MyMethodScope());
         }
     }

Theoretically it might work if I remap it to Scopes.SINGLETON but I
feel that doing that will risk one test method to affect the outcome
of the next test method.

Any ideas regarding the best way to accomplish this ?


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

Reply via email to