- Go download MXUnit
- If you're using Eclipse, install the Eclipse plugin
- Somewhere in your codebase, create a directory named "tests" (or whatever)
- Pick a fairly easy existing component that you've already written. Let's say it's named "Bob". Now, go to your tests directory and create a new file called "BobTest.cfc".
- Inside that file, add a cfcomponent tag and have it extend mxunit.framework.TestCase
- Then, pick a function in Bob to run. Maybe it's "init". Think to yourself, "What's one thing this function should do?" Then, back in your test, write a new test function, something like
.... - Run the test to confirm everything's "hooked up" correctly. This test should pass.
- Now, try to write a simple test for Bob.init() by creating an instance of Bob and invoking its init() function. Write an assertion or two on the result of that call to init().
Mid-Michigan CFUG MXUnit Presentation Roundup
Thanks!
To all who attended, thanks for spending so much time with me. And thanks to Rick and Nick for setting it all up.
Here's some follow-up:
Remember my onMissingMethod / UserBean problem?
Turns out, the reason the test was failing was that I needed to call user.setid(id=5), not user.setid(5). Umm...... that ain't cool. So I wrote some notes into bean.cfc and userbean.cfc for refactoring. Give those refactorings a shot!
Follow-up, or, What to do next
Subscribe to:
Post Comments (Atom)

5 comments:
> I needed to call user.setid(id=5), not user.setid(5).
I'm really glad you mentioned this, because I ran into this same issue on another project. This behavior has got me a bit confused ... did you find any resource explaining why this is? Or what's your take on it?
thanks!
bill
in this specific case, the problem is in the implementation of onMissingMethod inside of bean.cfc. As practice, I've set up a function to test to ensure that bean.setid(5) works... it's up to folks to download the zip file and refactor the onMissingMethod to get that call to work. it's entirely doable, quite simply even.
so i don't think this is a coldfusion onMissingMethod problem. this is a specific implementation problem
I always thought that was caused by not supplying a value to all of your arguments in the same order they are listed in your method. Throw in an optional argument and your hosed if you don't include the names.
Is there more to it that that?
dang ... I'm going to have to think this morning ...
@mike: nope, that's it. the thing is, in this specific case, the problem is in an onMissingMethod function that's attempting to do dynamic getters/setters. the nice thing about this is that a setter will only take a single argument. so it's easy to implement onMissingMethod to just not care about named args.
So here's a case where you can get around a lame problem in onMissingMethod b/c the implementation is attempting to do a very simple/specific thing.
for more complicated onMissingMethod implementations, I'm not sure it'd be so easily dealt with.
Post a Comment