MockBox – Mocking a Super Class

Posted: March 9, 2011 in ColdFusion

I’m getting my hands dirty using MXUnit Testing w/ MockBox recently. The basics where fairly easy to pickup, but I’ve now hit a road block. Lets say I need to test this method:

<cfcomponent extends="message" output="false">
    <cffunction name="send" access="public" returntype="void" output="false">
        <cfargument name="name" type="string" required="true">
        <cfif name neq "test">
            <cfset super.send(>

So following unit test ideology, I should just test what’s happening in this method and not attached methods.  If I had instantiated an object or the method was in the some component I could just mock the method being called. However since the method is located in the component’s parent, this does not appear to be working. The test contains:

variables.mockBox = new mockbox.MockBox();
variables.component = CreateObject('component', 'thisComponent');

This returns the error: “Expression: Element COMPONENT.SUPER is undefined in a Java object of type class [Ljava.lang.String; referenced as ””.

Now technically I could wrap the super.send call inside another local method and mock that method. However that would be coding for the test and would be worthless code and processor usage outside the test.

I’ve Googled this and searched ColdBox’s site for a solution to this, however I’m not getting anywhere.

Does anyone have any ideas or suggestions?

  1. Chris says:

    At this point in time, we’ve decided to treat the child and parent as a whole and not mock the parent method until we can find the best solution for this.

  2. Is there another method of the same name in the child that you need to specify super? If not one workaround is removed the super reference and just mock save.

    I’m not at a machine to try this but another possible is MXUnits injectMethod() which would allow you to swap out that method for your own test one. It’s not as elegant as having mockbox though.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s