4 Replies Latest reply on Mar 3, 2010 12:16 PM by markdemich

    Ordering TestCases

    markdemich Level 1

      I've sucessfully ordered tests within a test case.  However, I need to order the testcases themselves.  My code doesn't depend on it, but each testcase class I made matches a chapter in a spec and I would like to get them in order so everytime I run the unit test, any errors reported are in a consistent order.  Is there a way to do this.

        • 1. Re: Ordering TestCases
          mlabriola Level 4

          You can do this a few ways. First, you can put order metadata at the top of each testcase. The framework will find and use these. This works and it is quick, but it is not ideal as it means the testcase now have order themselves, as opposed to order within a given run of cases. It does sound though like this might be fine for your situation.

           

          Ultimately when you run tests with FlexUnit, a Request object is made with all of the tests to be run. You can also make this Request object manually using the static methods of the Request class. If you make your own request instance, then you can also use the sortWith() method of the request to specify any type of sorting function you would like and customize this in code.

           

          Mike

          • 2. Re: Ordering TestCases
            markdemich Level 1

            It's not clear what syntax to use for the metadata and were it goes.

             

            Do I put it in the Suite class before each public definition of each testcase, or do I put it prior to the class definition in each testcase?  Also, what would the syntax be?

             

            Would it be,

             

            [TestCase(order=x)]

            • 3. Re: Ordering TestCases
              mlabriola Level 4

              Actually either of those would work. So, puting it in the suite definition

               

              [Suite(order=1)]

               

              would order that suite relative to the others.

               

              As long as you are at least on RC1, you can use this in a testcase tag, as you suggest, to do the same for individual test cases

               

              [TestCase(order=1)]

               

              Note this is the only actual use for the testcase tag presently, it has no other real use. Also note that any suites or cases without an order are assumed to be at order=0

               

              Mike

              • 4. Re: Ordering TestCases
                markdemich Level 1

                Perfect.  That worked like a charm.  I put it right above the class statement.