testing your cfcs

This post is to explain how to test your cfc to make sure they are working the way that you meant. I am wondering if it is possible to test a cfc directly using cfdump? However, since you don’t run a cfc directly, this may not work.


    <cffunction name="getArtist" access="remote" returntype="query">
        <cfset var qRead = "" />

        <cfquery datasource="cfartgallery" name="qRead">
            SELECT artistid, firstname, lastname, email
            FROM artists

        <cfreturn qRead />


to test the cfc I create a test file and invoke the cfc and then use cfdump to see the results


     <!--- dump the output--->
     <cfdump  var = "#qRead#">

Happy Coding

One Reply to “testing your cfcs”

  1. The method you’re using is fine. You can always add the cfdump and cfabort tags in the function you want to test (directly after the query tags) ie:

    &lt;cffunction name=&quot;getArtist&quot; access=&quot;remote&quot; returntype=&quot;query&quot;&gt;
    	&lt;cfset var qRead = &quot;&quot; /&gt;
        &lt;cfquery datasource=&quot;cfartgallery&quot; name=&quot;qRead&quot;&gt;
            SELECT artistid, firstname, lastname, email
            FROM artists
        &lt;cfdump var=&quot;#qRead#&quot; /&gt;
        &lt;cfabort /&gt;
        &lt;cfreturn qRead /&gt;

    so on your calling page you wouldn’t need to include the dump tags. This is, of course, a simple but effective way of doing it. You could create a new generic function that dumps any query passed to it etc..

Leave a Reply

Your email address will not be published. Required fields are marked *