3 Replies Latest reply on Aug 11, 2010 6:03 AM by mlabriola

    FlexUnit 0.9 to FlexUnit 4 question


      Hi me again with a question.


      Our Flex applications have a back-end to retrieve and set information from/to. This back-end server requires a login (and logout when done). Now every bit of functionality that is tested via this back-end has seperate cases based on groups of functionality (there are about 150 - 200 different calls grouped in about 20 test cases).


      In FlexUnit 0.9 the suite was setup as follows:



      public class EIBTestSuite extends TestSuite
                public function EIBTestSuite()
                     // Verify that the servers are online
                     this.addTest(new EibCase("VerifyEuroportTest"));
                     this.addTest(new EibCase("VerifyServiceTest"));
                     // Login
                     this.addTest(new UserCase("LoginTest"));
                     // Payment
                     this.addTest(new PaymentCase("paymentStart"));
                     this.addTest(new PaymentCase("paymentEntry"));
                     this.addTest(new PaymentCase("removePaymentEntry"));
                     this.addTest(new PaymentCase("loadStandingPayments"));
                     // Other cases
                     // Logoff
                     this.addTest(new UserCase("LogoutTest"));



      As you can see the Login and Logout test are in the same case but are called not directly after eachother. This way we don't need to do the login / logout calls for every case we have.


      Now I'm trying to convert our tests to FlexUnit 4 but I have a problem with converting the above code to FlexUnit 4. Because when I would change the above code to the following all cases after the UserCase would fail because there is no user logged in.



           public class EIBTestSuite
                public var eibCase:EibCase;
                public var userCase:UserCase;
                public var paymentCase:PaymentCase;
                // Other cases




      What we could do is add the login and logout calls to each seperate case and ensure the order in which the tests are executed. But first of all this is a lot of repetition for the same piece of code and second if the login procedure would ever change it would have to be changed in all the cases. Neither is desirable.


      Is there a best-practices way for changing the described situation to FlexUnit 4?


      Thanks for the help,

      Rick Veenstra

        • 1. Re: FlexUnit 0.9 to FlexUnit 4 question

          You should order your tests




          more info here http://docs.flexunit.org/index.php?title=Order

          • 2. Re: FlexUnit 0.9 to FlexUnit 4 question
            Wubzorz Level 1

            I do use orders within each case in order to ensure a certain flow. But does that work accross several cases as well?


            So say I have just the login and logout test within the usercase and I use just 1 test from the PaymentCase (to simplify the description below), and I set it up as follows:




            public class UserCase
                public function loginTest():void { ..... }
                public function logoutTest():void { ..... }




            public class PaymentCase
                public function paymentStartTest():void {.....}


            Would the order of exection then be: loginTest -> paymentStartTest -> logoutTest?

            • 3. Re: FlexUnit 0.9 to FlexUnit 4 question
              mlabriola Level 4

              I would make a test suite that contains all of your tests case. Test suites can also contain other suites, so this should be very flexible regardless of the number/types/levels of test hierarchy.


              You should then be able to make two *static* functions of the top-level suite. One will be for logging in. One will be for logging out. Mark the login one with [BeforeClass] and the logout with [AfterClass]. These functions need to be static because they quite literally run before the suite constructor and potentially after garbage collection of the suite.


              I personally would prefer to login and logout before and after each test as you know there is no state or other session information that has been corrupted, but this method should work for what you are asking.