Skip to content

gregstewart/stubbie

Repository files navigation

Stubbie 0.3

Short and sweet:
Stubbie creates a set of test stub objects to be used in your unit tests based on your projects CFCs.

Stubbie was inspired by a feature in Rails that creates stub test objects based on objects found in your application.

You can run Stubbie standalone or as a plugin (there is a Mach-ii plugin available) and on execution it will recursively examine your projects code for CFCs and generate generic test objects for you, as well as a Test Suite. No more excuses to not use Unit Testing.

It currently supports both MXUnit, CFUnit and CFCUnit.

Credits:
Special thanks must go to Stephen (Spike) Milligan for allowing me to use his CFCDoc code which allowed me to quickly build the project without having to worry about the File System and CFC parsing.

Seth Petry-Johnson also deserves a special mention for allowing me to use his VarScopeChecker.cfc as part of the release so that we can all benefit from a var scope unit test.

Installation:
The simplest way to install stubbie is to just place it in your webroot, alternatively you can just create a mapping called /stubbie and point it to your install folder.

Usage:
Using stubbie requires 2 steps. The first is editing config.xml and the second is calling the component.

Step 1
Open up the config.xml file and edit it the following settings
<stubbie>

	<config>
		<appName value="myAppName" /><!-- the name of your app, e.g. the folder name under which the app resides, used to suffix the root path of your app -->
		<appPath value="/Full/Path/To/Root/Of/Your/App" /><!-- full path to the app, minus the app folder name -->
		<packageRoot value="com.myDomain" /><!-- if you have a mapping for your app's cfcs, e.g. com.mydomain, specify it here -->
		<saveTestFilesTo value="" /><!-- Not implemented yet, optional storage location for the test stubs -->
		<unitTestFramework value="mxunit" requiresApplicationScopeAccess="true" /><!-- cfcUnit/cfUnit/mxunit requiresApplicationScopeAccess : true/false (only really applicable to mxunit if you want to create a remoteFacade to access the application scope of yoru app from within your tests)-->
		<coldSpring use="false" path="config/cs.xml" useMachIIColdSpring="false" /><!-- use CS to autowire to wire up the beans, if MachII app use that CS -->
	</config>
	
</stubbie>

Step 2
Place the following code in anywhere you wish to invoke stubbie from:
<cfset configFilePath = ExpandPath('./config.xml')/>

<cfset stubbie = CreateObject("component","Stubbie").init(configFilePath)/>
<cfset stubbie.build()/>

Calling the template will kick off the process. This involves the creation of a folder called test under the appPath which in turn will hold all of the test CFCs for your project. 

Depending on what unit test framework you have chosen you also have a test suite created for you. If you chose the cfcUnit option you will find a AllTests.cfc under {appPath}/tests/ and if you chose cfUnit you'll find cfUnitTestRunner.cfm.

Requirements:
I have developed it and tested it on CFMX 8 and 7 but it should work just fine on CFMX 6.1.


MXUnit:
If you wish to view the results of a MXUnit TestSuite build cease a test.cfm file like below in your test output folder:

<cfparam name="url.output" default="html">

<cfset testSuite = CreateObject("component","stubbie.test.AllTests") />
<cfset result = testSuite.suite() />
<cfoutput>#result.getResultsOutput(url.output)#</cfoutput>
<cfdump var="#testSuite#" />

Be sure to update the path for the test suite (here I am basing it off a build I ran for stubbie). Then simply open your browser to the location of the test.cfm file and all things being well you should see the results of your test.

Mach-ii plugin:
I am assuming that you have followed the previous steps and are using a mapping called stubbie.  To add the mach-ii plugin imply add the the lines found between <!-- Start stubbie plugin code --> and  <!-- Start stubbie plugin code -->. This also assumes that you have a your stubby config file inside a config folder under the root of your mach-ii application.

<!-- PLUGINS -->
<plugins>
	<!-- Start stubbie plugin code -->
	<plugin name="StubbiePlugin" type="stubbie.machii.StubbiePlugin">
		<parameters>
			<parameter name="stubbieConfigFilePath" value="./config/stubbie/config.xml" />
		</parameters>
	</plugin>
	<!-- End stubbie plugin code -->
</plugins>

If you are using MXUnit, then to take full benefit of the integration between Mach-ii and ColdSpring I suggest you also set the attribute in your config.xml for useMachIIColdSpring to true. If you choose to do so a few things will happen. For one the generator will create CFCs that hook into the ColdFusionApplication scope to find Mach-ii and try and use the serviceFactory as created by mach-ii (NOTE you may need to update this value, I am working of defaults here). Secondly the code will create an additional CFC for use with MXUnit: RemoteFacade.cfc (this is required in order to access the application scope using the Eclipse plugin). Finally if you are using Eclipse for your tests you will need to update the URL for the service to point to this RemoteFacade.cfc.

About

creates test stub objects for ColdFusion components

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published