WireBox standalone - using MXUnit to test injected dependencies

Hi all

I'm pretty new to dependency injection (DI) and I was attracted by the
non-XML setup the new Wirebox framework offers.

I just wanted to know what the best practice was for mocking of
dependencies when doing unit testing?

For example, say I have a MyService.cfc with a dependency like so:

<cfproperty name="myGamesGW" inject="id:gamesGateway" />

When unit testing (using MXUnit) I would like to mock this object. Is
the best way to

1) Set accessors="true" on the MyService.cfc and call
myService.setMyGamesGW(myMockGateway) ?
2) Or should I use the MXUnit injectProperty() method like so:
injectProperty(myService, "myGamesGW", myMockGateway)

I'm trying to get an idea of the best way to approach things. Any and
all valid alternative solutions to undertake unit testing with a DI
framework are welcome!

Cheers,
Ciaran

PS: I am NOT using ColdBox - use WireBox standalone.

  1. Set accessors=“true” on the MyService.cfc and call

myService.setMyGamesGW(myMockGateway) ?

  1. Or should I use the MXUnit injectProperty() method like so:

injectProperty(myService, “myGamesGW”, myMockGateway)

I would go with number 2. Also, note that MockBox has these capabilities to allow you to inject mocks very easily also. So you can use either mxunit’s injectProperty or use mockbox and add the extra features of mocking

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Thanks for that clarification.

IS it possible to use Wirebox with MockBox (and possibly LogBox)
standalone from ColdBox? We are using a different framework at the
moment but I'd like to check out the mocking stuff.

Cheers,
Ciaran

Ignore this question - it seems I can :slight_smile:

Sure,

http://www.coldbox.org/download

Regards,
Andrew Scott
http://www.andyscott.id.au/

From: coldbox@googlegroups.com [mailto:coldbox@googlegroups.com] On
Behalf Of Ciaran Archer
Sent: Wednesday, 9 March 2011 7:18 PM
To: ColdBox Platform
Subject: [coldbox:8628] Re: WireBox standalone - using MXUnit to test
injected dependencies

Thanks for that clarification.

IS it possible to use Wirebox with MockBox (and possibly LogBox)

standalone

Je!

Yes, that is our purpose to use our internal modules in any approach, of course, if you use them within ColdBox MVC, you get more goodies :slight_smile:

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com