|
Order
How to control the order in which your tests run and which tests are selected to be run
The BasicsYour tests need to act independently of each other. So, the point behind ordering your tests in a custom way is not to ensure that test A sets up some state that test B needs. If this is the reason you are reading this section, please reconsider. Tests need to be independent of each other and generally independent of order. Why then would we include the capability to manipulate order? Well, because there are other valid reasons to do so. If you have many tests of increasing complexity, it makes sense to order these so that, in the event a simple test fails, you don’t waste time running the more complicated versions. You may also have hundreds of test methods in your TestCase or hundreds of TestCases and you wish to decide when to run these in a way that we have not even begun to consider. This framework provides the ability to manipulate both the order and selection criteria for tests on each level (Suite, TestCase, Method) using standard Flex filter functions and sorts. SortingThe TestRunner, TestSuite and TestCase classes all have a public property called sorter which can be set to an instance of the Flex framework Sort class. You can define different sort criteria for each individual TestCase in the system, or choose to have them all sort the same way. The default sorters choose an alphabetical approach; however, this is likely to change in the future, so please do not rely on this feature when naming your tests. FilteringThe TestRunner, TestSuite and TestCase classes all also have a public property named filter which can be set to any function that uses the following signature: f(item:Object):Boolean If the function returns true, the relevant item is kept. If it returns false, the item will not be counted in the testing. The TestRunner and TestSuite filter functions currently always return true. The TestCase filter function returns true for any method that begins with the letters ‘test’. If you do not wish to provide a filter function, or wish to manipulate this filtering through inheritance, the defaultFilterFunction is also defined in each of these classes in the following method: protected function defaultFilterFunction( item:Object ):Boolean; This method can be overridden in a subclass to manipulate the filtering instead of providing a new filter. WhyUsing these features you can actually make a very dynamic test environment where tests are removed or added based on other factors and features. I am not sure you want to, but we simply provided the interface to maximize potential damage. |
Sign in to add a comment

A good reason for Ordering is documentation. I have modified (hacked not properly reimplemented) the runner result display to show test methods as sentences:
testShouldInvalidatePolygon becomes Should Invalidate Polygon.
This my runner shows documentation of what I expect my class to do (Class is synonymous with a test case in my world)
Unfortunately there appears to be no way to sort the tests in the order i'd like, which is the order theyre defined in the test case.
I also like the idea of filtering.
I have implemented some Test Methods with naming: failsShouldFooWhenBar.
fails (instead of 'test') indicates a known issue that wont be fixed any time soon. We can switch to showing issues by modifying Case filters, however its not working for me, possibly because the TestResultDisplay? is filtering by ^test elsewhere (perhaps I need to set filtering on the Runner and Suite).
An alternative would be a bedded in naming scheme for test methods that let some methods be marked as 'warnings'. Warnings are nice because I don't want to lose the documentation that things are not quite right, but for expediency i don't want my tests to fail on something i have an existing workaround for.
You could write your own sorting function to do something like:
test1DoSomethingCool test2DoSomethingElse test3DoAnotherthing
and then sort by the number after tests... if you want them in that order, that is one way.
One other thing to note: test methods only need to start with the word 'test' because of a filter function in the framework. You could eliminate or change that rule in any way you would like.
mike
Mike: have you considered the namespace approach that AS3Unit uses, which appears to eliminate the need for magical test naming standards by simply using a namespace to group the test methods?