unit testing not find component

Hey everyone,
I am trying to get handler/model testing working with coldbox. now, we
are not on 3+, but 2.6.3, so it is different i think. Plus, whomever
started this project, seemed to strip out all the testing folders, so
I have had to add them back in.
So, I have mxunit folder in my coldbox app, and i can bring up the
wsdl. I thenk set up the project to connect to my remotefacade in the
test folder. I have a simple test created with the cfcomponent
extending coldbox.system.testing.BaseTestCase
I have a setup with the super.setup(), and simple tests.

when i run the tests within coldfusion builder2, i get an error can't
find cf component or interface...

any idea what could be causing this?

is there a different setup for models compared to handlers, or are
they basically the same?

thanks
Dan

Everything is basically the same.

I would pose this question on the MXUnit group. Sounds like a configuration issue with your MXUnit Eclipse Plugin.

Thanks, I will try that...it is hard for me to figure this out since I
am using coldbox 2.6.3, and all videos,docs, ect all seem to be newer
testing setup for coldbox. I try to put the newer code in place,
however it does not even work when i try to use the browser setup...

ugh, i wish the original developers did not rip out all the testing
code, it would be easier to figure this out....

thanks
dan

You can find documentation for 2.X here: http://ortus.svnrepository.com/coldbox/trac.cgi

There are a number of ways you can setup Builder to do your tests.

The number one problem is how you are going to define the location of your tests, personally I keep them away from the main source code. To do that one needs to create a project where the web root is a folder inside the project, then create your tests outside of the web root.

You then create your httpAntRunner in that folder, and point Builder to use that. You will also need to then set up a virtual directory for IIS / Apache to know about that directory.

There are many examples, but your best bet is to work out what will suite you and read how to set it up over at mxUnit.

I am more than happy to discuss it further in here.

P.S the method that I described above is the better way to approach it, as stated it keeps your tests and code separated.

This is the link I keep coming back to:
http://ortus.svnrepository.com/coldbox/trac.cgi/wiki/cbUnitTestingHandlersGuide
and I read this over and over, and I can't get anything to work...i
try to put my file into the browser:
http://localhost/test/integration/mainTest.cfc?method=testonAppInit

and this gives me an error, so I am not sure if I have testing stuff
set up incorrectly, or am I just doing something wrong. here is the
beginning of my mainTest.cfc

<cfcomponent extends="coldbox.system.testing.BaseTestCase">
<!---<cfcomponent extends="coldbox.system.testing.BaseHandlerTest">
<cfcomponent extends="coldbox.system.extras.testing.BaseMXUnitTest">---

  <cffunction name="setUp" returntype="void" output="false">
    <cfscript>
    // Call the super setup method to setup the app.
    super.setup();

    // Any preparation work will go here for this test.
    </cfscript>
  </cffunction>

  <cffunction name="testonAppInit" returntype="void" output="false"
access="remote">
    <cfscript>
    var event = "";

    //Place any variables on the form or URL scope to test the handler.
    //URL.name = "luis"
    event = execute("main.onAppInit");

    //Do your asserts below

    </cfscript>
  </cffunction>

Does anything look wrong here? when i run it in the browser with the
link pasted in above, i get this error:
The getSetting method was not found.
Either there are no methods with the specified method name and
argument types, or the getSetting method is overloaded with argument
types that ColdFusion cannot decipher reliably. ColdFusion found 0
methods that matched the provided arguments. If this is a Java object
and you verified that the method exists, you may need to use the
javacast function to reduce ambiguity.

does this help any...

thanks
Dan

Andrew,
since I am using ColdBox, and unit testing is suppose to be built
right in, i figure i'd use the built in folder structure...now old
developers removed all the testing folders, so I have put in what I
think could work, but I may be using newer folder structure with
coldbox 2.6.3, but i am not sure yet...it is a pain when developers
decide that the testing information is not important enough to keep in
the folder structure...ugh.

thanks
Dan

Testing is not built right in, and it doesn’t work like that.

You need to download and install mxunit, then you need to follow the instructions there in setting up a basic test. Once you have a basic test up and running, then you can go ahead and get the tests going for your application.

ColdBox supports testing yes, but you still need something like mxunit for it to actually work.

Also you don’t say what the error message is either.

sorry my bad, i should have mentioned it uses mxUnit but that is not
bundled with coldbox. I have mxunit downloaded and the plugin for
eclipse running as well.
I have the coldfusion builder project preferences set for the remote
facade, but the overall preferences I am not sure about.

when I run the test in builder I get one error:
testonAppInit
Application: Could not find the ColdFusion Component or Interface
coldbox.system.web.Controller. Ensure that the name is correct and
that the component or interface exists.
        at C:\LOCALSERVER\icert-DEV\coldbox\system\testing
\BaseTestCase.cfc:
113
        at C:\LOCALSERVER\icert-DEV\test\integration\MainTest.cfc: 16

when I run this in the browser http://localhost/test/integration/mainTest.cfc?method=testonAppInit
i get another:
The getSetting method was not found.
Either there are no methods with the specified method name and
argument types, or the getSetting method is overloaded with argument
types that ColdFusion cannot decipher reliably. ColdFusion found 0
methods that matched the provided arguments. If this is a Java object
and you verified that the method exists, you may need to use the
javacast function to reduce ambiguity.

so I am not sure if mxunit is set up right, i think it is, or if
something with my code is not set up right.

thanks
Dan

Ok now that is making sense.

Your second option is never going to work, all tests must be run through mxunit.

Ok can you give me a snapshot of how you have your directory structure.

Here is also a very basic test I whipped up

setAppMapping("/"); setConfigMapping(ExpandPath(instance.AppMapping & "/config/coldbox.cfc")); super.setup();

But I also need to know your directory structure.

OK, so my first difference from your code to mine is we are only using
2.6.3, so we still have the coldbox.xlm.cfm file.
folders you'll care about:

+coldbox
      +dashboard
      +system
         +beans
         +cache
         +config
         +extras
            +antisamy
            +javaloader
            +livewire
            +testing
                 basemxunittest.cfc
                 basetest.cfc
             +transfer
            coldboxfactory.cfc
            coldboxproxy.cfc
          +includes
          +interceptors
          +plugins
          +services
          +testing
              +mock
              +mockutils
              +stubs
              baseHandlerTest.cfc
              baseModelTest.cfc
              baseTestCase.cfc
          +util
+config
    application.cfm
    coldbox.xml.cfm
    modelmappings.cfm
    routes.cfm
+handlers
+includes
+interceptors
+layouts
+models
+mxunit
+plugins
+test
    +integration
         mainTest.cfc
    +mocks
    +resources
         remoteFacade.cfc
    +unit
    application.cfc
    testSuite.cfm
+views

I want to be able to set application variables in the test/
application.cfc file (if I can) since many of the models use
application variables. I figure I can do this because of the headless
setup?
I figured for mainTest.cfc I could either extend the
coldbox.system.testing.BaseMXUnitTestor since I added in the test
folder in system i thought i could use
coldbox.system.testing.BaseHandlerTest, but I am not really sure if
this will work in 2.6.3?

I also want to test my models not just handlers but not sure how to
set up a unit test for that, so I thought i'd start with handlers
since that seems documented.
Below is my mainTest.cfc, when I run this in builder i get the can't
find component or interface. when i run this in the browser, i get the
The getSetting method was not found. The error occurred in C:
\LOCALSERVER\icert-DEV\coldbox\system\testing\BaseTestCase.cfc: line
336:

<cfcomponent extends="coldbox.system.testing.BaseTestCase">
  <cffunction name="setUp" returntype="void" output="false">
    <cfscript>
    //Setup ColdBox Mappings For this Test
      setAppMapping("/");
      setConfigMapping(ExpandPath(instance.AppMapping & "/config/
coldbox.xml.cfm"));

    dump(getConfigMapping());

    // Call the super setup method to setup the app.
    super.setup();

    // Any preparation work will go here for this test.
    </cfscript>
  </cffunction>
  <cffunction name="testonAppInit" returntype="void" output="false"
access="remote">
    <cfscript>
    var event = "";

    //Place any variables on the form or URL scope to test the handler.
    //URL.name = "luis"
    event = execute("main.onAppInit");

    //Do your asserts below

    </cfscript>
  </cffunction>

</cfcomponent>

Not sure if I am trying to mix 3.0/3.5 code into my 2.6.3 code base,
or if I am just not setting something up right?

when I run this test, it works:
<cfcomponent extends="coldbox.system.extras.testing.BaseMXUnitTest">

  <cffunction name="setUp" returntype="void" output="false">
    <cfscript>
    //Setup ColdBox Mappings For this Test
      setAppMapping("\");
      setConfigMapping(ExpandPath(instance.AppMapping & "/config/
coldbox.xml.cfm"));

    // Call the super setup method to setup the app.
    super.setup();

    // Any preparation work will go here for this test.
    </cfscript>
  </cffunction>

  <cffunction name="Testsplash" returntype="void" output="false">
    <cfscript>
    var event = "";

    //Place any variables on the form or URL scope to test the handler.
    //URL.name = "luis"
    event = execute("ehSearch.splash");

    //Do your asserts below
      //assertEquals("ehSearch.splash",
event.getValue("setnextevent",""), "This totally failed!!");
      assertEquals("", event.getValue("setnextevent",""), "This totally
failed!!");
    </cfscript>
  </cffunction>

cfc function called:
<cffunction name="splash" access="public" returntype="void"
output="false"
    hint="I show a portal splash page.">
    <cfargument name="Event" type="coldbox.system.beans.requestContext">

    <cfset event.setLayout("Layout.Portal")>

    <cfset Event.setView("Portal/vwPortalSplash")>

  </cffunction>

now that function does nothing, but it ran. but the only test that
ran :slight_smile:

Does this provide enough info?

thanks
dan

As I stated in my previous post your second option will not work.

When running any test there are 2 options to run them, the first is setting up ColdFusion Builder or CFEclipse to run the tests from there, all you do is right click the test or directory and select mxUnit run tests.

The other way is to run the tests via a test suite, in the browser, but again you need to do this through mxunit. The difference that time is that you require the HTMLrunner.

So before you even begin running any tests for ColdBox, you need to understand how to use mxunit to run tests. Once you understand that process, then you can modify your tests to run your ColdBox stuff.

Tests are meant to run that method, and test that method. They don’t care about settings in Application.cfc, so if you have an event handler that specifically calls up something in application.cfc which is extremely rare for any ColdBox application, then your test doesn’t care.

Tests should only care about failing and passing, and writing your tests to cover all possible outcomes of that method. Which means what is or could go into that method, and what could come out of that method. The meat and bones of the test is then said to be called black boxed, which is a way of saying it shouldn’t care about what is outside of it only what is coming in and out of the method.

So my advice to you, is look at the docs for mxunit, and work out how to write a test that will work with mxunit first, even if it is a simple fail(“I am under development”) in a test case, will show if it is working. Then work out which method of testing you want to use, I prefer running my tests from CFBuilder. Once you have that worked out, then you can go back to writing your tests for ColdBox.

So far I can’t see any problems with your test as it stands now, however I am hearing a problem in how you are trying to run that test.

Ok, so the 2 options are run through Builder and the mxUnit plugin or
actually going to localhost/mxunit/index.cfm and run it...is this it?
I just tried using method=runTestRemote and that ran the test in the
browsers. I still get issues with the tests.

Coldbox seems to run tests different than I remember when I created
tests a year ago using framework one...so much easier than.

Tests are meant to run that method, and test that method. They don't
care
about settings in Application.cfc, so if you have an event handler
that
specifically calls up something in application.cfc which is extremely
rare
for any ColdBox application, then your test doesn't care.

You mention this above, and I understand that tests only care about
running and testing one function at a time, however some of my
functions run queries and those queries use application.datasource...i
thought from videos and reading that having the application.cfc file
in the test folder allows the tests to run headlessly and because of
that, i'd be able to set application variables in that file and they'd
be referenced in my code. I know this is not done with just
mxUnit...in my fw1 testing, I changed my session variables to
cfarguments so I could run tests.

I do thank you for all the help, i just wish we designed this stuff
with testing in mind instead of me trying to fit testing into our
codebase :slight_smile:

dan

Ok, so the 2 options are run through Builder and the mxUnit plugin or
actually going to localhost/mxunit/index.cfm and run it…is this it?
I just tried using method=runTestRemote and that ran the test in the
browsers. I still get issues with the tests.

Coldbox seems to run tests different than I remember when I created
tests a year ago using framework one…so much easier than.

Ok I haven’t done it in a browser for a very long time, I always use CFBuilder and the remoteFaced these days. But from memory that is not how you run tests in the browser, you will need to read the docs on how tests are run from the browser over at mxunit.

Once you can run a test from the examples over at mxunit, then I would start writing ColdBox tests. Until you know how mxunit works, you are trying to get 2 things working at the same time, which is causing you problems because you don’t which section is the problem.

So to isolate you start at the beginning, get mxunit running and testing first. Then move on to the next step.

You mention this above, and I understand that tests only care about
running and testing one function at a time, however some of my
functions run queries and those queries use application.datasource…i
thought from videos and reading that having the application.cfc file
in the test folder allows the tests to run headlessly and because of
that, i’d be able to set application variables in that file and they’d
be referenced in my code. I know this is not done with just
mxUnit…in my fw1 testing, I changed my session variables to
cfarguments so I could run tests.

I do thank you for all the help, i just wish we designed this stuff
with testing in mind instead of me trying to fit testing into our
codebase :slight_smile:

What I mean is your tests don’t need to know anything more than what they are testing. In other words they rely on what you are testing to do what they have to do.

As you have the tests in the webroot, your tests will pick up the application.cfc already So I am not sure what you are trying to say, all I can add is that if your handler runs fine outside of the test then it will work in the test. All you need to do is pass the handler what it needs to know.

One more thing.

Where did you get the

ColdBox 2.6.3 / 2.6.4 never had the testing folder here, so my next question is what made you think the previous developer removed it?

I had to add these folders into the code. The extra folder is in the
code with the testing stuff in it, but the system.testing folder is in
a newer version of coldbox...a few months ago when i was playing with
unit testing, I copied this folder in, commented out some of the mock
box stuff, and got it to work. That is the only reason why it was in
there. But the former developers did not have any test stuff in the
code except for the few files in the extras folder.

I have been able to run some simple handler tests in my coldbox code,
however, a lot of the handlers use application variables which seems
to be an issue.

Also, i want to just test my model files since that is where the
queries are, but the datasource is an application variable as well,
this seems to be a problem...oh and i can't seem to use coldbox and
it's internal testing structure to connect to any of my models.

thanks for checking into the system.testing folder, i should have been
more clear what folders i copied into our code.

dan

ColdBox 2.6.3 had the test files in another location, so by grabbing something from a newer version you are tainting your own process.