TestNG and Guice? (using Mycila right now but having an issue getting it to work using AbstractMycilaTestNGTest.)

19 views
Skip to first unread message

Rick

unread,
Jan 15, 2009, 5:59:10 PM1/15/09
to google...@googlegroups.com
I'm asking here for lack of a better list and for any other recommendations.

I'm trying to use mycilia for testing and according to the testng
example here http://code.mycila.com/wiki/MycilaTesting I should be
able to just extend AbstractMycilaTestNGTest and annotate with my
GuiceContext However that abstract class doesn't seem to help me,
instead I have to use the other approarch shown in each of my test
classes:

@BeforeClass
public void setup() {
TestSetup.setup(this);
}


I was hoping I could just have all my classes extend a BaseTest class
which extends AbstractMycilaTestNGTest and everything would be fine,
but it's not working for me (None of my Injections take place nor do I
see my Module even loaded.)

I was hoping to just extends my tests from:

@GuiceContext(OndpServicesTestModule.class)
public abstract class BaseTest extends AbstractMycilaTestNGTest {

}


(As a side note even when I push up the @BeforeClass implementation
into this base class, things aren't working. It seems odd that I have
to actually use the @BeforeClass setUp method in my actual concrete
Test classes and not in the BaseTest class?)

I'm hopefully missing something very simple, but I'm stumped right now.

Rick

unread,
Jan 15, 2009, 8:40:18 PM1/15/09
to google...@googlegroups.com
In case anyone else searches the list for tenstng solutions, I found
this approach to work great.
http://asemantics.dyndns.org/m2doc/com.asemantics/testnguice/1.0/inject.html
(I'm using this now instead of mycila.)

Just make sure your factory class is listed first and it runs great
(the document above has a typo in the class name or the name has since
changed since that was written... the class is AbstractObjectFactory
not AbstractTestObjectFactory.)

--
Rick

Mathieu

unread,
Jan 15, 2009, 10:22:09 PM1/15/09
to google-guice
Hi,

I don't know how you setup your environment, but this usage has been
tested and works well: In example:

@GuiceContext(AModule.class)
public final class ExtendTest extends AbstractMycilaTestNGTest {
@Inject
@Named("service1")
Service service1;
@Test
public void test_inject() {
assertEquals(service1.go(), "go1");
}
}

If you need some help, i suggest you post fore information on your
setup and the libraries you are using on your classpath at
http://code.google.com/p/mycila/issues/list so that we can help you.
Nevertheless, i hardly advise to not use inheritance even for test
classes since it leads to junk classes having an accumulation of
methods which leads to tests that are time consuming to maintain.
There are plenty of ways to avoid that, static methods, delegation and
annotations are some.

Thank you !

On Jan 15, 8:40 pm, Rick <ric...@gmail.com> wrote:
> In case anyone else searches the list for tenstng solutions, I found
> this approach to work great.http://asemantics.dyndns.org/m2doc/com.asemantics/testnguice/1.0/inje...
>  (I'm using this now instead of mycila.)
>
> Just make sure your factory class is listed first and it runs great
> (the document above has a typo in the class name or the name has since
> changed since that was written... the class is AbstractObjectFactory
> not AbstractTestObjectFactory.)
>
>
>
> On Thu, Jan 15, 2009 at 5:59 PM, Rick <ric...@gmail.com> wrote:
> > I'm asking here for lack of a better list and for any other recommendations.
>
> > I'm trying to use mycilia for testing and according to  the testng
> > example herehttp://code.mycila.com/wiki/MycilaTestingI should be

Rick

unread,
Jan 16, 2009, 12:00:48 AM1/16/09
to google...@googlegroups.com
On Thu, Jan 15, 2009 at 10:22 PM, Mathieu <mathieu...@gmail.com> wrote:
>
> Hi,
>
> I don't know how you setup your environment, but this usage has been
> tested and works well: In example:
>
> @GuiceContext(AModule.class)
> public final class ExtendTest extends AbstractMycilaTestNGTest {
> @Inject
> @Named("service1")
> Service service1;
> @Test
> public void test_inject() {
> assertEquals(service1.go(), "go1");
> }
> }
>
> If you need some help, i suggest you post fore information on your
> setup and the libraries you are using on your classpath at
> http://code.google.com/p/mycila/issues/list so that we can help you.
> Nevertheless, i hardly advise to not use inheritance even for test
> classes since it leads to junk classes having an accumulation of
> methods which leads to tests that are time consuming to maintain.
> There are plenty of ways to avoid that, static methods, delegation and
> annotations are some.

Ok, I'll post my setup in an issue's list. Thanks.

In regard to inheritence. I was using a BaseTestClass for a

@BeforeMethod and @AfterMethod which would initialize a time and the
afterMethod would log the time it took.

I also put my logger initialization in the base class. Just one less
thing to always have to put in each class.

I'm sure some AOP stuff could help out but using a BaseTest class for
this simple stuff seems to work fine. I'm open for some other
approaches.

Dhanji R. Prasanna

unread,
Jan 16, 2009, 1:57:38 AM1/16/09
to google...@googlegroups.com
On Fri, Jan 16, 2009 at 2:22 PM, Mathieu <mathieu...@gmail.com> wrote:

Hi,

I don't know how you setup your environment, but this usage has been
tested and works well: In example:

@GuiceContext(AModule.class)
public final class ExtendTest extends AbstractMycilaTestNGTest {
   @Inject
   @Named("service1")
   Service service1;
   @Test
   public void test_inject() {
       assertEquals(service1.go(), "go1");
   }
}

If you need some help, i suggest you post fore information on your
setup and the libraries you are using on your classpath at
http://code.google.com/p/mycila/issues/list so that we can help you.
Nevertheless, i hardly advise to not use inheritance even for test
classes since it leads to junk classes having an accumulation of
methods which leads to tests that are time consuming to maintain.

That's funny, I advise the opposite since inheritance leads to tight coupling.

;)
 
Dhanji.


Dhanji R. Prasanna

unread,
Jan 16, 2009, 2:04:04 AM1/16/09
to google...@googlegroups.com
Or did you mean, you "strongly" advise against inheritance? In which case, I agree.

Dhanji.

Rick

unread,
Jan 16, 2009, 10:05:06 AM1/16/09
to google...@googlegroups.com
On Fri, Jan 16, 2009 at 2:04 AM, Dhanji R. Prasanna <dha...@gmail.com> wrote:

>>>
>>> If you need some help, i suggest you post fore information on your
>>> setup and the libraries you are using on your classpath at
>>> http://code.google.com/p/mycila/issues/list so that we can help you.
>>> Nevertheless, i hardly advise to not use inheritance even for test
>>> classes since it leads to junk classes having an accumulation of
>>> methods which leads to tests that are time consuming to maintain.
>
> Or did you mean, you "strongly" advise against inheritance? In which case, I
> agree.

Yea you're both on the same page there.

Just curious though how would you recommend setting up a common
@BeforeMethod @AterMethod type of behavior? Is it at least ok to push
that into a class my tests classes can extend so they all have those
method implementations inherited?

Thanks
--
Rick

Mathieu

unread,
Jan 16, 2009, 7:45:07 PM1/16/09
to google-guice
When the project is small, i use to do this also to make my tests
smaller. But when the project grows, you end up by needing more stuff
in @BeforeClass that is quite specific to a test. So i find it easier
to maintain a test with less coupling since it is quite well isolated.

So like all, it depends on your needs, your project size, ... Take the
right approach, the simplest and the least coupling being often the
better ones ;)


On Jan 16, 10:05 am, Rick <ric...@gmail.com> wrote:
> On Fri, Jan 16, 2009 at 2:04 AM, Dhanji R. Prasanna <dha...@gmail.com> wrote:
>
>
>
> >>> If you need some help, i suggest you post fore information on your
> >>> setup and the libraries you are using on your classpath at
> >>>http://code.google.com/p/mycila/issues/listso that we can help you.

Simone Tripodi

unread,
Jan 20, 2009, 3:37:04 AM1/20/09
to google...@googlegroups.com
Hi Rick!
I'm the author of TestNGuice, thanks for using it!!!
And above all, thanks to have found an error in the documentation,
I'll fix it ASAP.
Best regards,
Simone

> Just make sure your factory class is listed first and it runs great
> (the document above has a typo in the class name or the name has since
> changed since that was written... the class is AbstractObjectFactory
> not AbstractTestObjectFactory.)
>

--
My LinkedIn profile: http://www.linkedin.com/in/simonetripodi
My GoogleCode profile: http://code.google.com/u/simone.tripodi/
My Picasa: http://picasaweb.google.com/simone.tripodi/
My Tube: http://www.youtube.com/user/stripodi
My Del.icio.us: http://del.icio.us/simone.tripodi

Reply all
Reply to author
Forward
0 new messages