Service Testing with MockBox

19 views
Skip to first unread message

Charlie Schaubmair

unread,
Nov 4, 2009, 5:39:18 AM11/4/09
to col...@googlegroups.com
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
test2.cfc
test3.cfc

Charlie

unread,
Dec 1, 2009, 3:51:41 AM12/1/09
to ColdBox Platform
Hi,

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

Maybe one can help me, please?

cheers
Charlie

On Nov 4, 11:39 am, Charlie Schaubmair <occur...@gmail.com> wrote:
> 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
> 1KViewDownload
>
>  test2.cfc
> 2KViewDownload
>
>  test3.cfc
> 2KViewDownload

John Whish

unread,
Dec 1, 2009, 6:00:11 AM12/1/09
to col...@googlegroups.com
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.


Does that help?
Reply all
Reply to author
Forward
0 new messages