TestNG testng = new TestNG();
testng.setObjectFactory(MyObjectFactory.class)
this limits MyObjectFactory to have a default constructor only.
Is there a reason why I can't do this:
TestNG testng = new TestNG();
IObjectFactory myFactory = new MyObjectFactory();
testng.setObjectFactory(myFactory);
As an example, I was thinking about the GuiceObjectFactory from TestNG
book
public GuiceObjectFactory() {
injector = Guice.createInjector(this);
}
what if for some reason I would like to create my injector outside and
pass it to the factory through the constructor?
public GuiceObjectFactory(Injector injector)
this is just an example, but what if I would like to pass any other
param to the factory itself?
Any workarounds?
Thanks
David
I guess I could use something like
class FactorySetup {
@ObjectFactory
public IObjectFactory createFactory() {
Startable service = new StartableService();
return new MyObjectFactory(something);
}
}
When and by who does FactorySetup gets instatiated?
How can I have control over its lifecycle?
I would Ideally want to have this:
Startable service = new StartableService();
service.start();
IObjectFactory myFactory = new MyObjectFactory(service);
TestNG testng = new TestNG();
testng.setObjectFactory(myFactory);
...
testn.run();
...
service.stop();
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Hi Cedric,
I am sorry misread your email. You can set ObjectFactory programmatically to TestNG object. I do it all the time with PowerMock' object factory.
Yes, I think that's all I need and will solve my problem.
Thanks!
On Feb 12, 3:02 pm, Cédric Beust ♔ <cbe...@google.com> wrote:
> On Fri, Feb 12, 2010 at 2:59 PM, Kartik Kumar <krishnan.1...@gmail.com>wrote:
>
> > Hi Cedric,
>
> > I am sorry misread your email. You can set ObjectFactory programmatically
> > to TestNG object. I do it all the time with PowerMock' object factory.
>
> Yes, but until now, you could only set the ObjectFactory *class*, which
> means the only way to instantiate one is if the class has a no-arg
> constructor. I just added a setter so you can now specify the instance of
> factory you want.
>
> --
> ***Cédric
> *