12 Replies Latest reply on May 24, 2011 1:59 PM by gantaclaus

    commitProperties testing


      Hello! I have several UIComponents with overridden commitProperties function. When i use some property setter i need to wait for commitProperties to finish execution in order to test the results. How should I approach this issue? Currently I use step SequenceDelay in my sequence, but this causes tests to run slow. I also tried waiting update_complete event, but this one is unreliable, sometimes changes are made after one update_complete event is dispatched, and some times after two update_complete events.

        • 1. Re: commitProperties testing
          legrosb Level 3

          @yimiyimi88 - To test these UI components, I'd suggest writing integration tests which use the UIImpersonator class.  You can find more information about it on the wiki @ http://docs.flexunit.org/index.php?title=Writing_an_Async_setup#Create_a_New_Test_Case.  Basically you're making asserts using the Async tool for events dispatched by the Flex framework to signify that certain lifecycle stages have been completed.  UIImpersonator will add your custom UI components to the stage so that they participate in the lifecycle.


          Give it a sping and let us know what questions we can help with.



          • 2. Re: commitProperties testing
            yimiyimi88 Level 1

            I am already using UIImpersonator. I am already testing asynchronous behaviour of my components using fluint sequences. My current problem is how to wait for commitProperties to be executed. I mentioned it can be done using adding SequenceDelay step after using SequenceSetter property, but this solution is not good, I also tried waiting for UPDATE_COMPLETE event, but this event is unreliable since it is dispatched unknown amount of times before commitProperties is executed. So, can some help me finding an exact solution how to approach testing commitProperties behaviour? Solution can use sequences or Async class static methods, it really does not matter. Thanks

            • 3. Re: commitProperties testing
              legrosb Level 3

              @yimiyimi88 - Sorry, guess I should have assumed you were using UIImpersonator since you mentioned you're using Sequences with UI components.  I dug around in the SDK and didn't see anything in the lifecyle being dispatched specifically for when commitProperties is called.  The only real check I can think of adding are listeners for propertyChange events since all UI components should expose them.  If you could provide us with snippets of your test and code being tested we can attempt to help you further.



              • 4. Re: commitProperties testing
                mlabriola Level 4

                The update_complete is really the right way to do this. I am very surprised to hear that things are happening after a variable number of validation loops.


                IMO, a first step might be finding out why. Something that takes more than 1 validation loop usually points to a circumstance where a component is invalidating itself partially through validation. This is generally bad and usually a big performance hit. I guess my 2 cents here is just to try to find out why and be sure this is the behavior you want.


                Other than that, there are likely only 2 choices left. Have your component dispatch a custom event when it is in the desired state... which I don't really like because you are adding functionality only for testing


                If there is a way to check if this code has run, you could check after the first update complete, and, if it has not run, add another async listener for the next round.


                All of this concerns me though for a few reasons. The mot important aspect, IMO, of this type of testing is complete reproducibility. If the code works one way sometimes and another later, it seems like an issue. What if another portion of the system was listening to the update_complete event, etc to do work? Just seems like a bad situation.


                If you can provide more details I am willing to try to help more,


                • 5. Re: commitProperties testing
                  yimiyimi88 Level 1

                  Hi all! Functionality in my commitProperties is quite simple: if some private variable has been changed, set LinkBar dataProvider propery to some arrayCollection. What I did now is listen for UPDATE_COMPLETE, CREATION_COMPLETE events and generate some output. I found out that LayoutManager dispatches a UPDATE_COMPLETE event right AFTER CREATION_COMPLETE. This could explain why am I receiving sometimes one and sometimes two UPDATE_COMPLETE events. btw. my component is extended from Box. I will try to proceed on event UPDATE_COMPLETE instead of CREATION_COMPLETE in my setup function before performing any tests.

                  • 6. Re: commitProperties testing
                    mlabriola Level 4

                    you just revealed some very important information we didnt know before. uicomponents all go through a layout phase when they are added to the display list. until that phase is complete, your component isnt really stable and crreated, positioned and sized. with uicomponents it is generally advisable to add the component to the display list and wait for the creation complete before you begin your test.


                    then your test would change a property and watch for the update complete. the sequence testing and uicomponent testing wiki pages show this technique. i incorrectly assumed you were already doing this

                    • 7. Re: commitProperties testing
                      yimiyimi88 Level 1

                      No, your assumptions were correct! I testing the same way as described in the documentation. I wait for creation_complete in setup function using Async proceedOnEvent. Let me explain one more time my problem and a possible solution:


                      After I added my component to UIImpersonator and CREATION_COMPLETE has been caught(done in setup) my tests are executed.

                      After SequenceSetter step I wait for an UPDATE_COMPLETE event using SequenceWaiter.

                      I added some eventlisteners in my component and I figured out that immediately AFTER CREATION_COMPLETE, UPDATE_COMPLETE is dispatched by LayoutManager!!!!!

                      If my understating is correct, the trouble was caused by this first update_complete event. It could happen that I caught this first update_complete in my SequenceWaiter instead of second update_complete event dispatched when commitProperties is executed.

                      Now I am waiting for UPDATE_COMPLETE event instead of CREATION_COMPLETE in my setup. For now It works fine.

                      You can try doing it by yourself: Create a component extending any UIComponent class, add it to DisplayList and listen for both events, and you will see update_complete event immediately after creation_complete event. And if your tests rely on update_complete you could unexpectedly catch this first update_complete event instead of the one you are expecting. This is my theory.


                      • 8. Re: commitProperties testing

                        I tried listening to a Creation_Complete event as well as an Update_Complete event and received a timeout error for the Update_Complete Event.


                        I didn't see a problem with first listening for Creation_complete in setup, then in test adding a SequenceSetter for the component then listening with Sequencewaiter for an Update_Complete.


                        If you have a project you can zip up I can take a look at it.

                        • 9. Re: commitProperties testing
                          yimiyimi88 Level 1

                          Try this code and you will see, that there is an update_complete event:


                            [Before (async,ui)]
                          public function setUp():void {
                                 instance=new UIComponent();
                                 Async.proceedOnEvent( this, instance, FlexEvent.UPDATE_COMPLETE, 1500);

                          [After (async)]
                               public function tearDown():void {

                                 [Test (async)]
                               public function test1():void {
                                     var sequence:SequenceRunner = new SequenceRunner( this );
                                 sequence.addStep( new SequenceSetter(instance,{width:100}));
                                 sequence.addStep( new SequenceWaiter(instance,FlexEvent.UPDATE_COMPLETE,1500));

                          • 10. Re: commitProperties testing
                            mlabriola Level 4

                            I think your solution is likely fine for 99% of the cases.


                            The only place this might be an issue is some of the list classes which go through a little bit longer phase of startup in some cases to measure rows, etc.



                            • 11. Re: commitProperties testing
                              yimiyimi88 Level 1

                              Thank you all for your help!

                              • 12. Re: commitProperties testing

                                This was very helpful and solved my problems with testing commitProperties methods