Service Testing with MockBox

Hi,

I’ve asked one of my questions allready in the CB-Forum, but it seems here are more users reading this.

I’m a totally newbie in testing.

I’ve a ColdBox App. and want to test some services I’ve created. For these services I need also the objects which will be created via other beans.

These beans will be created via ColdSpring, so now my question:
How is it possible to get these beans via ColdSpring to test it with MockBox?

My solution for this is now working → see attached test.cfc

then I’ve created another test function and saw that it is always very, very slow (every test lasts for minimum 5 seconds), because the setUP-function is called for every test-function → test2.cfc

then my idea was to set everything into the application scope → test3.cfc
but then my:
getController().runEvent(“main.onRequestEnd”);
will not work anymore
but it is now very fast: 0-20ms / test

Am I on the correct way, or how to test this?

The next question for me is:
How to test if an user object was inserted correct into our DB?
Maybe something like this:

  • call the user service which will insert the user object into DB (called with an own created user dummy object), this will creat also a session with the user object

  • call the user service which will get the user from the db by the session object
    But then I’m testing 2 functions from my user service.

cheers
Charlie

test.cfc (1.41 KB)

test2.cfc (1.82 KB)

test3.cfc (1.99 KB)

Hi,

sorry for posting again, but maybe no one saw my previous post?

Maybe one can help me, please?

cheers
Charlie

I’m not any kind of authority on Unit Testing but ideally you want to test you components independently of any other cfc, so if you want to test your ServiceXYZ cfc then any dependencies should be passed in as stubs/mocks. You probably want to use a different ColdSpring XML config for testing which uses MockBox to create the dependancies. That way you can test your service without worrying (or even writing) any other cfcs.

Also have a read of this: http://www.andyscott.id.au/index.cfm/archive/MockBox

Does that help?