A few folks have asked how you can leverage MXUnit and MockBox to mock a super class class. Here is a simple example to showcase this:
Class Parent A
<cfcomponent name="A"> <!--- send ---> <cffunction access="public" hint="" name="send" output="false" returntype="any"> <cfreturn parent=""> </cffunction> </cfcomponent>
Class Parent B
Last night we did a presentation on MockBox, the ColdFusion Mocking/Stubbing framework. It was a good crowd and we got really involved in TDD, testing and mocking discussions. If you have never done any kind of mocking and testing, we encourage you to first see our blog post:
And then continue d...
Once you get an appreciation for the importance of unit testing and integration testing is when we reach a new level in our development careers. Testing is critical to mission critical applications, and even for our own little projects, where we test that our code should work as expected. There’s that word again, expected. Expectations in unit testing is like a nasty hamburger at a soccer match in El Salvador. They go hand in hand :)
I am very excited for this years cf.Objective(). This will be my third year and each year it has gotten better and I always leave inspired and ready to improve all aspects of my craft. It is great to be surrounded by like minded individuals with the same goal to make themselves better at what they do.
This year I have the unique honor to present at the Pecha Kucha BOF that Bob Silverberg organized. I will be presenting on Mocking, it's not just for picking on people. So, you should come join the crowd at the BOF and mock me, or at least learn new ways to mock.
If you haven't registered for cf.Objective(). I believe you still can today. You should also be sure to register for the ColdBox 1 day training workshop. So, stop what your doing right now and head on over to the registration page and go for it.
Hope to see you at the BOF. And thanks Bob for organizing it.
MockBox can have many amazing uses. One well documented use is in assistance in creating complicated unit tests insuring you are only testing one small unit of work, it can be used for many other interesting use cases.
One of the ways we find MockBox useful during our development cycle at Computer Know How is to Mock objects we haven't had the time to complete yet, but we do know what we expect as response. This allows us to continue development without waiting for the piece of something we haven't done yet slow us down, but keep the method calls exactly as they will be in when the object is complete.
So, how do you use MockBox outside of the context of a unit test? Well, its easy.
Inside a ColdBox application.
//get an instance of mockbox to use for mocking things not 100% built yet inside a ColdBox app
mockBox = createObject("component","coldbox.system.testing.MockBox").init();
Outside a ColdBox application.
//get an instance of mockbox to use for mocking things not 100% built yet outside a ColdBox app.
mockBox = createObject("component","mockbox.system.testing.MockBox").init();
Now that MockBox is initialized, we can start mocking objects. Lets say we have a User Object that we haven't had time to build yet. Right now it looks really advanced with lots of cool properties and functions that we spent a ton of time on. Something like this.
cfcomponent hint="I am the User ORM cfc"