mxUnit testing and RC..

Hey all,
so I have a bunch of functions I am trying to test, and the only argument for all of them is this:

when I run my test, every test fails because it is looking for the Event…i guess i am not doing something simple with my unit test…

any help would be appreciated…

dan

@fmdano

Your question seems a bit too vague to offer any assistance… can you post some code samples of your unit tests and the test target?

Here is an example of a type of function that I am trying to call as a unit test…not sure if I should even test this if it is just setting a view, but I think it is storing info into the rc, so I think i need to test it, just not sure how to run my test because of the cfargument:

var rc = Event.getCollection(); oSession = getPlugin("sessionstorage"); rc.user = oSession.getVar("user"); rc.qryMyCases = "";

//Init profile Object
objCase = CreateObject(“component”, “#Application.dNPath#model.lcaQueue”);

qryMyCases = objCase.getMyCases();
rc.qryMyCases = qryMyCases;

//Set xeh
rc.xehSetQueue = “ehLCAQueue.doGetNextCases” ;

//Set Layout
Event.setLayout(“Layout.Portal”);

Event.setView(“lcaQueue/vwMyCases”);

@fmdano

To answer your question, I think we need to look at what are you trying to unit test. As you mentioned, this is simply a view, so all “code” technically have already been executed that’s why we separate the Model, View and Controller. The resulting view is in a way your unit test. Now, you probably may already have or should unit test the methods you are calling to get the data for that view, myCases result for example, but you do that by unit testing the component that is returning you the cases, not at the controller.

Hope that points you in the right direction. :slight_smile:

There are a few things that are going on here that can be improved to help make it easier to test. You may enjoy attending the session later this month on testing. The training is free. You can RSVP here: http://www.coldbox.org/cbdw

The Testing session is July 25th at 12:00 EDT.

Hey guys,
first, I did mention to my developer team about the free coldbox training online, so I hope more of them take advantage of it, even if we are only on 2.6.

I can’t really screw with the model functions, since they are tested and on production…my tests are being done on my own, to learn more about MXUnit, learn the codebase better, and set up tests. The model where my code sample came from, has a lot of functions on them, and each one has a cfargument at the top setting the rc. Is there a way to replicate this via a mxunit test, or how might I get around the rc being set as an argument.

I know the models could and should be updated and refactored, but the work time constraints always comes out when I even mention refactoring…so gotta work with what I have.

thanks for any more help, and looking forward to the CB dev week…now, if we could only get the company to pay for some team members to go to the coldbox training after RIACon :slight_smile:

dan

Is this what you mean by model function?

var rc = Event.getCollection(); oSession = getPlugin("sessionstorage"); rc.user = oSession.getVar("user"); rc.qryMyCases = "";

//Init profile Object
objCase = CreateObject(“component”, “#Application.dNPath#model.lcaQueue”);

qryMyCases = objCase.getMyCases();
rc.qryMyCases = qryMyCases;

//Set xeh
rc.xehSetQueue = “ehLCAQueue.doGetNextCases” ;

//Set Layout
Event.setLayout(“Layout.Portal”);

Event.setView(“lcaQueue/vwMyCases”);

Yep…this is a function in a model file in my ColdBox application…as you see the Event is an argument for the function…as far as I know it is not actually passed in, but maybe I am wrong…I thought in coldbox this is what you do first in a model function, set the RC…if you set it first, i assume it is not something to pass in, so not sure how to test it…

@fmdano

First of all, kudos for getting your team to start unit testing, many teams out there don’t make it a priority during the development live cycle and it should be just as important as choosing an IDE.

About the example you shown, the method you are testing is not an actual model function (or method), that’s your Controller method within your handler. It should simply tie your domain Model to your View, acting as a marshal in between and not do much else, not even contain business processing rules. In your example, the objCase.getMyCases(); method is your model function since it processes and returns to you persisted data from your domain model (the domain model is more than just your database, it’s really your business domain model where all your business rules and their processing also resides).

You probably want to unit tests the methods in the …model.IcaQueue CFC component, that way you can make sure they are returning (or in some cases processing) what you expected of them prior to letting the controller call them and pass any returned data back to your view.

Hope this helps and definitely be sure to attend Aaron’s session on Test Driven Development during the ColdBox Developer Week, it’s a great opportunity to get more in depth on this subject.

Cheers…

Phill,
Thanks for the write up. Actually, the code I showed you is in a model file…i don’t think all the developers here understand coldbox. I think they ran some code to get data into the rc, then set the current view. I can and will test the actual model functions such as getMyCases, however, I was just checking to see if in any tests if the rc as an argument can be masked in a unit test.

As for my team doing unit testing, actually they are not, i am…partially for my education, and also because we have a ton of functions and we just test via test plans manually…no automation. I thought by using mxunit, i could start to automate even a bit of what we do.

thanks for the help…
dan