Reputation: 9535
I have a bunch of NumericSteppers (start week, start year, end week, end year), which are deep within ViewStacks, NavigatorContents etc. I wanted to unit test my date steppers, and was wondering how I can go about doing that? When I initialize the top level parent component, the children components don't get created. Do I have to manually add all these components by iterating down the tree (please say no :) )? Can I do it using UIImpersonator?
Sorry if the question is basic, Flex is very new to me.
Upvotes: 0
Views: 357
Reputation: 18193
In Flash, creating unit tests for GUI components is problematic. I generally write unit tests for controllers, presentation models, mediators (etc) -- ie: the non GUI classes that contain business logic.
Writing tests for GUI objects becomes a losing proposition, for many reasons:
I generally avoid writing unit tests for components like a date stepper, which we compose together to form the greater "view". I typically use a presentation model, and if the component has particular business logic that should be tested, the tests are written for the non-gui presentation model class (or controller, or mediator, or whatever).
public class MyViewPM
{
// write a unit test for this method
public function onSubmitButtonClick():void
{
}
}
public class MyView extends Sprite
{
// this is injected by your MVC framework
// or set when the the view is created, or added to stage, etc.
public var pm:MyViewPM;
public function MyView()
{
submitButton.addEventListener(MouseEvent.Click, onMouseClick);
}
private function onMouseClick(event:Event):void
{
pm.onSubmitButtonClick();
}
}
Upvotes: 1