Simple CFC function call for test

This is a newbie question.

I’d like to do a simple CFC function call for unit testing but I want to call an existing function written in CF Is there such an example?.

For example let’s say I have a CFC file called Sample.cfc in my code base that provides a lookup. It returns a 1 if the argument AccountType=“Business” and a 2 if AccountType=“Consumer” and 0 otherwise. The CFC looks like this:

<cfcomponent displayname=“Sample” ">

I want to call this from a unit test run function so I can do the assertions. How do I do that? What I am looking for is how I get a reference to the Sample component so I can call the EvaluateAccountType function with various arguments and do assertions on what it returns.

Thanks,

Steve

We got the solution using mocking. Assuming that Sample.cfc is in a directory called cfc under the application root, our SimpleCFCUnitTest.cfc contains:

component extends=“testbox.system.BaseSpec” {

// executes before all suites
function beforeAll()
{
mockedEnum=CreateMock(“cfc.Sample”);
}

// executes after all suites
function afterAll(){}

// All suites go in here
function run( testResults, testBox ){
describe(“A suite”, function() {
it(“Simple CFC call”,
function() {
results=mockedEnum.EvaluateAccountType(“Business”);
expect( results ).toBe(1);
});
});
}
}

The test runs successfully.

Steve