Unit Testing, getModel and ColdboxConfig beans

I'm trying to set up some unit tests but have run into a problem when
using ColdboxConfig beans. I have the following coldspring bean
defined:

<bean id="SettingSiteMailFrom" factory-bean="ColdboxConfig" factory-
method="getKey">
    <constructor-arg name="key"><value>siteMailFrom</value></
constructor-arg>
</bean>

Which gets injected into my service like so:

<bean id="CustomerService" singleton="true"
class="ppp.model.customerservice" >
  <constructor-arg name="Transfer"><ref bean="Transfer"/></constructor-

  <constructor-arg name="siteMailFrom"><ref bean="SettingSiteMailFrom"/

</constructor-arg>

</bean>

This works fine when I run the site normally but in my unittest I'm
calling:

customerService = getModel("model.customerService");

and get the error Element SITEMAILFROM is undefined in ARGUMENTS. The
transfer bean gets passed in successfully.

Any thoughts on what I'm doing wrong?

Cheers!

ok, I am confused, you are using coldspring but in your test you are not?

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

Hmm... well no, I'm not using coldspring in my tests. I was thinking
that getModel would get that component which has already been
initialised by coldspring - so all its dependencies would already be
injected. But I'm now realising that the fact that the "init"
function is being called indicates this is not the case.

My general problem is I'm trying test my models, which have
dependencies, without mocking those dependencies. I'm struggling to
find examples of how to do this. Maybe it's just not valid approach
and I'm missing the point? Perhaps what I'm trying to do falls under
integration testing?

I'm pretty ignorant when it comes to testing and I appreciate the help!

Why don’t you want to use mocks? You may want to look up integration testing in coldbox if you’re not worried about testing components in isolation.

– sent by a little green robot

Yea, so I would recommend the following.

You are using coldspring for your DI in your app, and that is fine. I would recommend two types of tests: 1) Unit tests for your models (in isolation) and 2) Integration testing for your handlers so you can test EVERYTHING top-down.

For number 1, look in the what’s new for the new testing class: http://wiki.coldbox.org/wiki/WhatsNew:3.0.0.cfm#New_Targeted_Model_Testing, coldbox.system.testing.BaseModelTest

This will help you test model objects in isolation by creating it for you and giving it mocking capabilities immediately, so you can just do things like:

mockGateway = getMockBox().createEmptyMock(“model.MyGateway”);
model.$property(“mygateway”,“variables”, mockGateway);

etc etc. This will allow you to test the CFC without relying on the dependency injection framework or any other dependency, thus isolation. Then via integration testing (testing your handlers), you can test the whole shabang! How the DI loads, creates, and serves, how the framework creates your handlers, etc

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