-
1. Re: Testing states in FlexUnit4
Michael Labriola Feb 17, 2010 5:46 AM (in response to Ignacio Martín Prieto)There are exceedingly few things in the Flex framework that are synchronous. For almost everything in the component lifecycle, updating properties, creating children and, I am sure, states, things are going to be asynchronous. When you are creating the button, you are waiting for creationComplete, which is good. My guess is that after you rollout, you likely need to wait for another even indicating that the state has changed before you try to do your assert.
Right now your assert is happening synchronously, meaning you issue a rollout and immediately expect the state to have chnaged and everything to have updated. That is likely not a reasonable expectation in Flex.
Mike
-
2. Re: Testing states in FlexUnit4
Ignacio Martín Prieto Feb 17, 2010 9:34 AM (in response to Michael Labriola)Hi Mike,
I did try listening for other events dispatched by the flex framework like FRAME_ENTER or FRAME_EXIT and some others. None of them seemed to work as the skin state had not been updated at that point. I have done some research but I haven´t found any event that gets dispatched after a display update. Any ideas of what event could it be?
Thanks,
Ignacio
-
3. Re: Testing states in FlexUnit4
Ignacio Martín Prieto Feb 17, 2010 10:52 AM (in response to Ignacio Martín Prieto)I found FlexEvent.UPDATE_COMPLETE useful in case anyone is interested:
Async.handleEvent( this, myComponent, FlexEvent.UPDATE_COMPLETE, handleStateChange, 1000 );
I was also able to listen to the currentStateChange event on the skin, but I coudn´t do it twice in the same test like this:
[Test(async,ui)]
public function testOne() : void
{
Async.handleEvent( this, myComponent, StateChangeEvent.CURRENT_STATE_CHANGE, handleStateChange, 1000 );
component.btnSubmit.dispatchEvent( new MouseEvent( MouseEvent.CLICK ) ); // this triggers the state change
}
protected function handleStateChange( event : Event, param : * ) : void
{
Assert.assertEquals( "Something went wrong", "state2", myComponent.skin.currentState );Async.handleEvent( this, myComponent, StateChangeEvent.CURRENT_STATE_CHANGE, handleStateChange2, 1000 );
component.btnSubmit.dispatchEvent( new MouseEvent( MouseEvent.CLICK ) ); // this triggers the state change
}protected function handleStateChange2( event : Event, param : * ) : void
{
Assert.assertEquals( "Something went wrong", "state2", myComponent.skin.currentState );
}I got a timeout on the second wait when I tried that.
Any ideas?
Thanks,
Ignacio
-
4. Re: Testing states in FlexUnit4
davorian Mar 31, 2010 5:57 PM (in response to Ignacio Martín Prieto)You have two timeouts of 1000 but the test method testOne has a test metadata tag with no timeout attribute on it try 2000. I think this thus defaults to 500. So your second Async can occur after the method timesout.
-
5. Re: Testing states in FlexUnit4
rduclos56 Apr 16, 2010 11:31 AM (in response to Ignacio Martín Prieto)@Ignacio: Did you ever figure out the timeout issue? I recreated this example was able to run both tests in under .2s so I don't think setting the timeout variable any higher would solve this.
-Created a component with 2 skin parts, button and textinput
-Created a skin for that component that had the button only in btnState and textInput in textInput State only
-Created handler functions for a click event on the button and a roll_over on the textInput, that would set the skin's current state as well as dispatch a custom flash event called skinStateChange
-Also over rode the partAdded and partRemoved functions, adding listeners to the button and textinput for the click and rollover events.
-Created two tests, one to test the button skin state and one for the textinput skin state.
- - - First test since the component's skin starts in the button state, I had the component listen for the skinStateChange event, and used an Async handler to call a function that tested if the skins current state equaled the a string that was set to what state it should be in, which in this case should be in textInputState since the button is being clicked. Had the button dispatch a Click event.
--Second test is pretty much the same, but need to set the skin's current state to textInputState first, so the textinput can be created as well as allowing us to test the change of states to the button state, and that the textinput will be dispatching a roll_over event instead of a click event.
Let me know if you have any questions or want to see any of the code.
-
6. Re: Testing states in FlexUnit4
nikos101 Jan 4, 2011 8:04 AM (in response to rduclos56)so can you run both aysnc tests in order? Any of you have any ideas how I can test a button that for some weird reason is dispatching multiple click events randomly?
-
7. Re: Testing states in FlexUnit4
rduclos56 Jan 6, 2011 2:55 PM (in response to nikos101)@Nikos - Hey, sorry it's been awhile, but let me see if I can help out at all. The tests are run independently of eachother, and what I mean by this is the second test is not relying on what is happening from the first test. So make sure you have all your preconditions set before running the test. Do not make tests dependent on eachother!
As to your second point, without seeing code I have no idea why your button is dispatching multiple click events randomly ;p
Also I might recommend opening a new topic since this one is a bit old, also if you need any more info on Flexunit check out the wiki.
-
8. Re: Testing states in FlexUnit4
nikos101 Jan 7, 2011 2:04 AM (in response to rduclos56)Thanks mate, my problems have been solved in the meantime


