Its an interesting problem Allen, and one that ive been trying to tackle for a
while.
The easiest way to do this is to:
Var view:Object;
Function setup(){
View.myLabel = new Label()
viewHelper = new myViewHelper()
viewHelper.view = view;
}
You can do this with most of the standard controls. Instantiating a mxml file
directly from action script seems to be a lot more difficult. I've had
some luck with instantiating the mxml normally as a class, the calling init().
I'm sure somebody will reply to this with the correct way to do
it!
The next step is to take the mock view and extract it in to a separate class:
Class com.views.mockView{
Var myLabel:Label;
mockVieW(){
this.myLabel = new Label
}
}
...
..
Function setup(){
viewHelper.View = new mockView();
}
The major disadvantage of this approach is that you will have to be sure to
Keep your actual view and mock view "in-sync", but overall, you should be
able to reliably unit tests your view helpers.
Ta,
Mike
________________________________________
From: Allen Manning [mailto:[EMAIL PROTECTED]
Sent: 11 April 2005 17:08
To: [email protected]
Subject: [flexcoders] Using FlexUnit with Cairngorm
Hello Flexcoders,
�
I've started using FlexUnit to test business logic in my business delegates.��
�
I would now like to use FlexUnit to test my View Helpers and getter�/ setter
functions in the views themselves.� Does anyone have any examples of how
one�may run tests against their mxml views?
�
For example, if I want to test that a function getLabel():String placed in the
root of mx:Application in file 'index.mxml' returns the string 'myLabel', how
would I go about writing my test?�
�
public function testGetLabelFromView() : Void
{
��� myViewToTest = mx.core.application.Application;//?? how do I get access to
this ??
��� assertEquals('should be ',�'myLabel' ,myViewToTest.getLabel());
}
I'm going to run this test from a testing application, tests.mxml so
mx.core.application.Application refers to my testing application and not the
target application I wish to test.
�
Do I need to instantiate my target application in the tests themselves?� Like
this:
�
public function testGetLabelFromView() : Void
{
��� myViewToTest = index;//do I call this as a class?
��� assertEquals('should be ',�'myLabel' ,myViewToTest.getLabel());
}
Any help would be greatly appreciated.
�
Many Thanks,
Allen
�
Allen Manning, Technical Director���������������������������������������������
Prismix Ltd t: +44 (0)870 749 1100 f: +44 (0)870 749 1200 w: www.prismix.com
________________________________________
Yahoo! Groups Links
* To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
�
* To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
�
* Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/