Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Question: Unit testing a command  (Read 10340 times)
glidealong
Newbie
*
Posts: 5


View Profile Email
« on: May 27, 2008, 10:38:08 »

Hi all,

I am in a dilemma with respect to testing my commands with unit tests written in FlexUnit. I could easily test the methods in the proxy and I understand that tesing a Mediator is a bit more complex stuff which might require mock objects to be used to reflect the actual runtime usage. But with respect to commands I am lost, how am i supposed to test the my commands if i have only the execute method defined in my command class?

Any clues or inputs would be appreciated.

Thanks a lot
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: May 27, 2008, 11:02:56 »

The easiest way would be to instantiate the command and call its execute method.

You might want to examine the unit tests for the framework itself.

Its difficult to test cascadint activity in the app, though.

-=Cliff>
Logged
glidealong
Newbie
*
Posts: 5


View Profile Email
« Reply #2 on: May 28, 2008, 01:52:05 »

Thanks Cliff for the prompt reply..
But my question was, what should I check for while testing the execute method, since i am not holding any values in the command, just passes the values from mediator to proxy and vice versa.

Thanks again for the reply.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: May 28, 2008, 06:21:10 »

That would be tha part about it being hard to test cascading activity in the app.

You can test som methods of some classes in isolation but when it comes to testing the running app, its difficult. Why? Because your not running the app your running the test runner. So the state the app must be in to test this command isn't necessarily something you can just 'set' in the setup for the test. So if the command requires the proxy to be present and to have received its remote data and it will retrieve it and send a notification to a mediator, say, that's hard to do without a mock object for that proxy. Eventually you end up having to mock huge parts of your system and your mocks come into question.

As you'll find elsewhere in these forums if you search for unit test, I thinl what's needed is an in-situ testing apparatus that could trace notification flow, command execution, etc. Unit testing classes in place inside a framework is not easy.

-=Cliff>
Logged
glidealong
Newbie
*
Posts: 5


View Profile Email
« Reply #4 on: May 29, 2008, 09:22:28 »

Thanks a lot for the reply.. It cleared a lot of questions I had, cuz in the process of writing tests for my application i found that more than 60% of my tests required some kind of mocking to do some kind of unit testing. Then I was wondering if I was missing something in the way that I am using PureMVC since it gives me a code coverage of around 1/3 only. Anyway I think I should be looking at something like http://riatest.com/ for testing the entire applications data flow and the cascade of actions.

Thanks again and Keep up the great work.
Logged
Pages: [1]
Print